HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
toolbar_tab_button_widget.hpp
Go to the documentation of this file.
1// Copyright Take Vos 2021-2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
9#pragma once
10
12#include "../macros.hpp"
13
14namespace hi { inline namespace v1 {
15
48public:
50 using delegate_type = typename super::delegate_type;
51
70
83 template<
88 requires requires { make_default_radio_button_delegate(hi_forward(value), hi_forward(on_value)); }
89 :
91 parent,
92 make_default_radio_button_delegate(hi_forward(value), hi_forward(on_value)),
93 hi_forward(attributes)...)
94 {
95 }
96
98 {
99 // A toolbar tab button draws a focus line across the whole toolbar
100 // which is beyond it's own clipping rectangle. The parent is the toolbar
101 // so it will include everything that needs to be redrawn.
102 if (parent != nullptr) {
104 } else {
106 }
107 }
108
110 [[nodiscard]] box_constraints update_constraints() noexcept override
111 {
112 _label_constraints = super::update_constraints();
113
114 // On left side a check mark, on right side short-cut. Around the label extra margin.
115 hilet extra_size = extent2{theme().margin<float>() * 2.0f, theme().margin<float>()};
116 return _label_constraints + extra_size;
117 }
118
119 void set_layout(widget_layout const& context) noexcept override
120 {
121 if (compare_store(_layout, context)) {
122 hilet label_rectangle = aarectangle{
123 theme().margin<float>(),
124 0.0f,
125 context.width() - theme().margin<float>() * 2.0f,
126 context.height() - theme().margin<float>()};
127 _on_label_shape = _off_label_shape = _other_label_shape =
128 box_shape{_label_constraints, label_rectangle, theme().baseline_adjustment()};
129 }
130 super::set_layout(context);
131 }
132
133 void draw(draw_context const& context) noexcept override
134 {
135 if (*mode > widget_mode::invisible and overlaps(context, layout())) {
136 draw_toolbar_tab_button(context);
137 draw_button(context);
138 }
139 }
140
141 [[nodiscard]] bool accepts_keyboard_focus(keyboard_focus_group group) const noexcept override
142 {
143 return *mode >= widget_mode::partial and to_bool(group & hi::keyboard_focus_group::toolbar);
144 }
145 // @endprivatesection
146private:
147 box_constraints _label_constraints;
148
149 void draw_toolbar_tab_button(draw_context const& context) noexcept
150 {
151 // Draw the outline of the button across the clipping rectangle to clip the
152 // bottom of the outline.
153 hilet offset = theme().margin<float>() + theme().border_width();
154 hilet outline_rectangle = aarectangle{0, -offset, layout().width(), layout().height() + offset};
155
156 // The focus line will be drawn by the parent widget (toolbar_widget) at 0.5.
157 hilet button_z = *focus ? translate_z(0.6f) : translate_z(0.0f);
158
159 // clang-format off
161 theme().color(semantic_color::fill, semantic_layer - 1) :
162 theme().color(semantic_color::fill, semantic_layer);
163 // clang-format on
164
165 hilet corner_radii = hi::corner_radii(0.0f, 0.0f, theme().rounding_radius<float>(), theme().rounding_radius<float>());
166
167 context.draw_box(
168 layout(),
171 *focus ? focus_color() : button_color,
172 theme().border_width(),
174 corner_radii);
175 }
176};
177
178}} // namespace hi::v1
Defines abstract_button_widget.
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:227
@ on
The 'on' state of a button.
@ partial
A widget is partially enabled.
@ invisible
The widget is invisible.
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
border_side
The side where the border is drawn.
Definition draw_context.hpp:27
@ 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 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
The 4 radii of the corners of a quad or rectangle.
Definition corner_radii.hpp:19
A high-level geometric extent.
Definition extent2.hpp:29
virtual void request_redraw() const noexcept=0
Request the widget to be redrawn on the next frame.
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
A button delegate controls the state of a button widget.
Definition button_delegate.hpp:45
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:47
toolbar_tab_button_widget(widget *parent, Value &&value, OnValue &&on_value, Attributes &&...attributes) noexcept
Construct a toolbar tab button widget with a default button delegate.
Definition toolbar_tab_button_widget.hpp:87
void request_redraw() const noexcept override
Request the widget to be redrawn on the next frame.
Definition toolbar_tab_button_widget.hpp:97
toolbar_tab_button_widget(widget *parent, std::shared_ptr< delegate_type > delegate, button_widget_attribute auto &&...attributes) noexcept
Construct a toolbar tab button widget.
Definition toolbar_tab_button_widget.hpp:61
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
int semantic_layer
The draw layer of the widget.
Definition widget.hpp:66
observer< bool > hover
Mouse cursor is hovering over the widget.
Definition widget.hpp:46
observer< widget_mode > mode
The widget mode.
Definition widget.hpp:42
observer< bool > focus
The widget has keyboard focus.
Definition widget.hpp:50
Definition concepts.hpp:54
True if T is a forwarded type of Forward.
Definition concepts.hpp:131
Definition abstract_button_widget.hpp:27
T move(T... args)