57 constexpr static auto prefix = super::prefix;
72 this->set_attributes<0>(
hi_forward(attributes)...);
85 template<different_from<std::shared_ptr<delegate_type>> Value, button_w
idget_attribute... Attributes>
104 different_from<std::shared_ptr<delegate_type>> Value,
105 forward_of<observer<observer_decay_t<Value>>> OnValue,
106 button_widget_attribute... Attributes>
130 different_from<std::shared_ptr<delegate_type>> Value,
131 forward_of<observer<observer_decay_t<Value>>> OnValue,
132 forward_of<observer<observer_decay_t<Value>>> OffValue,
133 button_widget_attribute... Attributes>
147 _label_constraints = super::update_constraints();
150 _button_size = theme<prefix>.size(
this);
151 hilet extra_size =
extent2i{theme<prefix>.spacing_horizontal(
this) + _button_size.
width(), 0};
153 auto r = max(_label_constraints + extra_size, _button_size);
154 r.margins = theme<prefix>.margin(
this);
159 void set_layout(widget_layout
const& context)
noexcept override
164 if (alignment_ == horizontal_alignment::left or alignment_ == horizontal_alignment::right) {
165 _button_rectangle =
align(context.rectangle(), _button_size, alignment_);
170 hilet spacing = theme<prefix>.spacing_horizontal(
this);
171 hilet cap_height = theme<prefix>.cap_height(
this);
173 hilet label_width = context.width() - (_button_rectangle.width() + spacing);
174 if (alignment_ == horizontal_alignment::left) {
175 hilet label_left = _button_rectangle.right() + spacing;
176 hilet label_rectangle = aarectanglei{label_left, 0, label_width, context.height()};
177 this->_on_label_shape = this->_off_label_shape = this->_other_label_shape =
178 box_shape{_label_constraints, label_rectangle, cap_height};
180 }
else if (alignment_ == horizontal_alignment::right) {
181 hilet label_rectangle = aarectanglei{0, 0, label_width, context.height()};
182 this->_on_label_shape = this->_off_label_shape = this->_other_label_shape =
183 box_shape{_label_constraints, label_rectangle, cap_height};
189 hilet button_square = aarectangle{
190 narrow_cast<point2>(get<0>(_button_rectangle)),
191 extent2{narrow_cast<float>(_button_rectangle.height()), narrow_cast<float>(_button_rectangle.height())}};
193 hilet pip_size =
theme<prefix /
"pip">.size(
this);
194 hi_axiom(pip_size.width() == pip_size.height());
196 _pip_circle =
align(button_square, circle{pip_size.width() / 2}, alignment::middle_center());
198 hilet pip_to_button_margin_x2 = _button_rectangle.height() - narrow_cast<int>(_pip_circle.diameter());
199 _pip_move_range = _button_rectangle.width() - narrow_cast<int>(_pip_circle.diameter()) - pip_to_button_margin_x2;
201 super::set_layout(context);
204 void draw(widget_draw_context
const& context)
noexcept override
207 draw_toggle_button(context);
208 draw_toggle_pip(context);
209 this->draw_button(context);
216 box_constraints _label_constraints;
219 aarectanglei _button_rectangle;
220 animator<float> _animated_value = _animation_duration;
224 void draw_toggle_button(widget_draw_context
const& context)
noexcept
229 theme<prefix>.background_color(
this),
230 theme<prefix>.border_color(
this),
231 theme<prefix>.border_width(
this),
233 corner_radii{_button_rectangle.height() * 0.5f});
236 void draw_toggle_pip(widget_draw_context
const& context)
noexcept
239 if (_animated_value.is_animating()) {
243 hilet positioned_pip_circle = translate3{_pip_move_range * _animated_value.current_value(), 0.0f, 0.1f} * _pip_circle;
245 context.draw_circle(this->layout, positioned_pip_circle * 1.02f, theme<prefix>.fill_color(
this));