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 {
105 hi_axiom(loop::main().on_thread());
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());
250 if (!std::ranges::any_of(
reject_list, [&](
auto const& x) {
261 keyboard_focus_group group,
262 keyboard_focus_direction direction)
const noexcept override
264 hi_axiom(loop::main().on_thread());
277 for (
auto& child :
children(
false)) {
281 if (direction == keyboard_focus_direction::backward) {
286 hi_axiom_not_null(child);
290 if (
auto tmp = child->find_next_widget({}, group, direction);
tmp != 0) {
301 }
else if (
tmp != 0) {
322 hi_axiom(loop::main().on_thread());
350 hi_assert_not_null(w);
357 return w->surface.get();
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);
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);
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);
407 return theme().color(semantic_color::accent);
409 return theme().color(semantic_color::border, _layout.layer - 1);
416 return theme().text_style(semantic_text_style::label)->color;
418 return theme().color(semantic_color::border, _layout.layer - 1);
434 hi_axiom(loop::main().on_thread());
@ 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.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378
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: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