7#include "../concurrency/concurrency.hpp"
8#include "../theme/theme.hpp"
9#include "../macros.hpp"
15hi_export_module(hikogui.GUI : widget_state);
17hi_export
namespace hi {
inline namespace v1 {
84enum class widget_value {
90enum class widget_phase {
97constexpr auto widget_state_mode_shift = 0;
98constexpr auto widget_state_value_shift = 5;
107 constexpr widget_state(widget_state
const &)
noexcept =
default;
108 constexpr widget_state(widget_state &&)
noexcept =
default;
109 constexpr widget_state &operator=(widget_state
const &)
noexcept =
default;
110 constexpr widget_state &operator=(widget_state &&)
noexcept =
default;
112 constexpr widget_state()
noexcept =
default;
116 constexpr static widget_state
begin() noexcept
118 auto r = widget_state{};
131 constexpr static widget_state
end() noexcept
140 constexpr static size_t size() noexcept
142 return static_cast<size_t>(
end());
160 _mode =
static_cast<uint16_t
>(
mode);
169 [[nodiscard]]
constexpr size_t layer() const noexcept
180 _layer =
static_cast<uint16_t
>(
layer % 4);
188 [[nodiscard]]
constexpr widget_value
value() const noexcept
190 return static_cast<widget_value
>(_value);
199 _value =
static_cast<uint16_t
>(
value);
207 [[nodiscard]]
constexpr widget_phase
phase() const noexcept
210 return widget_phase::pressed;
212 return widget_phase::hover;
213 }
else if (_active) {
214 return widget_phase::normal;
216 return widget_phase::inactive;
220 [[nodiscard]]
constexpr bool pressed() const noexcept
231 _pressed =
static_cast<bool>(pressed);
235 [[nodiscard]]
constexpr bool hover() const noexcept
246 _hover =
static_cast<bool>(hover);
250 [[nodiscard]]
constexpr bool active() const noexcept
261 _active =
static_cast<bool>(active);
267 [[nodiscard]]
constexpr bool focus() const noexcept
269 return static_cast<bool>(_focus);
276 _focus =
static_cast<uint16_t
>(
focus);
286 }
else if (hover()) {
288 }
else if (active()) {
298 if (
value() != widget_value::off) {
313 template<std::
integral T>
314 constexpr explicit operator T() const noexcept
315 requires(sizeof(T) >= 2)
319 r +=
static_cast<T
>(_end);
322 r +=
static_cast<T
>(
focus());
325 r +=
static_cast<T
>(
phase());
328 r +=
static_cast<T
>(
value());
331 r +=
static_cast<T
>(
layer());
334 r +=
static_cast<T
>(
mode());
340 return static_cast<uint16_t
>(lhs) ==
static_cast<uint16_t
>(rhs);
362 if (
value() < widget_value::other) {
363 set_value(
static_cast<widget_value
>(std::to_underlying(
value()) + 1));
369 case widget_phase::inactive:
374 case widget_phase::normal:
379 case widget_phase::hover:
384 case widget_phase::pressed:
393 if (
focus() ==
false) {
405 [[nodiscard]]
constexpr friend bool need_reconstrain(widget_state
const &lhs, widget_state
const &rhs)
noexcept
407 return lhs._mode != rhs._mode;
412 [[nodiscard]]
constexpr friend bool need_relayout(widget_state
const &lhs, widget_state
const &rhs)
noexcept
419 [[nodiscard]]
constexpr friend bool need_redraw(widget_state
const &lhs, widget_state
const &rhs)
noexcept
431 uint16_t _layer : 2 = 0;
435 uint16_t _value : 2 =
static_cast<uint16_t
>(widget_value::off);
439 uint16_t _active: 1 = 1;
443 uint16_t _hover : 1 = 0;
447 uint16_t _pressed : 1 = 0;
451 uint16_t _focus : 1 = 0;
455 uint16_t _end : 1 = 0;
@ other
The gui_event does not have associated data.
Definition gui_event_variant.hpp:24
widget_mode
The mode that the widget is operating at.
Definition widget_state.hpp:26
@ partial
A widget is partially enabled.
Definition widget_state.hpp:73
@ collapse
The widget is collapsed.
Definition widget_state.hpp:34
@ invisible
The widget is invisible.
Definition widget_state.hpp:41
@ select
The widget is selectable.
Definition widget_state.hpp:63
@ enabled
The widget is fully enabled.
Definition widget_state.hpp:81
@ display
The widget is in display-only mode.
Definition widget_state.hpp:55
The HikoGUI namespace.
Definition array_generic.hpp:21
The HikoGUI API version 1.
Definition array_generic.hpp:22
style_pseudo_class
The different dynamic states of a widget from the point of view of styles.
Definition style_pseudo_class.hpp:18
@ disabled
The widget is disabled, often shown in gray.
Definition style_pseudo_class.hpp:23
@ focus
The widget has keyboard focus.
Definition style_pseudo_class.hpp:45
@ enabled
The widget is enabled, the normal idle state.
Definition style_pseudo_class.hpp:29
@ active
The widget was clicked by the mouse or otherwise activated.
Definition style_pseudo_class.hpp:41
@ hover
The mouse hovers over the widget.
Definition style_pseudo_class.hpp:35
@ _false
The value that the widget represent is 'false'.
Definition style_pseudo_class.hpp:49
@ _true
The value that the widget represent is 'true'.
Definition style_pseudo_class.hpp:53
@ on
The border is drawn on the edge of a quad.
Definition draw_context_intf.hpp:31
The state the widget is in.
Definition widget_state.hpp:105
constexpr widget_state & set_layer(size_t layer) noexcept
Set the layer of the widget.
Definition widget_state.hpp:178
constexpr widget_state & set_hover(bool hover) noexcept
Set if the mouse hovers over the widget.
Definition widget_state.hpp:244
constexpr widget_state & set_mode(widget_mode mode) noexcept
Set the mode of a widget.
Definition widget_state.hpp:158
static constexpr widget_state end() noexcept
End of the iteration of all possible widget states.
Definition widget_state.hpp:131
constexpr size_t layer() const noexcept
Get the layer of a widget.
Definition widget_state.hpp:169
constexpr widget_state & set_active(bool active) noexcept
Set if the window is active widget.
Definition widget_state.hpp:259
constexpr bool focus() const noexcept
Get if the window has keyboard focus.
Definition widget_state.hpp:267
constexpr widget_phase phase() const noexcept
Get the phase of the widget.
Definition widget_state.hpp:207
constexpr widget_state & set_value(widget_value value) noexcept
Set the value of the widget.
Definition widget_state.hpp:197
constexpr widget_state & set_pressed(bool pressed) noexcept
Set if the mouse/finger presses the widget.
Definition widget_state.hpp:229
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:405
static constexpr size_t size() noexcept
The number if possible widget states.
Definition widget_state.hpp:140
static constexpr widget_state begin() noexcept
Start of the iteration of all possible widget states.
Definition widget_state.hpp:116
constexpr widget_state & operator++() noexcept
Increment the widget-state.
Definition widget_state.hpp:348
constexpr widget_state & set_focus(bool focus) noexcept
Set if the window has keyboard focus.
Definition widget_state.hpp:274
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:412
constexpr widget_value value() const noexcept
Get the value of the widget.
Definition widget_state.hpp:188
constexpr widget_mode mode() const noexcept
Get the mode of a widget.
Definition widget_state.hpp:149
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:419