7#include "../concurrency/concurrency.hpp"
8#include "../macros.hpp"
14hi_export_module(hikogui.GUI : widget_state);
16hi_export
namespace hi {
inline namespace v1 {
83enum class widget_value {
89enum class widget_phase {
96constexpr auto widget_state_mode_shift = 0;
97constexpr auto widget_state_value_shift = 5;
139 constexpr static size_t size() noexcept
141 return static_cast<size_t>(
end());
159 _mode =
static_cast<uint16_t
>(
mode);
168 [[nodiscard]]
constexpr size_t layer() const noexcept
179 _layer =
static_cast<uint16_t
>(
layer % 4);
187 [[nodiscard]]
constexpr widget_value
value() const noexcept
189 return static_cast<widget_value
>(_value);
198 _value =
static_cast<uint16_t
>(
value);
206 [[nodiscard]]
constexpr widget_phase
phase() const noexcept
209 return widget_phase::pressed;
211 return widget_phase::hover;
212 }
else if (_active) {
213 return widget_phase::normal;
215 return widget_phase::inactive;
225 _pressed =
static_cast<bool>(pressed);
235 _hover =
static_cast<bool>(hover);
245 _active =
static_cast<bool>(active);
251 [[nodiscard]]
constexpr bool focus() const noexcept
253 return static_cast<bool>(_focus);
260 _focus =
static_cast<uint16_t
>(
focus);
270 template<std::
integral T>
271 constexpr explicit operator T() const noexcept
272 requires(sizeof(T) >= 2)
276 r +=
static_cast<T
>(_end);
279 r +=
static_cast<T
>(
focus());
282 r +=
static_cast<T
>(
phase());
285 r +=
static_cast<T
>(
value());
288 r +=
static_cast<T
>(
layer());
291 r +=
static_cast<T
>(
mode());
297 return static_cast<uint16_t
>(lhs) ==
static_cast<uint16_t
>(rhs);
319 if (
value() < widget_value::other) {
320 set_value(
static_cast<widget_value
>(std::to_underlying(
value()) + 1));
326 case widget_phase::inactive:
331 case widget_phase::normal:
336 case widget_phase::hover:
341 case widget_phase::pressed:
350 if (
focus() ==
false) {
364 return lhs._mode != rhs._mode;
388 uint16_t _layer : 2 = 0;
392 uint16_t _value : 2 =
static_cast<uint16_t
>(widget_value::off);
396 uint16_t _active: 1 = 1;
400 uint16_t _hover : 1 = 0;
404 uint16_t _pressed : 1 = 0;
408 uint16_t _focus : 1 = 0;
412 uint16_t _end : 1 = 0;
@ other
The gui_event does not have associated data.
widget_mode
The mode that the widget is operating at.
Definition widget_state.hpp:25
@ partial
A widget is partially enabled.
@ collapse
The widget is collapsed.
@ invisible
The widget is invisible.
@ select
The widget is selectable.
@ enabled
The widget is fully enabled.
@ display
The widget is in display-only mode.
The HikoGUI namespace.
Definition array_generic.hpp:20
@ on
The border is drawn on the edge of a quad.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
The state the widget is in.
Definition widget_state.hpp:104
constexpr widget_state & set_layer(size_t layer) noexcept
Set the layer of the widget.
Definition widget_state.hpp:177
constexpr widget_state & set_hover(bool hover) noexcept
Set if the mouse hovers over the widget.
Definition widget_state.hpp:233
constexpr widget_state & set_mode(widget_mode mode) noexcept
Set the mode of a widget.
Definition widget_state.hpp:157
static constexpr widget_state end() noexcept
End of the iteration of all possible widget states.
Definition widget_state.hpp:130
constexpr size_t layer() const noexcept
Get the layer of a widget.
Definition widget_state.hpp:168
constexpr widget_state & set_active(bool active) noexcept
Set if the window is active widget.
Definition widget_state.hpp:243
constexpr bool focus() const noexcept
Get if the window has keyboard focus.
Definition widget_state.hpp:251
constexpr widget_phase phase() const noexcept
Get the phase of the widget.
Definition widget_state.hpp:206
constexpr widget_state & set_value(widget_value value) noexcept
Set the value of the widget.
Definition widget_state.hpp:196
constexpr widget_state & set_pressed(bool pressed) noexcept
Set if the mouse/finger presses the widget.
Definition widget_state.hpp:223
constexpr friend bool need_reconstrain(widget_state const &lhs, widget_state const &rhs) noexcept
Check if the change in widget-state requires the widget to reconstrain.
Definition widget_state.hpp:362
static constexpr size_t size() noexcept
The number if possible widget states.
Definition widget_state.hpp:139
static constexpr widget_state begin() noexcept
Start of the iteration of all possible widget states.
Definition widget_state.hpp:115
constexpr widget_state & operator++() noexcept
Increment the widget-state.
Definition widget_state.hpp:305
constexpr widget_state & set_focus(bool focus) noexcept
Set if the window has keyboard focus.
Definition widget_state.hpp:258
constexpr friend bool need_relayout(widget_state const &lhs, widget_state const &rhs) noexcept
Check if the change in widget-state requires the widget to relayout.
Definition widget_state.hpp:369
constexpr widget_value value() const noexcept
Get the value of the widget.
Definition widget_state.hpp:187
constexpr widget_mode mode() const noexcept
Get the mode of a widget.
Definition widget_state.hpp:148
constexpr friend bool need_redraw(widget_state const &lhs, widget_state const &rhs) noexcept
Check if the change in widget-state requires the widget to redraw.
Definition widget_state.hpp:376