7#include "abstract_radio_button_widget.hpp"
8#include "../GUI/draw_context.hpp"
9#include "../observable.hpp"
10#include "../label.hpp"
23 using value_type =
typename super::value_type;
27 template<
typename Value,
typename Label>
31 value_type true_value,
33 Label &&
label) noexcept :
39 template<
typename Value>
43 value_type true_value,
44 Value &&value) noexcept :
56 void init() noexcept
override
58 label_callback =
label.subscribe([
this](
auto...) {
59 this->_request_reconstrain =
true;
68 _label_stencil = stencil::make_unique(alignment::top_left, *
label, theme::global->labelStyle);
70 ttlet minimum_height =
std::max(_label_stencil->preferred_extent().height(), theme::global->smallSize);
71 ttlet minimum_width = theme::global->smallSize + theme::global->margin + _label_stencil->preferred_extent().width();
73 super::_preferred_size = interval_extent2::make_minimum(minimum_width, minimum_height);
84 need_layout |= std::exchange(this->_request_relayout,
false);
87 0.0f,
std::round(this->
base_line() - theme::global->smallSize * 0.5f), theme::global->smallSize, theme::global->smallSize};
89 ttlet labelX = _outline_rectangle.right() + theme::global->margin;
91 _label_stencil->set_layout_parameters(_label_rectangle, this->
base_line());
93 _pip_rectangle = shrink(_outline_rectangle, 2.5f);
102 if (overlaps(context, this->_clipping_rectangle)) {
103 draw_outline(context);
116 typename decltype(
label)::callback_ptr_type label_callback;
122 context.draw_box_with_border_inside(
123 _outline_rectangle, this->background_color(), this->focus_color(),
corner_shapes{_outline_rectangle.height() * 0.5f});
126 void draw_pip(draw_context context)
noexcept
131 if (this->value == this->true_value) {
133 _pip_rectangle, this->accent_color(), corner_shapes{_pip_rectangle.height() * 0.5f});
137 void draw_label(draw_context context)
noexcept
140 _label_stencil->draw(context, this->label_color());
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:18
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 radio button widget.
Definition abstract_radio_button_widget.hpp:15
Definition radio_button_widget.hpp:20
bool update_constraints(hires_utc_clock::time_point display_time_point, bool need_reconstrain) noexcept override
Update the constraints of the widget.
Definition radio_button_widget.hpp:63
void draw(draw_context context, hires_utc_clock::time_point display_time_point) noexcept override
Draw the widget.
Definition radio_button_widget.hpp:98
void update_layout(hires_utc_clock::time_point display_time_point, bool need_layout) noexcept override
Update the internal layout of the widget.
Definition radio_button_widget.hpp:80
void init() noexcept override
Should be called right after allocating and constructing a widget.
Definition radio_button_widget.hpp:56
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.