12#include "radio_delegate.hpp"
13#include "../macros.hpp"
15hi_export_module(hikogui.widgets.toolbar_tab_button_widget);
17hi_export
namespace hi {
20template<
typename Context>
85 template<
size_t NumLabels>
103 hi_static_no_default(
"Maximum two label attributes (on/off) are allowed on a toolbar-tab-button");
108 alignment = std::forward<First>(first);
116 hi_static_no_default();
121 attributes_type attributes;
151 _on_label_widget = std::make_unique<label_widget>(
152 this, this->attributes.on_label,
this->attributes.alignment,
this->attributes.text_style);
153 _off_label_widget = std::make_unique<label_widget>(
154 this, this->attributes.off_label,
this->attributes.alignment,
this->attributes.text_style);
156 this->delegate->init(*
this);
157 _delegate_cbt = this->delegate->subscribe([&] {
158 set_value(this->delegate->state(*
this));
169 template<
typename...
Args>
171 requires(num_default_delegate_arguments<
Args...>() != 0)
196 _on_label_constraints = _on_label_widget->update_constraints();
197 _off_label_constraints = _off_label_widget->update_constraints();
199 _label_constraints = max(_on_label_constraints, _off_label_constraints);
202 auto const extra_size =
extent2{theme().margin<
float>() * 2.0f, theme().margin<
float>()};
206 void set_layout(widget_layout
const&
context)
noexcept override
210 theme().margin<
float>(),
212 context.width() - theme().margin<
float>() * 2.0f,
213 context.height() - theme().margin<
float>()};
214 _on_label_shape = _off_label_shape =
215 box_shape{_label_constraints,
label_rectangle, theme().baseline_adjustment()};
221 _on_label_widget->set_layout(
context.transform(_on_label_shape));
222 _off_label_widget->set_layout(
context.transform(_off_label_shape));
225 void draw(draw_context
const&
context)
noexcept override
228 draw_toolbar_tab_button(
context);
229 _on_label_widget->draw(
context);
230 _off_label_widget->draw(
context);
234 [[
nodiscard]]
bool accepts_keyboard_focus(keyboard_focus_group group)
const noexcept override
241 co_yield *_on_label_widget;
242 co_yield *_off_label_widget;
247 hi_axiom(loop::main().on_thread());
248 if (phase() == widget_phase::pressed) {
249 return theme().color(semantic_color::fill, _layout.layer + 2);
251 return super::background_color();
255 [[
nodiscard]] hitbox hitbox_test(point2 position)
const noexcept override
257 hi_axiom(loop::main().on_thread());
260 return {
id, _layout.elevation, hitbox_type::button};
273 bool handle_event(gui_event
const&
event)
noexcept override
275 hi_axiom(loop::main().on_thread());
277 switch (
event.type()) {
278 case gui_event_type::gui_activate:
285 case gui_event_type::mouse_down:
292 case gui_event_type::mouse_up:
297 handle_event(gui_event_type::gui_activate);
311 box_constraints _on_label_constraints;
312 box_shape _on_label_shape;
315 box_constraints _off_label_constraints;
316 box_shape _off_label_shape;
318 callback<
void()> _delegate_cbt;
321 box_constraints _label_constraints;
323 void draw_toolbar_tab_button(draw_context
const&
context)
noexcept
327 auto const offset = theme().margin<
float>() + theme().border_width();
331 auto const button_z = focus() ? translate_z(0.6f) : translate_z(0.0f);
334 auto button_color = (phase() == widget_phase::hover
or value() == widget_value::on) ?
335 theme().color(semantic_color::fill, _layout.layer - 1) :
336 theme().color(semantic_color::fill, _layout.layer);
346 theme().border_width(),
@ rectangle
The gui_event has rectangle data.
widget_mode
The mode that the widget is operating at.
Definition widget_state.hpp:25
@ partial
A widget is partially enabled.
@ invisible
The widget is invisible.
@ display
The widget is in display-only mode.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
border_side
The side where the border is drawn.
Definition draw_context_intf.hpp:28
@ 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:53
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378
Horizontal/Vertical alignment combination.
Definition alignment.hpp:244
The 4 radii of the corners of a quad or rectangle.
Definition corner_radii.hpp:26
A high-level geometric extent.
Definition extent2.hpp:32
notifier< void()> notifier
Notifier which is called after an action is completed by a widget.
Definition widget_intf.hpp:39
widget_id id
The numeric identifier of a widget.
Definition widget_intf.hpp:30
virtual void request_redraw() const noexcept=0
Request the widget to be redrawn on the next frame.
widget_layout const & layout() const noexcept
Get the current layout for this widget.
Definition widget_intf.hpp:206
widget_intf * parent
Pointer to the parent widget.
Definition widget_intf.hpp:35
A localizable message.
Definition txt.hpp:100
2D constraints.
Definition box_constraints.hpp:25
A observer pointing to the whole or part of a observed_base.
Definition observer_intf.hpp:32
void reset() noexcept
Reset the observer.
Definition observer_intf.hpp:421
Definition not_null.hpp:22
A radio delegate controls the state of a radio button widget.
Definition radio_delegate.hpp:16
A default radio button delegate.
Definition radio_delegate.hpp:56
A graphical control element that allows the user to choose only one of a predefined set of mutually e...
Definition toolbar_tab_button_widget.hpp:54
toolbar_tab_button_widget(not_null< widget_intf const * > parent, Args &&...args)
Construct a toolbar tab button widget with a default radio delegate.
Definition toolbar_tab_button_widget.hpp:170
not_null< std::shared_ptr< delegate_type > > delegate
The delegate that controls the button widget.
Definition toolbar_tab_button_widget.hpp:125
void request_redraw() const noexcept override
Request the widget to be redrawn on the next frame.
Definition toolbar_tab_button_widget.hpp:180
toolbar_tab_button_widget(not_null< widget_intf const * > parent, attributes_type attributes, not_null< std::shared_ptr< delegate_type > > delegate) noexcept
Construct a toolbar tab button widget.
Definition toolbar_tab_button_widget.hpp:145
Definition toolbar_tab_button_widget.hpp:59
observer< label > off_label
The label to show when the button is in the 'off' state.
Definition toolbar_tab_button_widget.hpp:66
observer< semantic_text_style > text_style
The text style to button's label.
Definition toolbar_tab_button_widget.hpp:70
observer< label > on_label
The label to show when the button is in the 'on' state.
Definition toolbar_tab_button_widget.hpp:62
An interactive graphical object as part of the user-interface.
Definition widget.hpp:37
void request_redraw() const noexcept override
Request the widget to be redrawn on the next frame.
Definition widget.hpp:135
widget(widget_intf const *parent) noexcept
Definition widget.hpp:49
bool handle_event(gui_event const &event) noexcept override
Handle command.
Definition widget.hpp:144
True if T is a forwarded type of Forward.
Definition concepts.hpp:136
Definition label_widget.hpp:30
Definition toolbar_tab_button_widget.hpp:21