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
include
asw
modules
ui
input_box.h
Go to the documentation of this file.
1
8
9
#ifndef ASW_MODULES_UI_INPUT_BOX_H
10
#define ASW_MODULES_UI_INPUT_BOX_H
11
12
#include <functional>
13
#include <optional>
14
#include <string>
15
16
#include "
../types.h
"
17
#include "
context.h
"
18
#include "
widget.h
"
19
20
namespace
asw::ui
{
21
24
class
InputBox
:
public
Widget
{
25
public
:
28
InputBox
()
29
{
30
focusable
=
true
;
31
}
32
35
~InputBox
()
override
;
36
37
InputBox
(
const
InputBox
&) =
delete
;
38
InputBox
&
operator=
(
const
InputBox
&) =
delete
;
39
41
std::function<void(
const
std::string&)>
on_change
;
42
48
void
on_focus_changed
(
Context
& ctx,
bool
focused)
override
;
49
56
bool
on_event
(
Context
& ctx,
const
UIEvent
& e)
override
;
57
62
void
draw
(
Context
& ctx)
override
;
63
65
asw::Font
font
;
66
68
std::string
value
;
69
71
std::string
placeholder
;
72
74
std::optional<InputStyle>
style
;
75
81
const
InputStyle
&
get_style
(
const
Context
& ctx)
const
82
{
83
return
style
? *
style
: ctx.
theme
.
input
;
84
}
85
86
private
:
87
std::size_t
_cursor_pos
= 0;
88
90
float
_scroll
= 0.0F;
91
};
92
93
}
// namespace asw::ui
94
95
#endif
// ASW_MODULES_UI_INPUT_BOX_H
asw::ui::Context
Shared state for the UI system.
Definition
context.h:97
asw::ui::Context::theme
Theme theme
The current UI theme.
Definition
context.h:104
asw::ui::InputBox
A text input widget.
Definition
input_box.h:24
asw::ui::InputBox::font
asw::Font font
The font for the text. Uses the theme font when empty.
Definition
input_box.h:65
asw::ui::InputBox::operator=
InputBox & operator=(const InputBox &)=delete
asw::ui::InputBox::style
std::optional< InputStyle > style
Style for this input box only. Uses the theme input style when empty.
Definition
input_box.h:74
asw::ui::InputBox::_scroll
float _scroll
How far the text is scrolled left, so the caret stays in view.
Definition
input_box.h:90
asw::ui::InputBox::draw
void draw(Context &ctx) override
Draw the input box.
Definition
input_box.cpp:144
asw::ui::InputBox::_cursor_pos
std::size_t _cursor_pos
Definition
input_box.h:87
asw::ui::InputBox::on_focus_changed
void on_focus_changed(Context &ctx, bool focused) override
Called when focus state changes.
Definition
input_box.cpp:51
asw::ui::InputBox::InputBox
InputBox()
Default constructor.
Definition
input_box.h:28
asw::ui::InputBox::on_change
std::function< void(const std::string &)> on_change
Callback invoked when the value changes.
Definition
input_box.h:41
asw::ui::InputBox::placeholder
std::string placeholder
Placeholder text shown when value is empty.
Definition
input_box.h:71
asw::ui::InputBox::~InputBox
~InputBox() override
Stops text input if the box is destroyed while focused.
Definition
input_box.cpp:44
asw::ui::InputBox::InputBox
InputBox(const InputBox &)=delete
asw::ui::InputBox::on_event
bool on_event(Context &ctx, const UIEvent &e) override
Handle a UI event.
Definition
input_box.cpp:63
asw::ui::InputBox::value
std::string value
The current text value.
Definition
input_box.h:68
asw::ui::InputBox::get_style
const InputStyle & get_style(const Context &ctx) const
Get the style this input box draws with.
Definition
input_box.h:81
asw::ui::Widget
Base class for all UI widgets.
Definition
widget.h:43
asw::ui::Widget::focusable
bool focusable
Whether the widget can receive focus. Focusable widgets are also the ones the pointer can press.
Definition
widget.h:88
context.h
UI context and focus management for the ASW UI module.
asw::ui
Definition
button.h:20
asw::Font
std::shared_ptr< TTF_Font > Font
Alias for a shared pointer to an TTF_Font.
Definition
types.h:79
asw::ui::InputStyle
How an input box looks. Set on Theme::input for every input box, or on InputBox::style for one input ...
Definition
theme.h:116
asw::ui::Theme::input
InputStyle input
Default input box style.
Definition
theme.h:270
asw::ui::UIEvent
Event structure for UI interactions.
Definition
event.h:21
types.h
Types used throughout the ASW library.
widget.h
Base widget class for the ASW UI module.
Generated by
1.12.0