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 <optional>
13#include <vector>
14
15#include "navigation.h"
16#include "theme.h"
17#include "widget.h"
18
19namespace asw::ui {
20
24public:
29 Widget* focused() const
30 {
31 return _focused;
32 }
33
39 void set_focus(Context& ctx, Widget* w);
40
44
49 void focus_next(Context& ctx);
50
55 void focus_prev(Context& ctx);
56
61 bool focus_start(Context& ctx);
62
74 void focus_dir(Context& ctx, int dx, int dy);
75
76private:
77 friend class Root;
78
79 // Rebuild the focusable widget list from the widget tree
80 void rebuild(Context& ctx, Widget& root);
81
82 void dfs(Widget& w);
83
84 std::vector<Widget*> _focusables;
85 Widget* _focused = nullptr;
86
87 // Whether the last rebuild found the focused widget in the tree
88 bool _focused_found = false;
89
90 // Across position kept during repeated moves one way
91 std::optional<float> _lane_x;
92 std::optional<float> _lane_y;
93};
94
97class Context {
98public:
101 Context() = default;
102
105
108
112
115 bool show_focus = false;
116
117private:
118 friend class Root;
119
120 // Widget pressed by the pointer, it gets pointer events until release
122
123 // Widget under the pointer
124 Widget* hover = nullptr;
125};
126
127} // namespace asw::ui
128
129#endif // ASW_UI_CONTEXT_H
Shared state for the UI system.
Definition context.h:97
bool show_focus
Whether focus is shown. Root turns it on for keyboard and controller navigation and off when the mous...
Definition context.h:115
Widget * hover
Definition context.h:124
Navigation navigation
Actions to read for focus navigation. Empty names use the built in keys.
Definition context.h:111
Widget * pointer_capture
Definition context.h:121
Context()=default
Default constructor.
FocusManager focus
The focus manager.
Definition context.h:107
Theme theme
The current UI theme.
Definition context.h:104
Manages focus navigation for UI widgets.
Definition context.h:23
void focus_prev(Context &ctx)
Move focus to the previous focusable widget.
Definition context.cpp:71
void focus_dir(Context &ctx, int dx, int dy)
Move focus in a direction based on widget positions.
Definition context.cpp:94
std::vector< Widget * > _focusables
Definition context.h:84
bool focus_start(Context &ctx)
Focus default_focus, or the first focusable widget, when nothing has focus.
Definition context.cpp:19
std::optional< float > _lane_y
Definition context.h:92
void set_focus(Context &ctx, Widget *w)
Set focus to a specific widget.
Definition context.cpp:31
void dfs(Widget &w)
Definition context.cpp:197
std::optional< float > _lane_x
Definition context.h:91
Widget * default_focus
Widget focused by the first navigation press when nothing has focus. The first focusable widget when ...
Definition context.h:43
void focus_next(Context &ctx)
Move focus to the next focusable widget.
Definition context.cpp:50
Widget * focused() const
Get the currently focused widget.
Definition context.h:29
void rebuild(Context &ctx, Widget &root)
Definition context.cpp:7
Root container that manages the UI tree, input, and rendering.
Definition root.h:49
Base class for all UI widgets.
Definition widget.h:43
Action based navigation for the ASW UI module.
Action names the UI reads for focus navigation, see asw/modules/action.h.
Definition navigation.h:33
Theme configuration for UI elements.
Definition theme.h:250
UI theme configuration for the ASW UI module.
Base widget class for the ASW UI module.