12#include "../macros.hpp"
14namespace hi {
inline namespace v1 {
87 template<different_from<std::shared_ptr<delegate_type>> Value, button_w
idget_attribute... Attributes>
156 _label_constraints = super::update_constraints();
159 _button_size = {theme().size() * 2.0f, theme().size()};
160 hilet
extra_size = extent2{theme().margin<
float>() + _button_size.
width(), 0.0f};
163 r.margins = theme().margin();
168 void set_layout(widget_layout
const&
context)
noexcept override
176 hi_not_implemented();
179 hilet
label_width =
context.width() - (_button_rectangle.width() + theme().margin<
float>());
181 hilet
label_left = _button_rectangle.right() + theme().margin<
float>();
183 _on_label_shape = _off_label_shape = _other_label_shape =
184 box_shape{_label_constraints,
label_rectangle, theme().baseline_adjustment()};
188 _on_label_shape = _off_label_shape = _other_label_shape =
189 box_shape{_label_constraints,
label_rectangle, theme().baseline_adjustment()};
192 hi_not_implemented();
196 aarectangle{
get<0>(_button_rectangle), extent2{_button_rectangle.height(), _button_rectangle.height()}};
198 _pip_circle =
align(
button_square, circle{theme().size() * 0.5f - 3.0f}, alignment::middle_center());
206 void draw(draw_context
const&
context)
noexcept override
219 box_constraints _label_constraints;
221 extent2 _button_size;
222 aarectangle _button_rectangle;
223 animator<float> _animated_value = _animation_duration;
225 float _pip_move_range;
227 void draw_toggle_button(draw_context
const&
context)
noexcept
234 theme().border_width(),
236 corner_radii{_button_rectangle.height() * 0.5f});
239 void draw_toggle_pip(draw_context
const&
context)
noexcept
242 if (_animated_value.is_animating()) {
246 hilet
positioned_pip_circle = translate3{_pip_move_range * _animated_value.current_value(), 0.0f, 0.1f} * _pip_circle;
Defines abstract_button_widget.
@ right
Align the text to the right side.
@ left
Align the text to the left side.
std::shared_ptr< button_delegate > make_default_toggle_button_delegate(auto &&value, auto &&...args) noexcept
Make a shared pointer to a toggle-button delegate.
Definition button_delegate.hpp:245
@ on
The 'on' state of a button.
@ invisible
The widget is invisible.
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
@ inside
The border is drawn inside the edge of a quad.
bool compare_store(T &lhs, U &&rhs) noexcept
Compare then store if there was a change.
Definition misc.hpp:56
constexpr horizontal_alignment mirror(horizontal_alignment const &rhs) noexcept
Mirror the horizontal alignment.
Definition alignment.hpp:203
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Horizontal/Vertical alignment combination.
Definition alignment.hpp:242
constexpr float & width() noexcept
Access the x-as-width element from the extent.
Definition extent2.hpp:104
widget_intf * parent
Pointer to the parent widget.
Definition widget_intf.hpp:28
2D constraints.
Definition box_constraints.hpp:25
Base class for implementing button widgets.
Definition abstract_button_widget.hpp:33
std::shared_ptr< delegate_type > delegate
The delegate that controls the button widget.
Definition abstract_button_widget.hpp:40
button_state state() const noexcept
Get the current state of the button.
Definition abstract_button_widget.hpp:88
observer< alignment > alignment
The alignment of the button and on/off/other label.
Definition abstract_button_widget.hpp:56
A button delegate controls the state of a button widget.
Definition button_delegate.hpp:45
A GUI widget that permits the user to make a binary choice.
Definition toggle_widget.hpp:53
toggle_widget(widget *parent, Value &&value, OnValue &&on_value, Attributes &&...attributes) noexcept
Construct a toggle widget with a default button delegate.
Definition toggle_widget.hpp:108
toggle_widget(widget *parent, std::shared_ptr< delegate_type > delegate, button_widget_attribute auto &&...attributes) noexcept
Construct a toggle widget.
Definition toggle_widget.hpp:67
toggle_widget(widget *parent, Value &&value, Attributes &&...attributes) noexcept
Construct a toggle widget with a default button delegate.
Definition toggle_widget.hpp:88
toggle_widget(widget *parent, Value &&value, OnValue &&on_value, OffValue &&off_value, Attributes &&...attributes) noexcept
Construct a toggle widget with a default button delegate.
Definition toggle_widget.hpp:137
An interactive graphical object as part of the user-interface.
Definition widget.hpp:37
widget_layout const & layout() const noexcept override
Get the current layout for this widget.
Definition widget.hpp:169
void request_redraw() const noexcept override
Request the widget to be redrawn on the next frame.
Definition widget.hpp:189
observer< widget_mode > mode
The widget mode.
Definition widget.hpp:42
Definition abstract_button_widget.hpp:27