42 cursor_pos_ = value.size();
54 value.insert(cursor_pos_, e.
text);
55 cursor_pos_ += e.
text.size();
63 if (cursor_pos_ > 0) {
64 value.erase(cursor_pos_ - 1, 1);
73 if (cursor_pos_ < value.size()) {
74 value.erase(cursor_pos_, 1);
82 if (cursor_pos_ > 0) {
88 if (cursor_pos_ < value.size()) {
98 cursor_pos_ = value.size();
115 constexpr float text_padding = 4.0F;
126 if (hovered_ && enabled) {
132 const SDL_Rect clip {
133 static_cast<int>(transform.position.x + text_padding),
134 static_cast<int>(transform.position.y),
135 static_cast<int>(transform.size.x - (text_padding * 2)),
136 static_cast<int>(transform.size.y),
141 const auto display_text = value.empty() ? placeholder : value;
144 if (!display_text.empty() && font !=
nullptr) {
146 const float text_y = transform.position.y + ((transform.size.y - text_size.y) / 2.0F);
147 const asw::Vec2 text_pos { transform.position.x + text_padding, text_y };
153 if (focused_ && font !=
nullptr) {
154 const auto before_cursor = value.substr(0, cursor_pos_);
155 float cursor_x = transform.position.x + text_padding;
157 if (!before_cursor.empty()) {
159 cursor_x +=
static_cast<float>(size.x);
163 const float cursor_y = transform.position.y
164 + ((transform.size.y -
static_cast<float>(text_height.y)) / 2.0F);
167 { cursor_x, cursor_y +
static_cast<float>(text_height.y) }, ctx.
theme.
text);
176 ring.position.x -= 2;
177 ring.position.y -= 2;
Shared state for the UI system.
Widget * pointer_capture
The widget that has captured pointer input.
FocusManager focus
The focus manager.
Theme theme
The current UI theme.
void set_focus(Context &ctx, Widget *w)
Set focus to a specific widget.
Display and window routines for the ASW library.
Routines for drawing sprites and primitives to the screen.
asw::Renderer * renderer
The renderer for the display module.
asw::Window * window
The window for the display module.
void line(const asw::Vec2< float > &position1, const asw::Vec2< float > &position2, asw::Color color)
Draw a line.
void text(const asw::Font &font, const std::string &text, const asw::Vec2< float > &position, asw::Color color, asw::TextJustify justify=asw::TextJustify::Left)
Draw text.
void rect(const asw::Quad< float > &position, asw::Color color)
Draw a rectangle.
void rect_fill(const asw::Quad< float > &position, asw::Color color)
Draw a filled rectangle.
asw::Vec2< int > get_text_size(const asw::Font &font, const std::string &text)
Get text size.
RGBA color struct with 8-bit channels.
asw::Color text
Default text color.
bool show_focus
Show focus rings around focused widgets. Enabled by default when using keyboard navigation.
asw::Color panel_bg
Panel background color.
asw::Color input_bg
Input box background color.
asw::Color text_dim
Dimmed text color.
asw::Color btn_focus_ring
Button focus ring color.
asw::Color btn_hover
Button hover color.
asw::Color btn_bg
Button background color.
Event structure for UI interactions.
asw::Vec2< float > pointer_pos
The pointer position.
std::string text
The text associated with a TextInput event.
asw::input::Key key
The key associated with the event.
Type type
The type of the event.
General utility functions.