14namespace hi {
inline namespace v1 {
42template<fixed_string Name =
"">
47 constexpr static auto prefix = super::prefix;
65 this->set_attributes<0>(
hi_forward(attributes)...);
99 different_from<std::shared_ptr<delegate_type>> Value,
100 forward_of<observer<observer_decay_t<Value>>> OnValue,
101 button_widget_attribute... Attributes>
125 different_from<std::shared_ptr<delegate_type>> Value,
126 forward_of<observer<observer_decay_t<Value>>> OnValue,
127 forward_of<observer<observer_decay_t<Value>>> OffValue,
128 button_widget_attribute... Attributes>
133 OffValue&& off_value,
134 Attributes&&...attributes)
noexcept
147 _label_constraints = super::update_constraints();
149 _button_size = theme<prefix>.size(
this);
150 hilet extra_size =
extent2i{theme<prefix>.horizontal_spacing(
this) + _button_size.
width(), 0};
152 auto constraints = max(_label_constraints + extra_size, _button_size);
153 constraints.margins = theme<prefix>.margin(
this);
154 constraints.alignment = *this->
alignment;
158 void set_layout(widget_layout
const& context)
noexcept override
163 if (alignment_ == horizontal_alignment::left or alignment_ == horizontal_alignment::right) {
164 _button_rectangle =
align(context.rectangle(), _button_size, alignment_);
169 hilet inner_margin = theme<prefix>.horizontal_spacing(
this);
170 hilet baseline_offset = theme<prefix>.cap_height(
this);
171 hilet icon_size =
theme<prefix /
"icon">.size(
this);
173 hilet label_width = context.width() - (_button_rectangle.width() + inner_margin);
174 if (alignment_ == horizontal_alignment::left) {
175 hilet label_left = _button_rectangle.right() + inner_margin;
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, baseline_offset);
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, baseline_offset);
189 hilet check_glyph_bb = narrow_cast<aarectanglei>(_check_glyph.get_bounding_rectangle() * icon_size);
190 _check_glyph_rectangle =
align(_button_rectangle, check_glyph_bb, alignment::middle_center());
192 _minus_glyph =
find_glyph(elusive_icon::Minus);
193 hilet minus_glyph_bb = narrow_cast<aarectanglei>(_minus_glyph.get_bounding_rectangle() * icon_size);
194 _minus_glyph_rectangle =
align(_button_rectangle, minus_glyph_bb, alignment::middle_center());
196 super::set_layout(context);
199 void draw(widget_draw_context
const& context)
noexcept override
202 draw_check_box(context);
203 draw_check_mark(context);
204 this->draw_button(context);
209 box_constraints _label_constraints;
212 aarectanglei _button_rectangle;
213 font_book::font_glyph_type _check_glyph;
214 aarectanglei _check_glyph_rectangle;
215 font_book::font_glyph_type _minus_glyph;
216 aarectanglei _minus_glyph_rectangle;
218 void draw_check_box(widget_draw_context
const& context)
noexcept
223 theme<prefix>.background_color(
this),
224 theme<prefix>.border_color(
this),
225 theme<prefix>.border_width(
this),
229 void draw_check_mark(widget_draw_context
const& context)
noexcept
235 translate_z(0.1f) * narrow_cast<aarectangle>(_check_glyph_rectangle),
238 theme<prefix>.fill_color(
this));
247 translate_z(0.1f) * narrow_cast<aarectangle>(_minus_glyph_rectangle),
250 theme<prefix>.fill_color(
this));
Defines abstract_button_widget.
#define hi_not_implemented(...)
This part of the code has not been implemented yet.
Definition assert.hpp:335
#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_toggle_button_delegate(auto &&value, auto &&...args) noexcept
Make a shared pointer to a toggle-button delegate.
Definition button_delegate.hpp:223
@ invisible
The widget is invisible.
DOXYGEN BUG.
Definition algorithm.hpp:13
auto find_glyph(font const &font, grapheme grapheme) noexcept
Find a glyph using the given code-point.
Definition font_book.hpp:234
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.
@ on
The widget is in the on-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:433
constexpr value_type & width() noexcept
Access the x-as-width element from the extent.
Definition extent.hpp:166
observer< widget_state > state
The state of the widget.
Definition widget.hpp:69
widget * parent
Pointer to the parent widget.
Definition widget.hpp:40
observer< widget_mode > mode
The widget mode.
Definition widget.hpp:53
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 GUI widget that permits the user to make a binary choice.
Definition checkbox_widget.hpp:43
checkbox_widget(widget *parent, std::shared_ptr< delegate_type > delegate, button_widget_attribute auto &&...attributes) noexcept
Construct a checkbox widget.
Definition checkbox_widget.hpp:58
checkbox_widget(widget *parent, Value &&value, OnValue &&on_value, Attributes &&...attributes) noexcept
Construct a checkbox widget with a default button delegate.
Definition checkbox_widget.hpp:102
checkbox_widget(widget *parent, Value &&value, OnValue &&on_value, OffValue &&off_value, Attributes &&...attributes) noexcept
Construct a checkbox widget with a default button delegate.
Definition checkbox_widget.hpp:129
checkbox_widget(widget *parent, different_from< std::shared_ptr< delegate_type > > auto &&value, button_widget_attribute auto &&...attributes) noexcept
Construct a checkbox widget with a default button delegate.
Definition checkbox_widget.hpp:78
Definition abstract_button_widget.hpp:26