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
button.h
Go to the documentation of this file.
1
8
9
#ifndef ASW_MODULES_UI_BUTTON_H
10
#define ASW_MODULES_UI_BUTTON_H
11
12
#include <functional>
13
#include <string>
14
15
#include "
../types.h
"
16
#include "
context.h
"
17
#include "
widget.h
"
18
19
namespace
asw::ui
{
20
23
class
Button
:
public
Widget
{
24
public
:
27
Button
()
28
{
29
focusable
=
true
;
30
}
31
33
std::function<void()>
on_click
;
34
40
void
on_focus_changed
(
Context
& ctx,
bool
focused)
override
;
41
48
bool
on_event
(
Context
& ctx,
const
UIEvent
& e)
override
;
49
54
void
draw
(
Context
& ctx)
override
;
55
57
float
padding
= 0.0f;
58
60
asw::Font
font
;
61
63
std::string
text
;
64
66
asw::Texture
texture
;
67
73
void
set_texture
(
const
asw::Texture
& tex,
bool
auto_size =
false
);
74
80
void
set_text
(
const
std::string& t,
bool
auto_size =
false
);
81
82
};
83
84
}
// namespace asw::ui
85
86
#endif
// ASW_MODULES_UI_BUTTON_H
asw::ui::Button
An interactive button widget.
Definition
button.h:23
asw::ui::Button::on_click
std::function< void()> on_click
Callback invoked when the button is clicked.
Definition
button.h:33
asw::ui::Button::on_focus_changed
void on_focus_changed(Context &ctx, bool focused) override
Called when focus state changes.
Definition
button.cpp:6
asw::ui::Button::on_event
bool on_event(Context &ctx, const UIEvent &e) override
Handle a UI event.
Definition
button.cpp:12
asw::ui::Button::texture
asw::Texture texture
The texture to display on the button.
Definition
button.h:66
asw::ui::Button::draw
void draw(Context &ctx) override
Draw the button.
Definition
button.cpp:87
asw::ui::Button::text
std::string text
The button text.
Definition
button.h:63
asw::ui::Button::set_text
void set_text(const std::string &t, bool auto_size=false)
Set the text, optionally resizing the button to match.
Definition
button.cpp:76
asw::ui::Button::font
asw::Font font
The font to use for the button text.
Definition
button.h:60
asw::ui::Button::padding
float padding
Padding applied inside the button on all sides.
Definition
button.h:57
asw::ui::Button::Button
Button()
Default constructor.
Definition
button.h:27
asw::ui::Button::set_texture
void set_texture(const asw::Texture &tex, bool auto_size=false)
Set the texture, optionally resizing the button to match.
Definition
button.cpp:67
asw::ui::Context
Shared state for the UI system.
Definition
context.h:75
asw::ui::Widget
Base class for all UI widgets.
Definition
widget.h:28
asw::ui::Widget::focusable
bool focusable
Whether the widget can receive focus.
Definition
widget.h:66
context.h
UI context and focus management for the ASW UI module.
asw::ui
Definition
button.h:19
asw::Font
std::shared_ptr< TTF_Font > Font
Alias for a shared pointer to an TTF_Font.
Definition
types.h:41
asw::Texture
std::shared_ptr< SDL_Texture > Texture
Alias for a shared pointer to an SDL_Texture.
Definition
types.h:38
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