7#include "abstract_button_widget.hpp"
8#include "../stencils/label_stencil.hpp"
26 template<
typename Value = observable<value_type>>
30 value_type true_value,
31 Value &&value = {})
noexcept :
36 void init() noexcept
override
38 _label_callback =
label.subscribe([
this](
auto...) {
39 this->_request_reconstrain =
true;
42 _callback = this->
subscribe([
this](
auto...) {
52 _label_stencil = stencil::make_unique(alignment::middle_center, *
label, theme::global->labelStyle);
53 this->_preferred_size = interval_extent2::make_minimum(_label_stencil->preferred_extent() +
extent2{theme::global->margin2Dx2});
64 need_layout |= std::exchange(this->_request_relayout,
false);
71 [[nodiscard]]
color background_color() const noexcept
override
74 return this->accent_color();
76 return super::background_color();
84 if (overlaps(context, this->_clipping_rectangle)) {
86 context.draw_box_with_border_inside(
87 this->
rectangle(), this->background_color(), this->focus_color(),
corner_shapes{theme::global->roundingRadius});
89 _label_stencil->draw(context, this->label_color(), translate_z(0.1f));
95 void clicked() noexcept
97 ttlet lock = std::scoped_lock(gui_system_mutex);
98 if (compare_then_assign(this->value, !this->value)) {
99 this->request_redraw();
104 typename decltype(label)::callback_ptr_type _label_callback;
105 super::callback_ptr_type _callback;
This is a RGBA floating point color.
Definition color.hpp:39
Definition corner_shapes.hpp:9
Draw context for drawing using the TTauri shaders.
Definition draw_context.hpp:33
Definition gui_window.hpp:37
A localized text + icon label.
Definition label.hpp:76
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
Definition button_widget.hpp:19
void init() noexcept override
Should be called right after allocating and constructing a widget.
Definition button_widget.hpp:36
void draw(draw_context context, hires_utc_clock::time_point display_time_point) noexcept override
Draw the widget.
Definition button_widget.hpp:80
bool update_constraints(hires_utc_clock::time_point display_time_point, bool need_reconstrain) noexcept override
Update the constraints of the widget.
Definition button_widget.hpp:47
void update_layout(hires_utc_clock::time_point displayTimePoint, bool need_layout) noexcept override
Update the internal layout of the widget.
Definition button_widget.hpp:60
virtual void update_layout(hires_utc_clock::time_point display_time_point, bool need_layout) noexcept
Update the internal layout of the widget.
aarectangle rectangle() const noexcept
Get the rectangle in local coordinates.
Definition widget.hpp:342
gui_window & window
Convenient reference to the Window.
Definition widget.hpp:101
virtual float base_line() const noexcept
Return the base-line where the text should be located.
Definition widget.hpp:351
virtual void draw(draw_context context, hires_utc_clock::time_point display_time_point) noexcept
Draw the widget.
Definition widget.hpp:462
virtual bool update_constraints(hires_utc_clock::time_point display_time_point, bool need_reconstrain) noexcept
Update the constraints of the widget.
abstract_container_widget const & parent() const noexcept
Get a reference to the parent.