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 "../theme/theme.hpp"
18#include "../GUI/GUI.hpp"
19#include "../macros.hpp"
25hi_export_module(hikogui.widgets.widget);
27hi_export
namespace hi {
inline namespace v1 {
50 explicit widget() noexcept : widget_intf()
61 [[nodiscard]] generator<widget_intf&>
children(
bool include_invisible)
noexcept override
73 [[nodiscard]] hitbox
hitbox_test(point2 position)
const noexcept override
106 hi_axiom(loop::main().on_thread());
128 return p->process_event(event);
147 hi_axiom(loop::main().on_thread());
149 switch (event.type()) {
150 case gui_event_type::keyboard_enter:
155 case gui_event_type::keyboard_exit:
159 case gui_event_type::mouse_enter:
163 case gui_event_type::mouse_exit:
177 case gui_event_type::gui_activate_stay:
187 case gui_event_type::gui_activate_next:
191 case gui_event_type::gui_widget_next:
193 gui_event::window_set_keyboard_target(
id, keyboard_focus_group::normal, keyboard_focus_direction::forward));
196 case gui_event_type::gui_widget_prev:
198 gui_event::window_set_keyboard_target(
id, keyboard_focus_group::normal, keyboard_focus_direction::backward));
201 case gui_event_type::gui_menu_next:
204 gui_event::window_set_keyboard_target(
id, keyboard_focus_group::menu, keyboard_focus_direction::forward));
209 case gui_event_type::gui_menu_prev:
212 gui_event::window_set_keyboard_target(
id, keyboard_focus_group::menu, keyboard_focus_direction::backward));
217 case gui_event_type::gui_toolbar_next:
220 gui_event::window_set_keyboard_target(
id, keyboard_focus_group::toolbar, keyboard_focus_direction::forward));
225 case gui_event_type::gui_toolbar_prev:
228 gui_event::window_set_keyboard_target(
id, keyboard_focus_group::toolbar, keyboard_focus_direction::backward));
243 hi_axiom(loop::main().on_thread());
245 auto handled =
false;
247 for (
auto& child : this->
children(
false)) {
248 handled |= child.handle_event_recursive(event, reject_list);
251 if (!std::ranges::any_of(reject_list, [&](
auto const& x) {
261 widget_id current_keyboard_widget,
262 keyboard_focus_group group,
263 keyboard_focus_direction direction)
const noexcept override
265 hi_axiom(loop::main().on_thread());
273 }
else if (current_keyboard_widget ==
id) {
278 for (
auto& child :
children(
false)) {
282 if (direction == keyboard_focus_direction::backward) {
286 for (
auto *child : children_) {
287 hi_axiom_not_null(child);
291 if (
auto tmp = child->find_next_widget({}, group, direction); tmp != 0) {
296 auto tmp = child->find_next_widget(current_keyboard_widget, group, direction);
297 if (tmp == current_keyboard_widget) {
302 }
else if (tmp != 0) {
314 return current_keyboard_widget;
323 hi_axiom(loop::main().on_thread());
326 p->scroll_to_show(_layout.to_parent *
rectangle);
330 [[nodiscard]] hi::theme
const& theme() const noexcept
332 hi_assert_not_null(window);
333 return window->theme;
336 [[nodiscard]] gfx_surface
const *surface() const noexcept
339 return window->surface.get();
345 [[nodiscard]]
virtual color background_color() const noexcept
348 if (phase() == widget_phase::hover) {
349 return theme().fill_color(_layout.layer + 1);
351 return theme().fill_color(_layout.layer);
354 return theme().fill_color(_layout.layer - 1);
358 [[nodiscard]]
virtual color foreground_color() const noexcept
361 if (phase() == widget_phase::hover) {
362 return theme().border_color(_layout.layer + 1);
364 return theme().border_color(_layout.layer);
367 return theme().border_color(_layout.layer - 1);
371 [[nodiscard]]
virtual color focus_color() const noexcept
375 return theme().accent_color();
376 }
else if (phase() == widget_phase::hover) {
377 return theme().border_color(_layout.layer + 1);
379 return theme().border_color(_layout.layer);
382 return theme().border_color(_layout.layer - 1);
386 [[nodiscard]]
virtual color accent_color() const noexcept
389 return theme().accent_color();
391 return theme().border_color(_layout.layer - 1);
405 [[nodiscard]] aarectangle make_overlay_rectangle(aarectangle requested_rectangle)
const noexcept
407 hi_axiom(loop::main().on_thread());
411 auto const window_bounds = aarectangle{
layout().
window_size} - theme().margin<
float>();
412 auto const response_window_rectangle = fit(window_bounds, requested_window_rectangle);
@ end
Start from the end of the file.
Definition seek_whence.hpp:17
@ begin
Start from the beginning of the file.
Definition seek_whence.hpp:15
@ window_redraw
Request that part of the window gets redrawn on the next frame.
Definition gui_event_type.hpp:46
@ window_deactivate
The window is not longer the top-window.
Definition gui_event_type.hpp:58
@ window_activate
The window becomes the top-window.
Definition gui_event_type.hpp:57
@ partial
A widget is partially enabled.
Definition widget_state.hpp:73
The HikoGUI namespace.
Definition array_generic.hpp:21
The HikoGUI API version 1.
Definition array_generic.hpp:22
@ color
A color value was modified.
Definition style_modify_mask.hpp:27
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
widget_id id
The numeric identifier of a widget.
Definition widget_intf.hpp:31
widget_layout const & layout() const noexcept
Get the current layout for this widget.
Definition widget_intf.hpp:241
virtual generator< widget_intf & > children(bool include_invisible=true) noexcept=0
Get a list of child widgets.
widget_intf * parent() const noexcept
Pointer to the parent widget.
Definition widget_intf.hpp:113
virtual void scroll_to_show(hi::aarectangle rectangle) noexcept=0
Scroll to show the given rectangle on the window.
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:38
bool accepts_keyboard_focus(keyboard_focus_group group) const noexcept override
Check if the widget will accept keyboard focus.
Definition widget.hpp:104
observer< extent2 > minimum
The minimum size this widget is allowed to be.
Definition widget.hpp:42
virtual hitbox hitbox_test_from_parent(point2 position, hitbox sibling_hitbox) const noexcept
Call hitbox_test from a parent widget.
Definition widget.hpp:96
void scroll_to_show() noexcept
Scroll to show the important part of the widget.
Definition widget_intf.hpp:347
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:239
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:260
void scroll_to_show(hi::aarectangle rectangle) noexcept override
Scroll to show the given rectangle on the window.
Definition widget.hpp:321
void set_layout(widget_layout const &context) noexcept override
Update the internal layout of the widget.
Definition widget.hpp:116
generator< widget_intf & > children(bool include_invisible) noexcept override
Get a list of child widgets.
Definition widget.hpp:61
void draw(draw_context const &context) noexcept override
Draw the widget.
Definition widget.hpp:121
void request_redraw() const noexcept override
Request the widget to be redrawn on the next frame.
Definition widget.hpp:136
virtual hitbox hitbox_test_from_parent(point2 position) const noexcept
Call hitbox_test from a parent widget.
Definition widget.hpp:84
widget() noexcept
Constructor for creating sub views.
Definition widget.hpp:50
hitbox hitbox_test(point2 position) const noexcept override
Find the widget that is under the mouse cursor.
Definition widget.hpp:73
box_constraints update_constraints() noexcept override
Update the constraints of the widget.
Definition widget.hpp:110
bool process_event(gui_event const &event) const noexcept override
Send a event to the window.
Definition widget.hpp:125
bool handle_event(gui_event const &event) noexcept override
Handle command.
Definition widget.hpp:145
observer< extent2 > maximum
The maximum size this widget is allowed to be.
Definition widget.hpp:46