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 = super::value_type;
27 template<
typename Value,
typename Label = observable<tt::label>>
31 value_type true_value,
33 Label &&
label = {})
noexcept :
37 this->_width_resistance = 2;
47 void init() noexcept
override
49 _label_callback =
label.subscribe([
this](
auto...) {
50 this->_request_reconstrain =
true;
65 return is_toolbar(group) && *this->
enabled;
73 _label_stencil = stencil::make_unique(alignment::top_center, *
label, theme::global->labelStyle);
75 ttlet minimum_height = _label_stencil->preferred_extent().height();
76 ttlet minimum_width = _label_stencil->preferred_extent().width() + 2.0f * theme::global->margin;
78 this->_preferred_size = {
79 f32x4{minimum_width, minimum_height},
81 this->_preferred_base_line =
relative_base_line{vertical_alignment::middle, -theme::global->margin};
92 need_layout |= std::exchange(this->_request_relayout,
false);
97 ttlet offset = theme::global->margin + theme::global->borderWidth;
98 _button_rectangle =
aarect{
115 draw_button(context);
117 draw_focus_line(context);
126 case command::gui_toolbar_next:
127 if (!this->
is_last(keyboard_focus_group::toolbar)) {
129 this->
shared_from_this(), keyboard_focus_group::toolbar, keyboard_focus_direction::forward);
133 case command::gui_toolbar_prev:
134 if (!this->
is_first(keyboard_focus_group::toolbar)) {
136 this->
shared_from_this(), keyboard_focus_group::toolbar, keyboard_focus_direction::backward);
147 typename decltype(
label)::callback_ptr_type _label_callback;
151 void draw_focus_line(
draw_context const &context)
noexcept
153 if (this->_focus && this->window.
active && *this->value == this->true_value) {
154 ttlet &parent_ = this->
parent();
158 auto parent_context = parent_.make_draw_context(context);
162 parent_context.transform =
translate3{0.0f, 0.0f, 1.7f} * parent_context.transform;
164 parent_context.fill_color = theme::global->accentColor;
165 parent_context.draw_filled_quad(
166 aarect{parent_.rectangle().x(), parent_.rectangle().y(), parent_.rectangle().width(), 1.0f});
170 void draw_button(draw_context context)
noexcept
173 if (this->_focus && this->window.
active) {
175 context.transform = translate3{0.0f, 0.0f, 0.8f} * context.transform;
177 context.transform = translate3{0.0f, 0.0f, 0.6f} * context.transform;
184 if (this->_hover || *this->value == this->true_value) {
185 context.fill_color = theme::global->fillColor(this->_semantic_layer - 1);
186 context.line_color = context.fill_color;
188 context.fill_color = theme::global->fillColor(this->_semantic_layer);
189 context.line_color = context.fill_color;
192 if (this->_focus && this->window.
active) {
193 context.line_color = theme::global->accentColor;
196 context.corner_shapes = f32x4{0.0f, 0.0f, theme::global->roundingRadius, theme::global->roundingRadius};
197 context.draw_box_with_border_inside(_button_rectangle);
200 void draw_label(draw_context context)
noexcept
204 context.transform = translate3{0.0f, 0.0f, 0.9f} * context.transform;
207 context.line_color = theme::global->labelStyle.color;
210 _label_stencil->draw(context,
true);
Definition alignment.hpp:104
Definition translate.hpp:14
Draw context for drawing using the TTauri shaders.
Definition draw_context.hpp:33
Definition gui_window.hpp:39
std::atomic< bool > active
Definition gui_window.hpp:71
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
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
bool handle_event(command command) noexcept
Handle command.
Definition abstract_button_widget.hpp:55
An abstract radio button widget.
Definition abstract_radio_button_widget.hpp:15
Definition toolbar_tab_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 toolbar_tab_button_widget.hpp:68
void init() noexcept override
Should be called right after allocating and constructing a widget.
Definition toolbar_tab_button_widget.hpp:47
bool accepts_keyboard_focus(keyboard_focus_group group) const noexcept override
Check if the widget will accept keyboard focus.
Definition toolbar_tab_button_widget.hpp:62
bool handle_event(tt::command command) noexcept override
Handle command.
Definition toolbar_tab_button_widget.hpp:123
void draw(draw_context context, hires_utc_clock::time_point display_time_point) noexcept override
Draw the widget.
Definition toolbar_tab_button_widget.hpp:110
aarect window_clipping_rectangle() const noexcept override
The tab button widget will draw beyond the normal clipping rectangle.
Definition toolbar_tab_button_widget.hpp:56
void update_layout(hires_utc_clock::time_point display_time_point, bool need_layout) noexcept override
Update the internal layout of the widget.
Definition toolbar_tab_button_widget.hpp:88
bool is_last(keyboard_focus_group group) const noexcept
Is this widget the last widget in the parent container.
virtual void update_layout(hires_utc_clock::time_point display_time_point, bool need_layout) noexcept
Update the internal layout of the widget.
observable< bool > enabled
The widget is enabled.
Definition widget.hpp:105
gui_window & window
Convenient reference to the Window.
Definition widget.hpp:100
virtual void draw(draw_context context, hires_utc_clock::time_point display_time_point) noexcept
Draw the widget.
Definition widget.hpp:460
float base_line() const noexcept
Get the base-line in local coordinates.
Definition widget.hpp:350
bool is_first(keyboard_focus_group group) const noexcept
Is this widget the first widget in the parent container.
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.
virtual aarect window_clipping_rectangle() const noexcept
Get the clipping-rectangle in window coordinates.
Definition widget.hpp:320
aarect window_rectangle() const noexcept
Get the rectangle in window coordinates.
Definition widget.hpp:310
aarect rectangle() const noexcept
Get the rectangle in local coordinates.
Definition widget.hpp:340
T shared_from_this(T... args)