21 value_type
const true_value;
25 using callback_type =
typename notifier_type::callback_type;
26 using callback_ptr_type =
typename notifier_type::callback_ptr_type;
28 template<
typename Value = observable<value_type>>
32 value_type true_value,
43 new_context.fill_color = theme::global->fillColor(this->_semantic_layer + 2);
52 return is_normal(group) && *
enabled;
57 ttlet lock = std::scoped_lock(gui_system_mutex);
61 case command::gui_activate: this->_notifier();
return true;
62 case command::gui_enter:
65 this->
shared_from_this(), keyboard_focus_group::normal, keyboard_focus_direction::forward);
76 ttlet lock = std::scoped_lock(gui_system_mutex);
79 if (event.cause.leftButton) {
82 if (compare_then_assign(_pressed,
static_cast<bool>(event.down.leftButton))) {
86 if (event.type == mouse_event::Type::ButtonUp && _window_rectangle.contains(event.position)) {
96 ttlet lock = std::scoped_lock(gui_system_mutex);
98 if (_window_clipping_rectangle.contains(window_position)) {
99 return hit_box{weak_from_this(), _draw_layer, *
enabled ? hit_box::Type::Button : hit_box::Type::Default};
108 template<
typename Callback>
109 [[nodiscard]] callback_ptr_type
subscribe(Callback &&callback)
noexcept
111 return _notifier.subscribe(std::forward<Callback>(callback));
119 return _notifier.unsubscribe(callback_ptr);
125 bool _pressed =
false;
128 notifier_type _notifier;
Draw context for drawing using the TTauri shaders.
Definition draw_context.hpp:33
Definition gui_window.hpp:39
void update_keyboard_target(std::shared_ptr< tt::widget > widget, keyboard_focus_group group=keyboard_focus_group::normal) noexcept
Change the keyboard focus to the given widget.
void request_redraw(aarect rectangle=aarect::infinity()) noexcept
Request a rectangle on the window to be redrawn.
Definition gui_window.hpp:115
Definition hit_box.hpp:15
Definition mouse_event.hpp:13
Definition observable.hpp:20
int recurse_lock_count() const noexcept
This function should be used in tt_axiom() to check if the lock is held by current thread.
Definition unfair_recursive_mutex.hpp:60
An abstract button widget.
Definition abstract_button_widget.hpp:16
callback_ptr_type subscribe(Callback &&callback) noexcept
Subscribe a callback to call when the button is activated.
Definition abstract_button_widget.hpp:109
bool accepts_keyboard_focus(keyboard_focus_group group) const noexcept
Check if the widget will accept keyboard focus.
Definition abstract_button_widget.hpp:49
bool handle_event(command command) noexcept
Handle command.
Definition abstract_button_widget.hpp:55
void unsubscribe(callback_ptr_type &callback_ptr) noexcept
Unsubscribe a callback.
Definition abstract_button_widget.hpp:117
draw_context make_draw_context(draw_context context) const noexcept override
Make a draw context for this widget.
Definition abstract_button_widget.hpp:38
hit_box hitbox_test(f32x4 window_position) const noexcept final
Find the widget that is under the mouse cursor.
Definition abstract_button_widget.hpp:94
bool handle_event(mouse_event const &event) noexcept final
Definition abstract_button_widget.hpp:74
virtual draw_context make_draw_context(draw_context context) const noexcept
Make a draw context for this widget.
observable< bool > enabled
The widget is enabled.
Definition widget.hpp:105
widget(gui_window &window, std::shared_ptr< abstract_container_widget > parent) noexcept
virtual bool handle_event(command command) noexcept
Handle command.
gui_window & window
Convenient reference to the Window.
Definition widget.hpp:100
abstract_container_widget const & parent() const noexcept
Get a reference to the parent.
virtual aarect window_clipping_rectangle() const noexcept
Get the clipping-rectangle in window coordinates.
Definition widget.hpp:320
T shared_from_this(T... args)