7#include "abstract_bool_toggle_button_widget.hpp"
9#include "../stencils/label_stencil.hpp"
10#include "../GUI/draw_context.hpp"
11#include "../observable.hpp"
27 template<
typename Value = observable<
bool>>
34 _on_label_callback = this->on_label.subscribe([
this](
auto...) {
35 _request_reconstrain =
true;
37 _off_label_callback = this->off_label.subscribe([
this](
auto...) {
38 _request_reconstrain =
true;
49 _on_label_stencil = stencil::make_unique(alignment::top_left, *on_label, theme::global->labelStyle);
50 _off_label_stencil = stencil::make_unique(alignment::top_left, *off_label, theme::global->labelStyle);
53 {_on_label_stencil->preferred_extent().height(),
54 _off_label_stencil->preferred_extent().height(),
55 theme::global->smallSize});
58 std::max({_on_label_stencil->preferred_extent().width(), _off_label_stencil->preferred_extent().width()}) +
59 theme::global->smallSize * 2.0f + theme::global->
margin;
61 _preferred_size = interval_extent2::make_minimum(minimumWidth, minimumHeight);
73 need_layout |= std::exchange(_request_relayout,
false);
78 theme::global->smallSize * 2.0f + 1.0f,
79 theme::global->smallSize};
81 ttlet labelX = theme::global->smallSize * 2.0f + theme::global->margin;
83 _on_label_stencil->set_layout_parameters(_label_rectangle,
base_line());
84 _off_label_stencil->set_layout_parameters(_label_rectangle,
base_line());
87 shrink(
aarectangle{0.0f, _rail_rectangle.bottom(), _rail_rectangle.height(), _rail_rectangle.height()}, 2.5f);
89 ttlet sliderMoveWidth = theme::global->smallSize * 2.0f - (_slider_rectangle.left() * 2.0f);
90 _slider_move_range = sliderMoveWidth - _slider_rectangle.width();
100 if (overlaps(context, _clipping_rectangle)) {
102 draw_slider(context);
115 float _slider_move_range;
122 decltype(value)::callback_ptr_type _value_callback;
123 decltype(on_label)::callback_ptr_type _on_label_callback;
124 decltype(off_label)::callback_ptr_type _off_label_callback;
131 _rail_rectangle, background_color(), focus_color(),
corner_shapes{_rail_rectangle.height() * 0.5f});
134 void draw_slider(draw_context draw_context)
noexcept
140 if (animationProgress < 1.0f) {
144 ttlet animatedValue = to_float(value, _animation_duration);
145 ttlet positionedSliderRectangle = translate3{_slider_move_range * animatedValue, 0.0f, 0.1f} * _slider_rectangle;
147 draw_context.draw_box(
148 positionedSliderRectangle, accent_color(), corner_shapes{positionedSliderRectangle.height() * 0.5f});
151 void draw_label(draw_context draw_context)
noexcept
155 ttlet &label_stencil = *value ? _on_label_stencil : _off_label_stencil;
156 label_stencil->draw(draw_context, 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
void draw_box_with_border_inside(rectangle rectangle, color fill_color, color line_color, float line_width=1.0, tt::corner_shapes corner_shapes=tt::corner_shapes{}) const noexcept
Draw an axis aligned box This function will shrink to include the size of the border inside the given...
Definition draw_context.hpp:183
Definition gui_window.hpp:37
Definition observable.hpp:20
float animation_progress(duration animation_duration) const noexcept
The relative time since the start of the animation.
Definition observable.hpp:108
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 boolean toggle button widget.
Definition abstract_bool_toggle_button_widget.hpp:14
Definition toggle_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 toggle_widget.hpp:44
void update_layout(hires_utc_clock::time_point display_time_point, bool need_layout) noexcept override
Update the internal layout of the widget.
Definition toggle_widget.hpp:69
void draw(draw_context context, hires_utc_clock::time_point display_time_point) noexcept override
Draw the widget.
Definition toggle_widget.hpp:96
float margin() const noexcept
Get the margin around the Widget.
Definition widget.hpp:128
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.