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
context.h
Go to the documentation of this file.
1
8
9#ifndef ASW_UI_CONTEXT_H
10#define ASW_UI_CONTEXT_H
11
12#include <vector>
13
14#include "theme.h"
15#include "widget.h"
16
17namespace asw::ui {
18
22public:
28 void rebuild(Context& ctx, Widget& root);
29
34 Widget* focused() const
35 {
36 return focused_;
37 }
38
44 void set_focus(Context& ctx, Widget* w);
45
50 void focus_next(Context& ctx);
51
56 void focus_prev(Context& ctx);
57
64 void focus_dir(Context& ctx, int dx, int dy);
65
66private:
67 void dfs(Widget& w);
68
69 std::vector<Widget*> focusables_;
70 Widget* focused_ = nullptr;
71};
72
75class Context {
76public:
79 Context() = default;
80
83
86
89
91 Widget* hover = nullptr;
92
94 bool pointer_down = false;
95
97 bool need_focus_rebuild = true;
98};
99
100} // namespace asw::ui
101
102#endif // ASW_UI_CONTEXT_H
Shared state for the UI system.
Definition context.h:75
Widget * hover
The widget currently being hovered.
Definition context.h:91
bool pointer_down
Whether the pointer is currently down.
Definition context.h:94
Widget * pointer_capture
The widget that has captured pointer input.
Definition context.h:88
Context()=default
Default constructor.
FocusManager focus
The focus manager.
Definition context.h:85
Theme theme
The current UI theme.
Definition context.h:82
bool need_focus_rebuild
Whether the focus list needs to be rebuilt.
Definition context.h:97
Manages focus navigation for UI widgets.
Definition context.h:21
void focus_prev(Context &ctx)
Move focus to the previous focusable widget.
Definition context.cpp:58
void focus_dir(Context &ctx, int dx, int dy)
Move focus in a direction based on widget positions.
Definition context.cpp:82
void set_focus(Context &ctx, Widget *w)
Set focus to a specific widget.
Definition context.cpp:22
void dfs(Widget &w)
Definition context.cpp:138
void focus_next(Context &ctx)
Move focus to the next focusable widget.
Definition context.cpp:36
std::vector< Widget * > focusables_
Definition context.h:69
Widget * focused() const
Get the currently focused widget.
Definition context.h:34
void rebuild(Context &ctx, Widget &root)
Rebuild the focusable widget list from the widget tree.
Definition context.cpp:6
Base class for all UI widgets.
Definition widget.h:28
Theme configuration for UI elements.
Definition theme.h:18
UI theme configuration for the ASW UI module.
Base widget class for the ASW UI module.