13#include "../GFX/draw_context.hpp"
14#include "../GUI/theme.hpp"
15#include "../GUI/hitbox.hpp"
16#include "../GUI/keyboard_focus_direction.hpp"
17#include "../GUI/keyboard_focus_group.hpp"
19#include "../GUI/widget_id.hpp"
20#include "../layout/box_constraints.hpp"
21#include "../geometry/module.hpp"
22#include "../observer.hpp"
23#include "../chrono.hpp"
24#include "../generator.hpp"
25#include "../cache.hpp"
26#include "../os_settings.hpp"
27#include "../tagged_id.hpp"
33namespace hi {
inline namespace v1 {
103 observer<extent2i>
maximum = extent2i::large();
117 [[nodiscard]]
virtual generator<widget const&>
children(
bool include_invisible)
const noexcept
122 [[nodiscard]] generator<widget&>
children(
bool include_invisible)
noexcept
124 for (
auto& child : const_cast<
widget const *>(this)->
children(include_invisible)) {
125 co_yield const_cast<widget&
>(child);
136 [[nodiscard]]
virtual hitbox
hitbox_test(point2i position)
const noexcept
229 virtual bool process_event(
gui_event const& event)
const noexcept
232 return parent->process_event(event);
275 widget_id current_keyboard_widget,
276 keyboard_focus_group group,
277 keyboard_focus_direction direction)
const noexcept;
279 [[nodiscard]] widget_id find_first_widget(keyboard_focus_group group)
const noexcept;
281 [[nodiscard]] widget_id find_last_widget(keyboard_focus_group group)
const noexcept;
285 [[nodiscard]]
bool is_first(keyboard_focus_group group)
const noexcept;
289 [[nodiscard]]
bool is_last(keyboard_focus_group group)
const noexcept;
311 [[nodiscard]] virtual gui_window *window() const noexcept
320 [[nodiscard]]
virtual hi::theme
const& theme() const noexcept
326 [[nodiscard]]
virtual gfx_surface
const *surface() const noexcept
335 [[nodiscard]]
virtual color background_color() const noexcept;
337 [[nodiscard]] virtual color foreground_color() const noexcept;
339 [[nodiscard]] virtual color focus_color() const noexcept;
341 [[nodiscard]] virtual color accent_color() const noexcept;
343 [[nodiscard]] virtual color label_color() const noexcept;
346 widget_layout _layout;
348 decltype(
mode)::callback_token _mode_cbt;
359 [[nodiscard]] aarectanglei make_overlay_rectangle(aarectanglei requested_rectangle) const noexcept;
362inline
widget *get_if(
widget *start, widget_id
id,
bool include_invisible) noexcept
366 if (start->id ==
id) {
369 for (
auto& child : start->
children(include_invisible)) {
370 if (
hilet r = get_if(&child,
id, include_invisible); r !=
nullptr) {
377inline widget& get(
widget& start, widget_id
id,
bool include_invisible)
379 if (
auto r = get_if(
std::addressof(start),
id, include_invisible); r !=
nullptr) {
382 throw not_found_error(
"get widget by id");
Definition of GUI event types.
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:238
#define hi_assert_not_null(x,...)
Assert if an expression is not nullptr.
Definition assert.hpp:223
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
@ window_redraw
Request that part of the window gets redrawn on the next frame.
@ rectangle
The gui_event has rectangle data.
@ enabled
The widget is fully enabled.
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
Draw context for drawing using the HikoGUI shaders.
Definition draw_context.hpp:211
A user interface event.
Definition gui_event.hpp:74
2D constraints.
Definition box_constraints.hpp:22
An interactive graphical object as part of the user-interface.
Definition widget.hpp:46
virtual void draw(draw_context const &context) noexcept
Draw the widget.
Definition widget.hpp:227
widget_layout const & layout() const noexcept
Get the current layout for this widget.
Definition widget.hpp:208
bool is_first(keyboard_focus_group group) const noexcept
Is this widget the first widget in the parent container.
int logical_layer
The logical layer of the widget.
Definition widget.hpp:95
virtual void set_layout(widget_layout const &context) noexcept
Update the internal layout of the widget.
Definition widget.hpp:201
int semantic_layer
The draw layer of the widget.
Definition widget.hpp:86
observer< extent2i > minimum
The minimum size this widget is allowed to be.
Definition widget.hpp:99
observer< bool > hover
Mouse cursor is hovering over the widget.
Definition widget.hpp:66
virtual void scroll_to_show(hi::aarectanglei rectangle) noexcept
Scroll to show the given rectangle on the window.
virtual void request_redraw() const noexcept
Request the widget to be redrawn on the next frame.
Definition widget.hpp:240
virtual bool handle_event_recursive(gui_event const &event, std::vector< widget_id > const &reject_list=std::vector< widget_id >{}) noexcept
Handle command recursive.
widget(widget *parent) noexcept
virtual hitbox hitbox_test_from_parent(point2i position, hitbox sibling_hitbox) const noexcept
Call hitbox_test from a parent widget.
Definition widget.hpp:159
virtual generator< widget const & > children(bool include_invisible) const noexcept
Get a list of child widgets.
Definition widget.hpp:117
virtual box_constraints update_constraints() noexcept
Update the constraints of the widget.
Definition widget.hpp:184
virtual bool accepts_keyboard_focus(keyboard_focus_group group) const noexcept
Check if the widget will accept keyboard focus.
Definition widget.hpp:167
virtual bool handle_event(gui_event const &event) noexcept
Handle command.
virtual widget_id find_next_widget(widget_id current_keyboard_widget, keyboard_focus_group group, keyboard_focus_direction direction) const noexcept
Find the next widget that handles keyboard focus.
std::vector< widget_id > parent_chain() const noexcept
Get a list of parents of a given widget.
observer< extent2i > maximum
The maximum size this widget is allowed to be.
Definition widget.hpp:103
widget * parent
Pointer to the parent widget.
Definition widget.hpp:51
bool is_last(keyboard_focus_group group) const noexcept
Is this widget the last widget in the parent container.
void scroll_to_show() noexcept
Scroll to show the important part of the widget.
Definition widget.hpp:301
observer< widget_mode > mode
The widget mode.
Definition widget.hpp:62
observer< bool > focus
The widget has keyboard focus.
Definition widget.hpp:70
virtual hitbox hitbox_test(point2i position) const noexcept
Find the widget that is under the mouse cursor.
Definition widget.hpp:136
virtual hitbox hitbox_test_from_parent(point2i position) const noexcept
Call hitbox_test from a parent widget.
Definition widget.hpp:147
The layout of a widget.
Definition widget_layout.hpp:38
translate2i from_parent
This matrix transforms parent widget's coordinates to local coordinates.
Definition widget_layout.hpp:57
constexpr aarectanglei clipping_rectangle_on_window() const noexcept
Get the clipping rectangle in window coordinate system.
Definition widget_layout.hpp:146