10#include "../GFX/draw_context.hpp"
11#include "../GUI/hitbox.hpp"
12#include "../GUI/keyboard_focus_direction.hpp"
13#include "../GUI/keyboard_focus_group.hpp"
15#include "../geometry/extent.hpp"
16#include "../geometry/axis_aligned_rectangle.hpp"
17#include "../geometry/transform.hpp"
18#include "../hires_utc_clock.hpp"
19#include "../observable.hpp"
20#include "../command.hpp"
128 [[nodiscard]] virtual
float margin() const noexcept;
166 geo::transformer auto const &local_to_parent,
170 void set_layout_parameters_from_parent(
173 float draw_layer_delta) noexcept;
175 void set_layout_parameters_from_parent(
aarectangle child_rectangle) noexcept;
177 [[nodiscard]]
matrix3 parent_to_local() const noexcept;
179 [[nodiscard]]
matrix3 local_to_parent() const noexcept;
181 [[nodiscard]]
matrix3 window_to_local() const noexcept;
183 [[nodiscard]]
matrix3 local_to_window() const noexcept;
185 [[nodiscard]]
extent2 size() const noexcept;
187 [[nodiscard]]
float width() const noexcept;
189 [[nodiscard]]
float height() const noexcept;
202 [[nodiscard]]
aarectangle clipping_rectangle() const noexcept;
219 tt_axiom(is_gui_thread());
263 virtual [[nodiscard]]
color background_color() const noexcept;
265 virtual [[nodiscard]]
color foreground_color() const noexcept;
267 virtual [[nodiscard]]
color focus_color() const noexcept;
269 virtual [[nodiscard]]
color accent_color() const noexcept;
271 virtual [[nodiscard]]
color label_color() const noexcept;
290 virtual
void request_redraw() const noexcept;
298 [[nodiscard]] virtual
bool handle_event(
std::vector<command> const &commands) noexcept;
307 [[nodiscard]] virtual
bool
347 widget const *current_keyboard_widget,
348 keyboard_focus_group group,
349 keyboard_focus_direction direction) const noexcept;
351 [[nodiscard]]
widget const *find_first_widget(keyboard_focus_group group) const noexcept;
353 [[nodiscard]]
widget const *find_last_widget(keyboard_focus_group group) const noexcept;
357 [[nodiscard]]
bool is_first(keyboard_focus_group group) const noexcept;
361 [[nodiscard]]
bool is_last(keyboard_focus_group group) const noexcept;
429 std::atomic<
bool> _request_constrain = true;
433 std::atomic<
bool> _request_layout = true;
439 std::shared_ptr<
std::function<
void()>> _redraw_callback;
440 std::shared_ptr<
std::function<
void()>> _relayout_callback;
441 std::shared_ptr<
std::function<
void()>> _reconstrain_callback;
445 template<typename T, typename... Args>
446 T &make_widget(Args &&...args)
448 tt_axiom(is_gui_thread());
449 auto tmp = std::make_unique<T>(
window,
this, std::forward<Args>(args)...);
This is a RGBA floating point color.
Definition color.hpp:36
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:20
Class which represents an rectangle.
Definition rectangle.hpp:16
Draw context for drawing using the TTauri shaders.
Definition draw_context.hpp:29
Definition gui_window.hpp:36
Definition keyboard_event.hpp:40
Definition mouse_event.hpp:15
Timestamp.
Definition hires_utc_clock.hpp:19
An observable value.
Definition observable.hpp:280
An interactive graphical object as part of the user-interface.
Definition widget.hpp:39
bool is_last(keyboard_focus_group group) const noexcept
Is this widget the last widget in the parent container.
widget *const parent
Pointer to the parent widget.
Definition widget.hpp:48
virtual void init() noexcept
Should be called right after allocating and constructing a widget.
std::string id
A name of widget, should be unique between siblings.
Definition widget.hpp:52
int semantic_layer
The draw layer of the widget.
Definition widget.hpp:92
observable< bool > visible
The widget is visible.
Definition widget.hpp:62
observable< bool > enabled
The widget is enabled.
Definition widget.hpp:57
extent2 maximum_size() const noexcept
Maximum size.
virtual bool handle_event(command command) noexcept
Handle command.
gui_window & window
Convenient reference to the Window.
Definition widget.hpp:43
virtual float base_line() const noexcept
Return the base-line where the text should be located.
virtual void draw(draw_context context, hires_utc_clock::time_point display_time_point) noexcept
Draw the widget.
void clear() noexcept
Remove and deallocate all child widgets.
virtual bool constrain(hires_utc_clock::time_point display_time_point, bool need_reconstrain) noexcept
Update the constraints of the widget.
extent2 minimum_size() const noexcept
Minimum size.
extent2 preferred_size() const noexcept
Preferred size.
bool is_first(keyboard_focus_group group) const noexcept
Is this widget the first widget in the parent container.
virtual widget const * find_next_widget(widget const *current_keyboard_widget, keyboard_focus_group group, keyboard_focus_direction direction) const noexcept
Find the next widget that handles keyboard focus.
int logical_layer
The logical layer of the widget.
Definition widget.hpp:101
virtual hitbox hitbox_test(point2 position) const noexcept
Find the widget that is under the mouse cursor.
widget & add_widget(std::unique_ptr< widget > widget) noexcept
Add a widget directly to this widget.
virtual bool accepts_keyboard_focus(keyboard_focus_group group) const noexcept
Check if the widget will accept keyboard focus.
Definition widget.hpp:217
widget(gui_window &window, widget *parent) noexcept
virtual float margin() const noexcept
Get the margin around the Widget.
virtual void scroll_to_show(tt::rectangle rectangle) noexcept
Scroll to show the given rectangle on the window.
virtual bool handle_command_recursive(command command, std::vector< widget const * > const &reject_list) noexcept
Handle command recursive.
float draw_layer
The draw layer of the widget.
Definition widget.hpp:76
virtual void deinit() noexcept
Should be called right after allocating and constructing a widget.
std::vector< widget const * > parent_chain() const noexcept
Get a list of parents of a given widget.
void set_layout_parameters(geo::transformer auto const &local_to_parent, extent2 size, aarectangle const &clipping_rectangle) noexcept
Set the location and size of the widget inside the window.
virtual void layout(hires_utc_clock::time_point display_time_point, bool need_layout) noexcept
Update the internal layout of the widget.