7#include "../GUI/theme.hpp"
8#include "../GFX/draw_context.hpp"
9#include "../GUI/hitbox.hpp"
10#include "../GUI/keyboard_focus_direction.hpp"
11#include "../GUI/keyboard_focus_group.hpp"
12#include "../geometry/extent.hpp"
13#include "../geometry/axis_aligned_rectangle.hpp"
14#include "../geometry/transform.hpp"
15#include "../observable.hpp"
16#include "../command.hpp"
17#include "../chrono.hpp"
119 [[nodiscard]]
bool is_gui_thread() const noexcept;
140 [[nodiscard]] virtual
float margin() const noexcept;
178 geo::transformer auto const &local_to_parent,
182 void set_layout_parameters_from_parent(
185 float draw_layer_delta) noexcept;
187 void set_layout_parameters_from_parent(
aarectangle child_rectangle) noexcept;
189 [[nodiscard]]
matrix3 parent_to_local() const noexcept;
191 [[nodiscard]]
matrix3 local_to_parent() const noexcept;
193 [[nodiscard]]
matrix3 window_to_local() const noexcept;
195 [[nodiscard]]
matrix3 local_to_window() const noexcept;
197 [[nodiscard]]
extent2 size() const noexcept;
199 [[nodiscard]]
float width() const noexcept;
201 [[nodiscard]]
float height() const noexcept;
214 [[nodiscard]]
aarectangle clipping_rectangle() const noexcept;
231 tt_axiom(is_gui_thread());
254 [[nodiscard]]
virtual bool constrain(utc_nanoseconds display_time_point,
bool need_reconstrain)
noexcept;
273 [[nodiscard]]
virtual void layout(utc_nanoseconds display_time_point,
bool need_layout)
noexcept;
275 virtual [[nodiscard]]
color background_color() const noexcept;
277 virtual [[nodiscard]]
color foreground_color() const noexcept;
279 virtual [[nodiscard]]
color focus_color() const noexcept;
281 virtual [[nodiscard]]
color accent_color() const noexcept;
283 virtual [[nodiscard]]
color label_color() const noexcept;
302 virtual
void request_redraw() const noexcept;
310 [[nodiscard]] virtual
bool handle_event(
std::vector<command> const &commands) noexcept;
358 widget const *current_keyboard_widget,
359 keyboard_focus_group group,
360 keyboard_focus_direction direction) const noexcept;
362 [[nodiscard]]
widget const *find_first_widget(keyboard_focus_group group) const noexcept;
364 [[nodiscard]]
widget const *find_last_widget(keyboard_focus_group group) const noexcept;
368 [[nodiscard]]
bool is_first(keyboard_focus_group group) const noexcept;
372 [[nodiscard]]
bool is_last(keyboard_focus_group group) const noexcept;
440 std::atomic<
bool> _request_constrain = true;
444 std::atomic<
bool> _request_layout = true;
450 std::shared_ptr<
std::function<
void()>> _redraw_callback;
451 std::shared_ptr<
std::function<
void()>> _relayout_callback;
452 std::shared_ptr<
std::function<
void()>> _reconstrain_callback;
456 template<typename T, typename... Args>
457 T &make_widget(Args &&...args)
459 tt_axiom(is_gui_thread());
460 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:28
Definition gui_window.hpp:39
Definition keyboard_event.hpp:40
Definition mouse_event.hpp:15
A value which can be observed for modifications.
Definition observable.hpp:464
font_book keeps track of multiple fonts.
Definition font_book.hpp:30
An interactive graphical object as part of the user-interface.
Definition widget.hpp:37
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:46
virtual bool constrain(utc_nanoseconds display_time_point, bool need_reconstrain) noexcept
Update the constraints of the widget.
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:50
int semantic_layer
The draw layer of the widget.
Definition widget.hpp:90
observable< bool > visible
The widget is visible.
Definition widget.hpp:60
observable< bool > enabled
The widget is enabled.
Definition widget.hpp:55
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:41
virtual float base_line() const noexcept
Return the base-line where the text should be located.
virtual void layout(utc_nanoseconds display_time_point, bool need_layout) noexcept
Update the internal layout of the widget.
void clear() noexcept
Remove and deallocate all child widgets.
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:99
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:229
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:74
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 draw(draw_context context, utc_nanoseconds display_time_point) noexcept
Draw the widget.