8#include "widget_layout.hpp"
9#include "widget_id.hpp"
10#include "widget_state.hpp"
11#include "keyboard_focus_group.hpp"
12#include "../layout/layout.hpp"
13#include "../GFX/GFX.hpp"
14#include "../telemetry/telemetry.hpp"
15#include "../macros.hpp"
18hi_export_module(hikogui.GUI : widget_intf);
20hi_export
namespace hi {
47 release_widget_id(
id);
56 static std::optional<widget_state> old_state = std::nullopt;
59 if (need_reconstrain(*old_state, *
state)) {
60 ++global_counter<
"widget:state:reconstrain">;
63 }
else if (need_relayout(*old_state, *
state)) {
64 ++global_counter<
"widget:state:relayout">;
67 }
else if (need_redraw(*old_state, *
state)) {
68 ++global_counter<
"widget:state:redraw">;
78 template<forward_of<
void()> Func>
79 [[nodiscard]]
callback<void()>
subscribe(Func&& func, callback_flags flags = callback_flags::synchronous)
noexcept
81 return notifier.subscribe(std::forward<Func>(func), flags);
86 [[nodiscard]]
auto operator co_await()
const noexcept
91 [[nodiscard]]
size_t layer() const noexcept
93 return state->layer();
96 void set_layer(
size_t new_layer)
noexcept
98 state->set_layer(new_layer);
103 return state->mode();
108 state->set_mode(new_mode);
111 [[nodiscard]] widget_value value() const noexcept
113 return state->value();
116 void set_value(widget_value new_value)
noexcept
118 state->set_value(new_value);
121 [[nodiscard]] widget_phase phase() const noexcept
123 return state->phase();
126 void set_pressed(
bool pressed)
noexcept
128 state->set_pressed(pressed);
131 void set_hover(
bool hover)
noexcept
133 state->set_hover(hover);
136 void set_active(
bool active)
noexcept
138 state->set_active(active);
141 [[nodiscard]]
bool focus() const noexcept
143 return state->focus();
146 void set_focus(
bool new_focus)
noexcept
148 state->set_focus(new_focus);
163 [[nodiscard]]
virtual gui_window *
window() const noexcept = 0;
234 [[nodiscard]]
virtual hitbox
hitbox_test(point2 position)
const noexcept = 0;
264 std::vector<widget_id> const& reject_list =
std::vector<widget_id>{})
noexcept = 0;
281 widget_id current_keyboard_widget,
282 keyboard_focus_group group,
283 keyboard_focus_direction direction)
const noexcept = 0;
294 while (to_bool(w = w->parent)) {
325 hi_assert_not_null(start);
327 if (start->id ==
id) {
330 for (
auto& child : start->children(include_invisible)) {
331 if (
auto const r = get_if(&child,
id, include_invisible); r !=
nullptr) {
338inline widget_intf& get(widget_intf& start, widget_id
id,
bool include_invisible)
340 if (
auto r = get_if(
std::addressof(start),
id, include_invisible); r !=
nullptr) {
343 throw not_found_error(
"get widget by id");
@ window_relayout
Request that widgets get laid out on the next frame.
@ window_reconstrain
Request that widget get constraint on the next frame.
@ rectangle
The gui_event has rectangle data.
widget_mode
The mode that the widget is operating at.
Definition widget_state.hpp:25
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition callback.hpp:77
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:33
A rectangle / parallelogram in 3D space.
Definition rectangle.hpp:25
Draw context for drawing using the HikoGUI shaders.
Definition draw_context_intf.hpp:209
A user interface event.
Definition gui_event.hpp:82
Definition widget_intf.hpp:24
notifier< void()> notifier
Notifier which is called after an action is completed by a widget.
Definition widget_intf.hpp:39
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:288
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:30
virtual void request_redraw() const noexcept=0
Request the widget to be redrawn on the next frame.
widget_layout const & layout() const noexcept
Get the current layout for this widget.
Definition widget_intf.hpp:206
void scroll_to_show() noexcept
Scroll to show the important part of the widget.
Definition widget_intf.hpp:312
widget_intf * parent
Pointer to the parent widget.
Definition widget_intf.hpp:35
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 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.
callback< void()> subscribe(Func &&func, callback_flags flags=callback_flags::synchronous) noexcept
Subscribe a callback to be called when an action is completed by the widget.
Definition widget_intf.hpp:79
observer< widget_state > state
The current state of the widget.
Definition widget_intf.hpp:43
The layout of a widget.
Definition widget_layout.hpp:56
The state the widget is in.
Definition widget_state.hpp:104
2D constraints.
Definition box_constraints.hpp:25
A observer pointing to the whole or part of a observed_base.
Definition observer_intf.hpp:32