HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
toggle_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
13namespace hi { inline namespace v1 {
14
53public:
55 using delegate_type = typename super::delegate_type;
56
69 button_widget_attribute auto&&...attributes) noexcept :
71 {
72 alignment = alignment::top_left();
73 set_attributes<0>(hi_forward(attributes)...);
74 }
75
86 template<different_from<std::shared_ptr<delegate_type>> Value, button_widget_attribute... Attributes>
87 toggle_widget(widget *parent, Value&& value, Attributes&&...attributes) noexcept requires requires
88 {
91
103 template<
104 different_from<std::shared_ptr<delegate_type>> Value,
105 forward_of<observer<observer_decay_t<Value>>> OnValue,
106 button_widget_attribute... Attributes>
107 toggle_widget(widget *parent, Value&& value, OnValue&& on_value, Attributes&&...attributes) noexcept
108 requires requires
109 {
111 } :
113 parent,
115 hi_forward(attributes)...)
116 {
117 }
118
131 template<
132 different_from<std::shared_ptr<delegate_type>> Value,
133 forward_of<observer<observer_decay_t<Value>>> OnValue,
134 forward_of<observer<observer_decay_t<Value>>> OffValue,
135 button_widget_attribute... Attributes>
137 widget *parent,
138 Value&& value,
139 OnValue&& on_value,
140 OffValue&& off_value,
141 Attributes&&...attributes) noexcept requires requires
142 {
144 } :
146 parent,
148 hi_forward(attributes)...)
149 {
150 }
151
153 [[nodiscard]] box_constraints update_constraints() noexcept override;
154 void set_layout(widget_layout const& context) noexcept override;
155 void draw(draw_context const& context) noexcept override;
157private:
158 static constexpr std::chrono::nanoseconds _animation_duration = std::chrono::milliseconds(150);
159
160 box_constraints _label_constraints;
161
162 extent2i _button_size;
163 aarectanglei _button_rectangle;
164 animator<float> _animated_value = _animation_duration;
165 aarectanglei _pip_rectangle;
166 int _pip_move_range;
167
168 void draw_toggle_button(draw_context const& context) noexcept;
169 void draw_toggle_pip(draw_context const& context) noexcept;
170};
171
172}} // namespace hi::v1
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition utility.hpp:29
Defines abstract_button_widget.
geo::extent< int, 2 > extent2i
A 2D extent.
Definition extent.hpp:513
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
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:15
geometry/margins.hpp
Definition assert.hpp:18
2D constraints.
Definition box_constraints.hpp:25
Base class for implementing button widgets.
Definition abstract_button_widget.hpp:32
std::shared_ptr< delegate_type > delegate
The delegate that controls the button widget.
Definition abstract_button_widget.hpp:39
observer< alignment > alignment
The alignment of the button and on/off/other label.
Definition abstract_button_widget.hpp:55
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:52
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:107
toggle_widget(widget *parent, std::shared_ptr< delegate_type > delegate, button_widget_attribute auto &&...attributes) noexcept
Construct a toggle widget.
Definition toggle_widget.hpp:66
toggle_widget(widget *parent, Value &&value, Attributes &&...attributes) noexcept
Construct a toggle widget with a default button delegate.
Definition toggle_widget.hpp:87
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:136
An interactive graphical object as part of the user-interface.
Definition widget.hpp:46
widget * parent
Pointer to the parent widget.
Definition widget.hpp:51
The layout of a widget.
Definition widget_layout.hpp:41
Definition abstract_button_widget.hpp:26
T move(T... args)