23#include "../ktech.hpp"
57 std::function<
void()> OnInsert =
nullptr,
58 const std::vector<std::pair<char, char>>& allowedCharacters = {
charRange_all},
60 const std::string& text =
"Value = ",
61 unsigned int maxChars = 8,
62 const std::string& defaultString =
"String",
63 bool withFrame =
false,
66 :
Widget(
engine, ui, position),
m_OnInsert(std::move(OnInsert)), m_maxChars(maxChars), m_unselectedRGBA(unselected), m_selectedRGBA(selected),
m_string(defaultString)
72 for (
const std::pair<char, char>& charRange : allowedCharacters)
86 void SetText(
const std::string& text,
bool withFrame)
123 enum TextureIndex :
size_t
127 TEXTURES_SIZE_FRAMELESS,
128 ti_topLeftCorner = TEXTURES_SIZE_FRAMELESS,
131 ti_bottomRightCorner,
140 uint16_t m_currentChar = 0;
143 void OnSelect()
override
148 void OnDeselect()
override
153 auto Insert() ->
bool
157 if (m_currentChar == 0)
165 m_textures[ti_input](m_currentChar, 0).c =
' ';
167 else if (m_currentChar == m_maxChars)
184 void RenderSelected()
188 texture.Transform([&](
KTech::CellA& cell){ cell.
f = m_selectedRGBA; });
192 void RenderUnselected()
196 texture.Transform([&](
KTech::CellA& cell){ cell.
f = m_unselectedRGBA; });
Complete engine containing all engine components.
Definition engine.hpp:41
Input input
Input engine component.
Definition engine.hpp:47
Widget for entering a string.
Definition stringfield.hpp:29
void SetText(const std::string &text, bool withFrame)
Change the displayed text.
Definition stringfield.hpp:86
static constexpr std::pair< char, char > charRange_lower
Range of all lower case letters.
Definition stringfield.hpp:31
static constexpr std::pair< char, char > charRange_numbers
Range of all digits.
Definition stringfield.hpp:33
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.
Definition stringfield.hpp:55
static constexpr std::pair< char, char > charRange_upper
Range of all upper case letters.
Definition stringfield.hpp:32
std::function< void()> m_OnInsert
Function to call when the user inserts or removes a character.
Definition stringfield.hpp:38
std::string m_string
The entered string.
Definition stringfield.hpp:36
void SetValue(const std::string &value)
Change the entered string.
Definition stringfield.hpp:115
static constexpr std::pair< char, char > charRange_all
Range ofa all ASCII characters.
Definition stringfield.hpp:34
Like Cell, but with RGBA foreground and background colors, instead of RGB.
Definition cella.hpp:32
RGBA f
Foreground (character) color.
Definition cella.hpp:33
Serializable world structure identifier.
Definition id.hpp:38
2D vector, mostly used to store positions and directions.
Definition point.hpp:30
Like RGB, but also has an alpha channel representing transparency.
Definition rgba.hpp:30
A CellA-based sprite.
Definition texture.hpp:48
Unsigned 2D vector, mostly used to store sizes and 2D indexes.
Definition upoint.hpp:29