HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
widget_intf.hpp
1
2
3#pragma once
4
5#include "hitbox.hpp"
6#include "widget_layout.hpp"
7#include "widget_id.hpp"
8#include "keyboard_focus_group.hpp"
9#include "../layout/module.hpp"
10#include "../GFX/GFX.hpp"
11#include "../telemetry/telemetry.hpp"
12#include "../macros.hpp"
13
14namespace hi { inline namespace v1 {
15class gui_window;
16
18public:
23 widget_id id = {};
24
28 widget_intf *parent = nullptr;
29
30 virtual ~widget_intf() = default;
31
33
39 virtual void set_window(gui_window *window) noexcept = 0;
40
46 [[nodiscard]] virtual gui_window *window() const noexcept = 0;
47
51
55 {
56 for (auto& child : const_cast<widget_intf *>(this)->children(include_invisible)) {
57 co_yield child;
58 }
59 }
60
73
86
90
106
114 [[nodiscard]] virtual hitbox hitbox_test(point2 position) const noexcept = 0;
115
119 [[nodiscard]] virtual bool accepts_keyboard_focus(keyboard_focus_group group) const noexcept = 0;
120
124
128
134
144 std::vector<widget_id> const& reject_list = std::vector<widget_id>{}) noexcept = 0;
145
160 [[nodiscard]] virtual widget_id find_next_widget(
161 widget_id current_keyboard_widget,
162 keyboard_focus_group group,
163 keyboard_focus_direction direction) const noexcept = 0;
164
165 [[nodiscard]] virtual widget_id find_first_widget(keyboard_focus_group group) const noexcept = 0;
166
167 [[nodiscard]] virtual widget_id find_last_widget(keyboard_focus_group group) const noexcept = 0;
168
173 {
175
176 if (auto w = this) {
177 chain.push_back(w->id);
178 while (to_bool(w = w->parent)) {
179 chain.push_back(w->id);
180 }
181 }
182
183 return chain;
184 }
185
192 virtual void scroll_to_show(hi::aarectangle rectangle) noexcept = 0;
193
200};
201
202inline widget_intf *get_if(widget_intf *start, widget_id id, bool include_invisible) noexcept
203{
204 hi_assert_not_null(start);
205
206 if (start->id == id) {
207 return start;
208 }
209 for (auto& child : start->children(include_invisible)) {
210 if (hilet r = get_if(&child, id, include_invisible); r != nullptr) {
211 return r;
212 }
213 }
214 return nullptr;
215}
216
217inline widget_intf& get(widget_intf& start, widget_id id, bool include_invisible)
218{
219 if (auto r = get_if(std::addressof(start), id, include_invisible); r != nullptr) {
220 return *r;
221 }
222 throw not_found_error("get widget by id");
223}
224
225}} // namespace hi::v1
@ rectangle
The gui_event has rectangle data.
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:29
A rectangle / parallelogram in 3D space.
Definition rectangle.hpp:21
Draw context for drawing using the HikoGUI shaders.
Definition draw_context.hpp:208
A user interface event.
Definition gui_event.hpp:75
Definition widget_intf.hpp:17
virtual gui_window * window() const noexcept=0
Get the window that the widget is owned by.
std::vector< widget_id > parent_chain() const noexcept
Get a list of parents of a given widget.
Definition widget_intf.hpp:172
virtual bool handle_event_recursive(gui_event const &event, std::vector< widget_id > const &reject_list=std::vector< widget_id >{}) noexcept=0
Handle command recursive.
widget_id id
The numeric identifier of a widget.
Definition widget_intf.hpp:23
virtual void request_redraw() const noexcept=0
Request the widget to be redrawn on the next frame.
void scroll_to_show() noexcept
Scroll to show the important part of the widget.
Definition widget_intf.hpp:196
widget_intf * parent
Pointer to the parent widget.
Definition widget_intf.hpp:28
virtual bool process_event(gui_event const &event) const noexcept=0
Send a event to the window.
virtual bool accepts_keyboard_focus(keyboard_focus_group group) const noexcept=0
Check if the widget will accept keyboard focus.
virtual box_constraints update_constraints() noexcept=0
Update the constraints of the widget.
virtual widget_id find_next_widget(widget_id current_keyboard_widget, keyboard_focus_group group, keyboard_focus_direction direction) const noexcept=0
Find the next widget that handles keyboard focus.
virtual void set_layout(widget_layout const &context) noexcept=0
Update the internal layout of the widget.
virtual void scroll_to_show(hi::aarectangle rectangle) noexcept=0
Scroll to show the given rectangle on the window.
virtual bool handle_event(gui_event const &event) noexcept=0
Handle command.
virtual hitbox hitbox_test(point2 position) const noexcept=0
Find the widget that is under the mouse cursor.
virtual widget_layout const & layout() const noexcept=0
Get the current layout for this widget.
virtual generator< widget_intf & > children(bool include_invisible) noexcept=0
Get a list of child widgets.
virtual void draw(draw_context const &context) noexcept=0
Draw the widget.
virtual void set_window(gui_window *window) noexcept=0
Set the window for this tree of widgets.
The layout of a widget.
Definition widget_layout.hpp:38
2D constraints.
Definition box_constraints.hpp:25
T addressof(T... args)
T push_back(T... args)