8#include "button_delegate.hpp"
9#include "label_widget.hpp"
11#include "../animator.hpp"
13#include "../notifier.hpp"
14#include "../weak_or_unique_ptr.hpp"
47 template<
typename Label>
50 tt_axiom(is_gui_thread());
61 tt_axiom(is_gui_thread());
62 if (
auto delegate = _delegate.lock()) {
63 return delegate->state(*
this);
65 return button_state::off;
71 template<
typename Callback>
72 [[nodiscard]] callback_ptr_type
subscribe(Callback &&callback)
noexcept
74 tt_axiom(is_gui_thread());
75 return _notifier.subscribe(std::forward<Callback>(callback));
83 void init() noexcept override;
84 void deinit() noexcept override;
85 [[nodiscard]]
bool constrain(
hires_utc_clock::time_point display_time_point,
bool need_reconstrain) noexcept override;
86 [[nodiscard]]
void layout(
hires_utc_clock::time_point displayTimePoint,
bool need_layout) noexcept override;
87 [[nodiscard]]
color background_color() const noexcept override;
88 [[nodiscard]]
hitbox hitbox_test(
point2 position) const noexcept final;
89 [[nodiscard]]
bool accepts_keyboard_focus(keyboard_focus_group group) const noexcept override;
90 void activate() noexcept;
91 [[nodiscard]]
bool handle_event(command command) noexcept override;
92 [[nodiscard]]
bool handle_event(
mouse_event const &event) noexcept final;
100 bool _pressed = false;
button_state
The state of a button.
Definition button_state.hpp:13
This is a RGBA floating point color.
Definition color.hpp:36
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:20
Definition gui_window.hpp:36
Definition mouse_event.hpp:15
Timestamp.
Definition hires_utc_clock.hpp:19
A localizable message.
Definition l10n.hpp:149
Definition notifier.hpp:18
An observable value.
Definition observable.hpp:280
Class that hold either a weak_ptr or a unique_ptr This class is to hold a weak_ptr,...
Definition weak_or_unique_ptr.hpp:25
Definition abstract_button_widget.hpp:23
void unsubscribe(callback_ptr_type &callback_ptr) noexcept
Unsubscribe a callback.
button_state state() const noexcept
Get the current state of the button.
Definition abstract_button_widget.hpp:59
callback_ptr_type subscribe(Callback &&callback) noexcept
Subscribe a callback to call when the button is activated.
Definition abstract_button_widget.hpp:72
observable< label > off_label
The label to show when the button is in the 'off' state.
Definition abstract_button_widget.hpp:35
observable< label > other_label
The label to show when the button is in the 'other' state.
Definition abstract_button_widget.hpp:39
void set_label(Label const &rhs) noexcept
Set on/off/other labels of the button to the same value.
Definition abstract_button_widget.hpp:48
observable< label > on_label
The label to show when the button is in the 'on' state.
Definition abstract_button_widget.hpp:31
observable< alignment > label_alignment
The alignment of the on/off/other label.
Definition abstract_button_widget.hpp:43
Definition button_delegate.hpp:14
The GUI widget displays and lays out text together with an icon.
Definition label_widget.hpp:32
An interactive graphical object as part of the user-interface.
Definition widget.hpp:39
widget *const parent
Pointer to the parent widget.
Definition widget.hpp:48
gui_window & window
Convenient reference to the Window.
Definition widget.hpp:43
widget(gui_window &window, widget *parent) noexcept