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 {
60 [[nodiscard]] generator<widget_intf&>
children(
bool include_invisible)
noexcept override
72 [[nodiscard]] hitbox
hitbox_test(point2 position)
const noexcept override
105 hi_axiom(loop::main().on_thread());
127 return parent->process_event(event);
146 hi_axiom(loop::main().on_thread());
148 switch (event.type()) {
149 case gui_event_type::keyboard_enter:
154 case gui_event_type::keyboard_exit:
158 case gui_event_type::mouse_enter:
162 case gui_event_type::mouse_exit:
176 case gui_event_type::gui_activate_stay:
186 case gui_event_type::gui_activate_next:
190 case gui_event_type::gui_widget_next:
192 gui_event::window_set_keyboard_target(
id, keyboard_focus_group::normal, keyboard_focus_direction::forward));
195 case gui_event_type::gui_widget_prev:
197 gui_event::window_set_keyboard_target(
id, keyboard_focus_group::normal, keyboard_focus_direction::backward));
200 case gui_event_type::gui_menu_next:
203 gui_event::window_set_keyboard_target(
id, keyboard_focus_group::menu, keyboard_focus_direction::forward));
208 case gui_event_type::gui_menu_prev:
211 gui_event::window_set_keyboard_target(
id, keyboard_focus_group::menu, keyboard_focus_direction::backward));
216 case gui_event_type::gui_toolbar_next:
219 gui_event::window_set_keyboard_target(
id, keyboard_focus_group::toolbar, keyboard_focus_direction::forward));
224 case gui_event_type::gui_toolbar_prev:
227 gui_event::window_set_keyboard_target(
id, keyboard_focus_group::toolbar, keyboard_focus_direction::backward));
242 hi_axiom(loop::main().on_thread());
244 auto handled =
false;
246 for (
auto& child : this->
children(
false)) {
247 handled |= child.handle_event_recursive(event, reject_list);
250 if (!std::ranges::any_of(reject_list, [&](
auto const& x) {
260 widget_id current_keyboard_widget,
261 keyboard_focus_group group,
262 keyboard_focus_direction direction)
const noexcept override
264 hi_axiom(loop::main().on_thread());
272 }
else if (current_keyboard_widget ==
id) {
277 for (
auto& child :
children(
false)) {
281 if (direction == keyboard_focus_direction::backward) {
285 for (
auto *child : children_) {
286 hi_axiom_not_null(child);
290 if (
auto tmp = child->find_next_widget({}, group, direction); tmp != 0) {
295 auto tmp = child->find_next_widget(current_keyboard_widget, group, direction);
296 if (tmp == current_keyboard_widget) {
301 }
else if (tmp != 0) {
313 return current_keyboard_widget;
322 hi_axiom(loop::main().on_thread());
338 [[nodiscard]] gui_window *
window() const noexcept
override
347 [[nodiscard]] hi::theme
const& theme() const noexcept
350 hi_assert_not_null(w);
354 [[nodiscard]] gfx_surface
const *surface() const noexcept
357 return w->surface.get();
363 [[nodiscard]]
virtual color background_color() const noexcept
366 if (phase() == widget_phase::hover) {
367 return theme().color(semantic_color::fill, _layout.layer + 1);
369 return theme().color(semantic_color::fill, _layout.layer);
372 return theme().color(semantic_color::fill, _layout.layer - 1);
376 [[nodiscard]]
virtual color foreground_color() const noexcept
379 if (phase() == widget_phase::hover) {
380 return theme().color(semantic_color::border, _layout.layer + 1);
382 return theme().color(semantic_color::border, _layout.layer);
385 return theme().color(semantic_color::border, _layout.layer - 1);
389 [[nodiscard]]
virtual color focus_color() const noexcept
393 return theme().color(semantic_color::accent);
394 }
else if (phase() == widget_phase::hover) {
395 return theme().color(semantic_color::border, _layout.layer + 1);
397 return theme().color(semantic_color::border, _layout.layer);
400 return theme().color(semantic_color::border, _layout.layer - 1);
404 [[nodiscard]]
virtual color accent_color() const noexcept
407 return theme().color(semantic_color::accent);
409 return theme().color(semantic_color::border, _layout.layer - 1);
413 [[nodiscard]]
virtual color label_color() const noexcept
416 return theme().text_style(semantic_text_style::label)->color;
418 return theme().color(semantic_color::border, _layout.layer - 1);
432 [[nodiscard]] aarectangle make_overlay_rectangle(aarectangle requested_rectangle)
const noexcept
434 hi_axiom(loop::main().on_thread());
438 auto const window_bounds = aarectangle{
layout().
window_size} - theme().margin<
float>();
439 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:72
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
The HikoGUI API version 1.
Definition recursive_iterator.hpp:16
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:30
widget_layout const & layout() const noexcept
Get the current layout for this widget.
Definition widget_intf.hpp:206
widget_intf * parent
Pointer to the parent widget.
Definition widget_intf.hpp:35
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.
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:103
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:95
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:238
gui_window * window() const noexcept override
Get the window that the widget is owned by.
Definition widget.hpp:338
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:259
void scroll_to_show(hi::aarectangle rectangle) noexcept override
Scroll to show the given rectangle on the window.
Definition widget.hpp:320
void set_layout(widget_layout const &context) noexcept override
Update the internal layout of the widget.
Definition widget.hpp:115
generator< widget_intf & > children(bool include_invisible) noexcept override
Get a list of child widgets.
Definition widget.hpp:60
void draw(draw_context const &context) noexcept override
Draw the widget.
Definition widget.hpp:120
void request_redraw() const noexcept override
Request the widget to be redrawn on the next frame.
Definition widget.hpp:135
virtual hitbox hitbox_test_from_parent(point2 position) const noexcept
Call hitbox_test from a parent widget.
Definition widget.hpp:83
hitbox hitbox_test(point2 position) const noexcept override
Find the widget that is under the mouse cursor.
Definition widget.hpp:72
box_constraints update_constraints() noexcept override
Update the constraints of the widget.
Definition widget.hpp:109
void set_window(gui_window *window) noexcept override
Set the window for this tree of widgets.
Definition widget.hpp:329
widget(widget_intf const *parent) noexcept
Definition widget.hpp:49
bool process_event(gui_event const &event) const noexcept override
Send a event to the window.
Definition widget.hpp:124
bool handle_event(gui_event const &event) noexcept override
Handle command.
Definition widget.hpp:144
observer< extent2 > maximum
The maximum size this widget is allowed to be.
Definition widget.hpp:45