11#include "../layout/layout.hpp"
12#include "../geometry/geometry.hpp"
13#include "../observer/observer.hpp"
14#include "../time/time.hpp"
15#include "../settings/settings.hpp"
16#include "../numeric/numeric.hpp"
17#include "../GUI/GUI.hpp"
18#include "../macros.hpp"
24hi_export_module(hikogui.widgets.widget);
26hi_export
namespace hi {
inline namespace v1 {
66 [[nodiscard]] generator<widget_intf&>
children(
bool include_invisible)
noexcept override
78 [[nodiscard]] hitbox
hitbox_test(point2 position)
const noexcept override
111 hi_axiom(loop::main().on_thread());
152 hi_axiom(loop::main().on_thread());
154 switch (event.type()) {
155 case gui_event_type::keyboard_enter:
160 case gui_event_type::keyboard_exit:
164 case gui_event_type::mouse_enter:
168 case gui_event_type::mouse_exit:
182 case gui_event_type::gui_activate_stay:
192 case gui_event_type::gui_activate_next:
196 case gui_event_type::gui_widget_next:
198 gui_event::window_set_keyboard_target(
id, keyboard_focus_group::normal, keyboard_focus_direction::forward));
201 case gui_event_type::gui_widget_prev:
203 gui_event::window_set_keyboard_target(
id, keyboard_focus_group::normal, keyboard_focus_direction::backward));
206 case gui_event_type::gui_menu_next:
209 gui_event::window_set_keyboard_target(
id, keyboard_focus_group::menu, keyboard_focus_direction::forward));
214 case gui_event_type::gui_menu_prev:
217 gui_event::window_set_keyboard_target(
id, keyboard_focus_group::menu, keyboard_focus_direction::backward));
222 case gui_event_type::gui_toolbar_next:
225 gui_event::window_set_keyboard_target(
id, keyboard_focus_group::toolbar, keyboard_focus_direction::forward));
230 case gui_event_type::gui_toolbar_prev:
233 gui_event::window_set_keyboard_target(
id, keyboard_focus_group::toolbar, keyboard_focus_direction::backward));
248 hi_axiom(loop::main().on_thread());
250 auto handled =
false;
252 for (
auto& child : this->
children(false)) {
253 handled |= child.handle_event_recursive(event, reject_list);
256 if (!std::ranges::any_of(reject_list, [&](
auto const& x) {
266 widget_id current_keyboard_widget,
267 keyboard_focus_group group,
268 keyboard_focus_direction direction)
const noexcept override
270 hi_axiom(loop::main().on_thread());
278 }
else if (current_keyboard_widget ==
id) {
283 for (
auto& child :
children(
false)) {
287 if (direction == keyboard_focus_direction::backward) {
291 for (
auto *child : children_) {
292 hi_axiom_not_null(child);
296 if (
auto tmp = child->find_next_widget({}, group, direction); tmp != 0) {
301 auto tmp = child->find_next_widget(current_keyboard_widget, group, direction);
302 if (tmp == current_keyboard_widget) {
307 }
else if (tmp != 0) {
319 return current_keyboard_widget;
328 hi_axiom(loop::main().on_thread());
344 [[nodiscard]] gui_window *
window() const noexcept
override
353 [[nodiscard]] hi::theme
const& theme() const noexcept
356 hi_assert_not_null(w);
360 [[nodiscard]] gfx_surface
const *surface() const noexcept
363 return w->surface.get();
369 [[nodiscard]]
virtual color background_color() const noexcept
372 if (phase() == widget_phase::hover) {
373 return theme().color(semantic_color::fill, _layout.layer + 1);
375 return theme().color(semantic_color::fill, _layout.layer);
378 return theme().color(semantic_color::fill, _layout.layer - 1);
382 [[nodiscard]]
virtual color foreground_color() const noexcept
385 if (phase() == widget_phase::hover) {
386 return theme().color(semantic_color::border, _layout.layer + 1);
388 return theme().color(semantic_color::border, _layout.layer);
391 return theme().color(semantic_color::border, _layout.layer - 1);
395 [[nodiscard]]
virtual color focus_color() const noexcept
399 return theme().color(semantic_color::accent);
400 }
else if (phase() == widget_phase::hover) {
401 return theme().color(semantic_color::border, _layout.layer + 1);
403 return theme().color(semantic_color::border, _layout.layer);
406 return theme().color(semantic_color::border, _layout.layer - 1);
410 [[nodiscard]]
virtual color accent_color() const noexcept
413 return theme().color(semantic_color::accent);
415 return theme().color(semantic_color::border, _layout.layer - 1);
419 [[nodiscard]]
virtual color label_color() const noexcept
422 return theme().text_style(semantic_text_style::label)->color;
424 return theme().color(semantic_color::border, _layout.layer - 1);
438 [[nodiscard]] aarectangle make_overlay_rectangle(aarectangle requested_rectangle)
const noexcept
440 hi_axiom(loop::main().on_thread());
444 auto const window_bounds = aarectangle{
layout().
window_size} - theme().margin<
float>();
445 auto const response_window_rectangle = fit(window_bounds, requested_window_rectangle);
@ end
Start from the end of the file.
@ begin
Start from the beginning of the file.
@ window_redraw
Request that part of the window gets redrawn on the next frame.
@ window_deactivate
The window is not longer the top-window.
@ window_activate
The window becomes the top-window.
@ partial
A widget is partially enabled.
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:33
A high-level geometric extent.
Definition extent2.hpp:32
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
virtual gui_window * window() const noexcept=0
Get the window that the widget is owned by.
widget_id id
The numeric identifier of a widget.
Definition widget_intf.hpp:30
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 void scroll_to_show(hi::aarectangle rectangle) noexcept=0
Scroll to show the given rectangle on the window.
virtual generator< widget_intf & > children(bool include_invisible) noexcept=0
Get a list of child widgets.
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:56
constexpr aarectangle clipping_rectangle_on_window() const noexcept
Get the clipping rectangle in window coordinate system.
Definition widget_layout.hpp:198
translate2 from_window
This matrix transforms window coordinates to local coordinates.
Definition widget_layout.hpp:83
extent2 window_size
Size of the window.
Definition widget_layout.hpp:87
2D constraints.
Definition box_constraints.hpp:25
A observer pointing to the whole or part of a observed_base.
Definition observer_intf.hpp:32
An interactive graphical object as part of the user-interface.
Definition widget.hpp:37
bool accepts_keyboard_focus(keyboard_focus_group group) const noexcept override
Check if the widget will accept keyboard focus.
Definition widget.hpp:109
observer< extent2 > minimum
The minimum size this widget is allowed to be.
Definition widget.hpp:41
virtual hitbox hitbox_test_from_parent(point2 position, hitbox sibling_hitbox) const noexcept
Call hitbox_test from a parent widget.
Definition widget.hpp:101
void scroll_to_show() noexcept
Scroll to show the important part of the widget.
Definition widget_intf.hpp:312
bool handle_event_recursive(gui_event const &event, std::vector< widget_id > const &reject_list=std::vector< widget_id >{}) noexcept override
Handle command recursive.
Definition widget.hpp:244
gui_window * window() const noexcept override
Get the window that the widget is owned by.
Definition widget.hpp:344
virtual widget_id find_next_widget(widget_id current_keyboard_widget, keyboard_focus_group group, keyboard_focus_direction direction) const noexcept override
Find the next widget that handles keyboard focus.
Definition widget.hpp:265
void scroll_to_show(hi::aarectangle rectangle) noexcept override
Scroll to show the given rectangle on the window.
Definition widget.hpp:326
void set_layout(widget_layout const &context) noexcept override
Update the internal layout of the widget.
Definition widget.hpp:121
generator< widget_intf & > children(bool include_invisible) noexcept override
Get a list of child widgets.
Definition widget.hpp:66
void draw(draw_context const &context) noexcept override
Draw the widget.
Definition widget.hpp:126
void request_redraw() const noexcept override
Request the widget to be redrawn on the next frame.
Definition widget.hpp:141
virtual hitbox hitbox_test_from_parent(point2 position) const noexcept
Call hitbox_test from a parent widget.
Definition widget.hpp:89
widget() noexcept
Constructor for creating sub views.
Definition widget.hpp:55
hitbox hitbox_test(point2 position) const noexcept override
Find the widget that is under the mouse cursor.
Definition widget.hpp:78
box_constraints update_constraints() noexcept override
Update the constraints of the widget.
Definition widget.hpp:115
void set_window(gui_window *window) noexcept override
Set the window for this tree of widgets.
Definition widget.hpp:335
widget(widget_intf const *parent) noexcept
Constructor for creating sub views.
Definition widget.hpp:49
bool process_event(gui_event const &event) const noexcept override
Send a event to the window.
Definition widget.hpp:130
bool handle_event(gui_event const &event) noexcept override
Handle command.
Definition widget.hpp:150
observer< extent2 > maximum
The maximum size this widget is allowed to be.
Definition widget.hpp:45