23 class TextField :
public Frame {
27 std::string_view id, prefix, suffix;
33 static void enterSettings(std::unique_ptr<rose::Settings> &db,
const FieldSettings &setting);
66 std::shared_ptr<TextField>
mPair{};
85 explicit TextField(
int maxLength,
int padding = 0,
FontSize fontSize = 0,
const string &fontName =
"");
96 TextField(
int maxLenght,
const std::string &text,
const std::string &suffix =
"",
const std::string &prefix =
"",
97 int padding = 0,
FontSize fontSize = 0,
const string &fontName =
"");
106 explicit TextField(
Id id,
int padding = 0,
FontSize fontSize = 0,
const string &fontName =
"");
109 static void Settings(std::unique_ptr<rose::Settings> &db,
const std::array<FieldSettings,N> &settings) {
110 for (
const auto& setting : settings) {
111 enterSettings(db, setting);
121 void setPair(
const Id &pairId, std::shared_ptr<TextField> &pair);
139 bool textInputEvent(
const std::string &text)
override;
145 bool keyboardEvent(uint state, uint repeat, SDL_Keysym keysym)
override;
163 bool isModified()
const {
return mModified; }
167 bool mToUpperCase{
true};
178 template <
class W
idgetClass>
179 inline std::shared_ptr<WidgetClass> operator<<(std::shared_ptr<WidgetClass> widget,
const std::shared_ptr<std::regex>& regex) {
180 static_assert(std::is_base_of_v<rose::TextField,WidgetClass>,
"Regex can only be set on TextField Widgets." );
181 widget->setRegex(regex);
192 template <
class W
idgetClass>
194 static_assert(std::is_base_of_v<rose::TextField,WidgetClass>,
"ToUpperCase can only be set on TextField Widgets." );
Size mTextSize
The size of the rendered Text.
Definition: TextField.h:57
bool mModified
True when the value has been modified.
Definition: TextField.h:39
sdl::Texture mTextTexture
Texture to render the Text;.
Definition: TextField.h:63
std::shared_ptr< TextField > mPair
The companion in a TextField pair.
Definition: TextField.h:66
color::RGBA mErrorColor
The color used when validation fails.
Definition: TextField.h:49
An Widget to edit a small amount of text.
Definition: TextField.h:28
void setPair(const Id &pairId, std::shared_ptr< TextField > &pair)
Set up a pair of TextField widgets.
Definition: TextField.cpp:152
DataType
Encode expected data types.
Definition: Constants.h:45
sdl::Texture mSuffixTexture
Texture to render the Suffix;.
Definition: TextField.h:62
Rectangle widgetLayout(sdl::Renderer &renderer, Rectangle available, uint layoutStage) override
See Frame::widgetLayout()
Definition: TextField.cpp:38
Size mSuffixSize
The size of the rendered Suffix.
Definition: TextField.h:56
std::string mFontName
The font name.
Definition: TextField.h:45
std::string mText
The current text value.
Definition: TextField.h:53
Red Green Blue Alpha representation of a color.
Definition: Color.h:64
Not set to a valid value.
void draw(gm::Context &context, const Position< int > &containerPosition) override
Draw the visual.
Definition: TextField.h:77
FontSize mFontSize
The font size in pixels.
Definition: TextField.h:44
bool keyboardEvent(uint state, uint repeat, SDL_Keysym keysym) override
Handle KeyboardEvent.
Definition: TextField.cpp:338
sdl::Texture mPrefixTexture
Texture to render the Prefix;.
Definition: TextField.h:61
std::shared_ptr< TTF_Font > FontPointer
Type for TTF smart pointer.
Definition: Font.h:54
bool mHasFocus
True if the TextField has keyboard focus.
Definition: TextField.h:41
int mGlyphAdvance
The advance of mEm.
Definition: TextField.h:59
An encapsulation of the SDL_Texture structure.
Definition: Texture.h:40
void initializeComposite() override
See Widget::initializeComposite();.
Definition: TextField.cpp:181
void setFontName(const std::string &fontName)
Set the font name.
Definition: TextField.cpp:236
std::string::iterator mCaretLoc
The caret location in mText (one past).
Definition: TextField.h:54
size_t mPairIdx
The index of this object in the pair (0 or 1).
Definition: TextField.h:68
int FontSize
Type specifier to pass a Font size to a Widget through a manipulator.
Definition: Types.h:43
std::string mPrefix
The prefix to the text.
Definition: TextField.h:51
color::RGBA mTextColor
Text foreground color.
Definition: TextField.h:48
int mMaxLength
The maximum length of the text.
Definition: TextField.h:43
Constants and Enumerations.
FontPointer mFont
FontPointer to font in use.
Definition: TextField.h:46
Id mPairId
The Id of the pair.
Definition: TextField.h:67
Definition: TextField.h:25
char mEm
The largest Glyph that will be in the text.
Definition: TextField.h:38
int mTextMaxGlyph
The width of mEm.
Definition: TextField.h:58
bool keyboardFocusEvent(bool focus) override
Handle keyboard focus events.
Definition: TextField.cpp:368
FontMetrics mFontMetrics
The metrics of the current font.
Definition: TextField.h:47
A settings database.
Definition: Settings.h:27
A composite of a Position and a Size.
Definition: Types.h:307
A type to specify an Id value.
Definition: StructuredTypes.h:148
bool toUpperCase
If true input is forced to upper case.
Definition: TextField.h:91
bool mValidEntry
True if the current value passes validation.
Definition: TextField.h:40
Written as a workaround for an issue in the SDL2 Library.
Definition: Renderer.h:64
Size mPrefixSize
The size of the rendered Prefix.
Definition: TextField.h:55
A size in integer dimensions.
Definition: Types.h:230
Definition: TextField.h:98
The size metrics that pertain to a particular font.
Definition: Font.h:173
bool mToUpper
Convert chars to upper case.
Definition: TextField.h:42
void setRegex(std::shared_ptr< std::regex > regex)
Set the validation regex.
Definition: TextField.h:151
DataType mDataType
The type of data expected by the TextField.
Definition: TextField.h:37
ToDo: There is an issue that the initial scroll interaction is lost if the click/press lands on a Wid...
Definition: CelestialOverlay.cpp:13
color::RGBA mUnmodifiedColor
The color used when data is unmodified.
Definition: TextField.h:50
void setFontSize(FontSize fontSize) override
Set the font size in pixels.
Definition: TextField.cpp:230
std::shared_ptr< std::regex > mValidationPattern
Regular expression to validate content.
Definition: TextField.h:65
void setToUpper(bool toUpper)
Set the ToUpper flag.
Definition: TextField.h:159
std::string mSuffix
The suffix to the text.
Definition: TextField.h:52