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,
38 color background_color()
const noexcept override
41 return theme::global->fillColor(this->_semantic_layer + 2);
43 return super::background_color();
50 return is_normal(group) && *
enabled;
55 ttlet lock = std::scoped_lock(gui_system_mutex);
59 case command::gui_activate: this->_notifier();
return true;
60 case command::gui_enter:
63 this->
shared_from_this(), keyboard_focus_group::normal, keyboard_focus_direction::forward);
74 ttlet lock = std::scoped_lock(gui_system_mutex);
77 if (event.cause.leftButton) {
80 if (compare_then_assign(_pressed,
static_cast<bool>(event.down.leftButton))) {
84 if (event.type == mouse_event::Type::ButtonUp &&
rectangle().contains(event.position)) {
96 if (_visible_rectangle.contains(position)) {
97 return hit_box{weak_from_this(), _draw_layer, *
enabled ? hit_box::Type::Button : hit_box::Type::Default};
106 template<
typename Callback>
107 [[nodiscard]] callback_ptr_type
subscribe(Callback &&callback)
noexcept
109 return _notifier.subscribe(std::forward<Callback>(callback));
117 return _notifier.unsubscribe(callback_ptr);
123 bool _pressed =
false;
126 notifier_type _notifier;
This is a RGBA floating point color.
Definition color.hpp:39
Class which represents an rectangle.
Definition rectangle.hpp:16
Definition gui_window.hpp:37
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.
Definition hit_box.hpp:15
Definition mouse_event.hpp:15
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:107
hit_box hitbox_test(point2 position) const noexcept final
Find the widget that is under the mouse cursor.
Definition abstract_button_widget.hpp:92
bool accepts_keyboard_focus(keyboard_focus_group group) const noexcept
Check if the widget will accept keyboard focus.
Definition abstract_button_widget.hpp:47
bool handle_event(command command) noexcept
Handle command.
Definition abstract_button_widget.hpp:53
void unsubscribe(callback_ptr_type &callback_ptr) noexcept
Unsubscribe a callback.
Definition abstract_button_widget.hpp:115
bool handle_event(mouse_event const &event) noexcept final
Definition abstract_button_widget.hpp:72
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:101
abstract_container_widget const & parent() const noexcept
Get a reference to the parent.
T shared_from_this(T... args)