KTech 1.1.0
C++ 2D terminal game engine library
Loading...
Searching...
No Matches
StringField Class Reference

Widget for entering a string. More...

#include <stringfield.hpp>

Inheritance diagram for StringField:
KTech::Widget

Public Member Functions

 StringField (KTech::Engine &engine, KTech::ID< KTech::UI > ui, std::function< void()> OnInsert=nullptr, const std::vector< std::pair< char, char > > &allowedCharacters={charRange_all}, KTech::Point position={ 0, 0 }, const std::string &text="Value = ", unsigned int maxChars=8, const std::string &defaultString="String", bool withFrame=false, KTech::RGBA unselected=KTech::RGBAColors::gray, KTech::RGBA selected=KTech::RGBAColors::white)
 Construct a StringField.
 
void SetText (const std::string &text, bool withFrame)
 Change the displayed text.
 
void SetValue (const std::string &value)
 Change the entered string.
 
- Public Member Functions inherited from KTech::Widget
 Widget (Engine &engine, Point position=Point(0, 0), std::string name="")
 Construct a Widget.
 
 Widget (Engine &engine, const ID< UI > &parentUI, Point position=Point(0, 0), std::string name="")
 Construct a Widget and immediately enter a UI.
 
virtual ~Widget ()
 Leave parent UI (if in one) and remove itself from Memory.
 
auto AddWidget (const ID< Widget > &widget) -> bool
 Undocumented due to planned changes (see GitHub issue #106).
 
auto RemoveWidget (const ID< Widget > &widget) -> bool
 Undocumented due to planned changes (see GitHub issue #106).
 
auto RemoveAllWidgets () -> bool
 Undocumented due to planned changes (see GitHub issue #106).
 
auto EnterWidget (const ID< Widget > &widget) -> bool
 Undocumented due to planned changes (see GitHub issue #106).
 
auto EnterUI (const ID< UI > &ui) -> bool
 Enter a UI.
 
auto LeaveWidget () -> bool
 Undocumented due to planned changes (see GitHub issue #106).
 
auto LeaveUI () -> bool
 Leave the parent UI.
 
void Select ()
 Enable input callbacks, and call Widget::OnSelect().
 
void Deselect ()
 Disable input callbacks, and call Widget::OnDisable().
 
void Show ()
 Let UI render this Widget, and call Widget::OnShow().
 
void Hide ()
 Don't let UI render this Widget, and call Widget::OnHide().
 

Public Attributes

std::string m_string
 The entered string.
 
std::function< void()> m_OnInsert
 Function to call when the user inserts or removes a character.
 
- Public Attributes inherited from KTech::Widget
Engineengine
 Parent Engine.
 
const ID< Widgetm_id {ID<Widget>::Unique()}
 Personal ID.
 
std::string m_name
 String name.
 
ID< UIm_parentUI
 The UI containing this Widget.
 
ID< Widgetm_parentWidget = nullID<Widget>
 Undocumented because it's planned to change (see GitHub issue #106).
 
std::vector< ChildWidget > m_childWidgets
 Undocumented because it's planned to change (see GitHub issue #106).
 
bool m_selected = false
 true: player input reaches the Widget. false: player input doesn't.
 
bool m_shown = true
 true: will be rendered by UI. false: will be ignored by UI.
 
Point m_pos
 World position.
 
std::vector< Texturem_textures = {}
 Comprising Textures.
 
Input::CallbackGroup m_callbackGroup
 Group of all input callbacks, which are enabled and disabled in correspondence to Widget::m_selected.
 

Static Public Attributes

static constexpr std::pair< char, char > charRange_lower {'a', 'z'}
 Range of all lower case letters.
 
static constexpr std::pair< char, char > charRange_upper {'A', 'Z'}
 Range of all upper case letters.
 
static constexpr std::pair< char, char > charRange_numbers {'0', '9'}
 Range of all digits.
 
static constexpr std::pair< char, char > charRange_all {' ', '~'}
 Range ofa all ASCII characters.
 

Additional Inherited Members

- Protected Member Functions inherited from KTech::Widget
virtual auto OnTick () -> bool
 Virtual function called once each tick.
 
virtual void OnShow ()
 Virtual function called by Widget::Show().
 
virtual void OnHide ()
 Virtual function called by Widget::Hide().
 

Detailed Description

Widget for entering a string.

Constructor & Destructor Documentation

◆ StringField()

StringField::StringField ( KTech::Engine & engine,
KTech::ID< KTech::UI > ui,
std::function< void()> OnInsert = nullptr,
const std::vector< std::pair< char, char > > & allowedCharacters = {charRange_all},
KTech::Point position = { 0, 0 },
const std::string & text = "Value = ",
unsigned int maxChars = 8,
const std::string & defaultString = "String",
bool withFrame = false,
KTech::RGBA unselected = KTech::RGBAColors::gray,
KTech::RGBA selected = KTech::RGBAColors::white )
inline

Construct a StringField.

Parameters
[in]engineParent Engine.
[in]uiKTech::UI to immediately enter.
[in]OnInsertFunction to call when the user inserts or removes a digit.
[in]allowedCharactersVector of character pairs, representing the allowed characters (e.g. {StringField::charRange_all}, {{'a', 'c'}, {'x', 'z'}}).
[in]positionWorld position.
[in]textText to the left of the entered string.
[in]maxCharsMaximum allowed characters.
[in]defaultStringThe default string (e.g. "abc", " abc ").
[in]withFrameWhether to add a frame around the text and entered string.
[in]unselectedForeground (text and frame) color set when StringField is unselected.
[in]selectedForeground color set when StringField is selected.

Member Function Documentation

◆ SetText()

void StringField::SetText ( const std::string & text,
bool withFrame )
inline

Change the displayed text.

Parameters
[in]textText to the left of the entered string.
[in]withFrameWhether to add a frame around the text and entered string.

◆ SetValue()

void StringField::SetValue ( const std::string & value)
inline

Change the entered string.

Parameters
[in]valueNew string (e.g. "abc", " abc ").

The documentation for this class was generated from the following file: