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
checkbox.h
Go to the documentation of this file.
1
8
9#ifndef ASW_MODULES_UI_CHECKBOX_H
10#define ASW_MODULES_UI_CHECKBOX_H
11
12#include <functional>
13
14#include "button.h"
15
16namespace asw::ui {
17
25class Checkbox : public Button {
26public:
29 std::optional<CheckboxStyle> checkbox_style;
30
36 const CheckboxStyle& get_checkbox_style(const Context& ctx) const
37 {
39 }
40
42 bool checked = false;
43
45 std::function<void(bool)> on_change;
46
49
53
58 void draw(Context& ctx) override;
59
64 void activate(Context& ctx) override;
65};
66
67} // namespace asw::ui
68
69#endif // ASW_MODULES_UI_CHECKBOX_H
Button widget for the ASW UI module.
An interactive button widget.
Definition button.h:24
A button that toggles between checked and unchecked.
Definition checkbox.h:25
void draw(Context &ctx) override
Draw the checkbox.
Definition checkbox.cpp:17
std::function< void(bool)> on_change
Callback invoked when checked changes by user input.
Definition checkbox.h:45
asw::Texture texture_checked_hover
Texture shown when checked and hovered or focused. Falls back to texture_checked.
Definition checkbox.h:52
bool checked
Whether the box is checked.
Definition checkbox.h:42
const CheckboxStyle & get_checkbox_style(const Context &ctx) const
Get the style this checkbox draws with.
Definition checkbox.h:36
asw::Texture texture_checked
Texture shown when checked. Falls back to texture.
Definition checkbox.h:48
void activate(Context &ctx) override
Toggle checked, then call on_change and on_click.
Definition checkbox.cpp:8
std::optional< CheckboxStyle > checkbox_style
Style for this checkbox only. Uses the theme checkbox style when empty. The inherited Button::style i...
Definition checkbox.h:29
Shared state for the UI system.
Definition context.h:97
Theme theme
The current UI theme.
Definition context.h:104
std::shared_ptr< SDL_Texture > Texture
Alias for a shared pointer to an SDL_Texture.
Definition types.h:76
How a checkbox looks. Set on Theme::checkbox for every checkbox, or on Checkbox::checkbox_style for o...
Definition theme.h:66
CheckboxStyle checkbox
Default checkbox style.
Definition theme.h:267