13namespace hi {
inline namespace v1 {
42template<fixed_string Name =
"">
47 constexpr static auto prefix = super::prefix;
65 this->set_attributes<0>(
hi_forward(attributes)...);
81 different_from<std::shared_ptr<delegate_type>> Value,
82 forward_of<observer<observer_decay_t<Value>>> OnValue,
97 _label_constraints = super::update_constraints();
100 _button_size = theme<prefix>.size(
this);
103 hilet extra_size =
extent2i{theme<prefix>.spacing_horizontal(
this) + _button_size.
width(), 0};
105 auto constraints = max(_label_constraints + extra_size, _button_size);
106 constraints.margins = theme<prefix>.margin(
this);
107 constraints.alignment = *this->
alignment;
111 void set_layout(widget_layout
const& context)
noexcept override
116 if (alignment_ == horizontal_alignment::left or alignment_ == horizontal_alignment::right) {
117 _button_rectangle =
align(context.rectangle(), _button_size, alignment_);
122 hilet inner_margin = theme<prefix>.spacing_horizontal(
this);
123 hilet cap_height = theme<prefix>.cap_height(
this);
125 hilet label_width = context.width() - (_button_rectangle.width() + inner_margin);
126 if (alignment_ == horizontal_alignment::left) {
127 hilet label_left = _button_rectangle.right() + inner_margin;
128 hilet label_rectangle = aarectanglei{label_left, 0, label_width, context.height()};
129 this->_on_label_shape = this->_off_label_shape = this->_other_label_shape =
130 box_shape{_label_constraints, label_rectangle, cap_height};
132 }
else if (alignment_ == horizontal_alignment::right) {
133 hilet label_rectangle = aarectanglei{0, 0, label_width, context.height()};
134 this->_on_label_shape = this->_off_label_shape = this->_other_label_shape =
135 box_shape{_label_constraints, label_rectangle, cap_height};
141 _button_circle = circle{narrow_cast<aarectangle>(_button_rectangle)};
143 hilet pip_size =
theme<prefix /
"pip">.size(
this);
144 hi_axiom(pip_size.width() == pip_size.height());
147 align(narrow_cast<aarectangle>(_button_rectangle), circle{narrow_cast<float>(pip_size.width() / 2)}, alignment::middle_center());
149 super::set_layout(context);
152 void draw(widget_draw_context& context)
noexcept override
155 draw_radio_button(context);
156 draw_radio_pip(context);
157 this->draw_button(context);
164 box_constraints _label_constraints;
167 aarectanglei _button_rectangle;
168 circle _button_circle;
170 animator<float> _animated_value = _animation_duration;
173 void draw_radio_button(widget_draw_context& context)
noexcept
177 _button_circle * 1.02f,
178 theme<prefix>.background_color(
this),
179 theme<prefix>.border_color(
this),
180 theme<prefix>.border_width(
this),
184 void draw_radio_pip(widget_draw_context& context)
noexcept
187 if (_animated_value.is_animating()) {
192 auto float_value = _animated_value.current_value();
193 if (float_value > 0.0f) {
196 _pip_circle * 1.02f * float_value,
197 theme<prefix / "pip">.background_color(
this),
198 theme<prefix / "pip">.border_color(
this),
199 theme<prefix / "pip">.border_width(
this));
Defines abstract_button_widget.
#define hi_not_implemented(...)
This part of the code has not been implemented yet.
Definition assert.hpp:335
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition utility.hpp:29
geo::extent< int, 2 > extent2i
A 2D extent.
Definition extent.hpp:512
std::shared_ptr< button_delegate > make_default_radio_button_delegate(auto &&value, auto &&on_value) noexcept
Make a shared pointer to a radio-button delegate.
Definition button_delegate.hpp:205
@ invisible
The widget is invisible.
DOXYGEN BUG.
Definition algorithm.hpp:13
constexpr horizontal_alignment mirror(horizontal_alignment const &rhs) noexcept
Mirror the horizontal alignment.
Definition alignment.hpp:192
geometry/margins.hpp
Definition cache.hpp:11
@ inside
The border is drawn inside the edge of a quad.
@ off
The widget in the off-state.
bool compare_store(T &lhs, U &&rhs) noexcept
Compare then store if there was a change.
Definition utility.hpp:212
auto theme
A tagged global variable to a theme model for a widget's component.
Definition theme_model.hpp:578
constexpr value_type & width() noexcept
Access the x-as-width element from the extent.
Definition extent.hpp:166
constexpr value_type & height() noexcept
Access the y-as-height element from the extent.
Definition extent.hpp:177
virtual void request_redraw() const noexcept
Request the widget to be redrawn on the next frame.
Definition widget.hpp:265
observer< widget_state > state
The state of the widget.
Definition widget.hpp:65
widget * parent
Pointer to the parent widget.
Definition widget.hpp:40
observer< widget_mode > mode
The widget mode.
Definition widget.hpp:49
2D constraints.
Definition box_constraints.hpp:22
Base class for implementing button widgets.
Definition abstract_button_widget.hpp:33
observer< hi::alignment > alignment
The alignment of the button and on/off/other label.
Definition abstract_button_widget.hpp:58
std::shared_ptr< delegate_type > delegate
The delegate that controls the button widget.
Definition abstract_button_widget.hpp:42
A button delegate controls the state of a button widget.
Definition button_delegate.hpp:23
A graphical control element that allows the user to choose only one of a predefined set of mutually e...
Definition radio_button_widget.hpp:43
radio_button_widget(widget *parent, Value &&value, OnValue &&on_value, Attributes &&...attributes) noexcept
Construct a radio button widget with a default button delegate.
Definition radio_button_widget.hpp:84
radio_button_widget(widget *parent, std::shared_ptr< delegate_type > delegate, button_widget_attribute auto &&...attributes) noexcept
Construct a radio button widget.
Definition radio_button_widget.hpp:58
Definition abstract_button_widget.hpp:26