ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
Loading...
Searching...
No Matches
asw::ui::InputBox Class Reference

A text input widget. More...

#include <input_box.h>

Inheritance diagram for asw::ui::InputBox:
[legend]
Collaboration diagram for asw::ui::InputBox:
[legend]

Public Member Functions

 InputBox ()
 Default constructor.
 
void on_focus_changed (Context &ctx, bool focused) override
 Called when focus state changes.
 
bool on_event (Context &ctx, const UIEvent &e) override
 Handle a UI event.
 
void draw (Context &ctx) override
 Draw the input box.
 
- Public Member Functions inherited from asw::ui::Widget
 Widget ()
 Default constructor for Widget.
 
virtual ~Widget ()=default
 Default virtual destructor.
 
 Widget (Widget &&)=default
 Move constructor.
 
Widgetoperator= (Widget &&)=default
 Move assignment operator.
 
 Widget (const Widget &)=delete
 
Widgetoperator= (const Widget &)=delete
 
WidgetId id () const
 Get the unique identifier for this widget.
 
virtual void layout (Context &ctx)
 Lay out this widget and its children.
 
template<class T , class... Args>
T & add_child (Args &&... args)
 Add a child widget.
 

Public Attributes

std::function< void(const std::string &)> on_change
 Callback invoked when the value changes.
 
asw::Font font
 The font to use for the input text.
 
std::string value
 The current text value.
 
std::string placeholder
 Placeholder text shown when value is empty.
 
- Public Attributes inherited from asw::ui::Widget
bool visible = true
 Whether the widget is visible.
 
bool enabled = true
 Whether the widget is enabled.
 
bool focusable = false
 Whether the widget can receive focus.
 
Widgetparent = nullptr
 Pointer to the parent widget.
 
std::vector< std::unique_ptr< Widget > > children
 Child widgets.
 
asw::Quad< float > transform
 The transform (position and size) of the widget.
 

Private Attributes

bool hovered_ = false
 
bool focused_ = false
 
std::size_t cursor_pos_ = 0
 

Detailed Description

A text input widget.

Definition at line 23 of file input_box.h.

Constructor & Destructor Documentation

◆ InputBox()

asw::ui::InputBox::InputBox ( )
inline

Default constructor.

Definition at line 27 of file input_box.h.

Member Function Documentation

◆ draw()

void asw::ui::InputBox::draw ( Context & ctx)
overridevirtual

Draw the input box.

Parameters
ctxThe UI context.

Reimplemented from asw::ui::Widget.

Definition at line 113 of file input_box.cpp.

◆ on_event()

bool asw::ui::InputBox::on_event ( Context & ctx,
const UIEvent & e )
overridevirtual

Handle a UI event.

Parameters
ctxThe UI context.
eThe event to handle.
Returns
True if the event was handled.

Reimplemented from asw::ui::Widget.

Definition at line 23 of file input_box.cpp.

◆ on_focus_changed()

void asw::ui::InputBox::on_focus_changed ( Context & ctx,
bool focused )
overridevirtual

Called when focus state changes.

Parameters
ctxThe UI context.
focusedWhether the widget is now focused.

Reimplemented from asw::ui::Widget.

Definition at line 10 of file input_box.cpp.

Member Data Documentation

◆ cursor_pos_

std::size_t asw::ui::InputBox::cursor_pos_ = 0
private

Definition at line 68 of file input_box.h.

◆ focused_

bool asw::ui::InputBox::focused_ = false
private

Definition at line 67 of file input_box.h.

◆ font

asw::Font asw::ui::InputBox::font

The font to use for the input text.

Definition at line 57 of file input_box.h.

◆ hovered_

bool asw::ui::InputBox::hovered_ = false
private

Definition at line 66 of file input_box.h.

◆ on_change

std::function<void(const std::string&)> asw::ui::InputBox::on_change

Callback invoked when the value changes.

Definition at line 33 of file input_box.h.

◆ placeholder

std::string asw::ui::InputBox::placeholder

Placeholder text shown when value is empty.

Definition at line 63 of file input_box.h.

◆ value

std::string asw::ui::InputBox::value

The current text value.

Definition at line 60 of file input_box.h.


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