TachyonUI 1.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_state_atomic_values.h
Go to the documentation of this file.
1#pragma once
2
3#include <assert.h>
4#include <stdint.h>
5
6#include <gui_core/gui_id.h>
8
9// Small state values owned by GUIStateManager.
10
11namespace tachyon
12{
15
16 enum class MouseCursor : uint8_t; // gui_core/style/gui_style.h
17 enum class ElementState : uint8_t; // gui_core/style/gui_style.h
18
21 {
23 MouseCursor m_requested{};
24
25 public:
26 void Request(MouseCursor c) { m_requested = c; }
27 void Clear() { m_requested = {}; }
28 MouseCursor Get() const { return m_requested; }
29 };
30
33 {
34 ID m_focusedID = ID::Invalid();
35 ID m_prevFocusedID = ID::Invalid();
36
37 public:
38 ID GetFocusedID() const { return m_focusedID; }
41 ID GetPrevFocusedID() const { return m_prevFocusedID; }
42
43 void Set(ID id) { m_focusedID = id; }
44 void Clear() { m_focusedID = ID::Invalid(); }
45 void Commit() { m_prevFocusedID = m_focusedID; }
46 };
47
51 {
52 uint32_t m_disabledLevel = 0;
53 uint32_t m_selectedLevel = 0;
54 uint32_t m_indeterminateLevel = 0;
55 uint32_t m_invalidLevel = 0;
56 // PushShownState's states, innermost last.
57 static constexpr uint32_t kMaxShownStates = 8;
58 uint8_t m_shownStates[kMaxShownStates] {};
59 uint32_t m_shownLevel = 0;
60
61 public:
62 void PushDisabled() { m_disabledLevel++; }
63 void PopDisabled() { if (m_disabledLevel > 0) m_disabledLevel--; else ReportUnmatchedPop("ConstructionScopes: PopDisabled without PushDisabled (ignored)"); }
64
65 void PushSelected() { m_selectedLevel++; }
66 void PopSelected() { if (m_selectedLevel > 0) m_selectedLevel--; else ReportUnmatchedPop("ConstructionScopes: PopSelected without PushSelected (ignored)"); }
67
68 void PushInvalid() { m_invalidLevel++; }
69 void PopInvalid() { if (m_invalidLevel > 0) m_invalidLevel--; else ReportUnmatchedPop("ConstructionScopes: PopInvalid without PushInvalid (ignored)"); }
70
71 void PushIndeterminate() { m_indeterminateLevel++; }
72 void PopIndeterminate() { if (m_indeterminateLevel > 0) m_indeterminateLevel--; else ReportUnmatchedPop("ConstructionScopes: PopIndeterminate without PushIndeterminate (ignored)"); }
73
78 {
79 if (m_shownLevel < kMaxShownStates) m_shownStates[m_shownLevel] = static_cast<uint8_t>(states);
80 m_shownLevel++;
81 }
82 void PopShownState() { if (m_shownLevel > 0) m_shownLevel--; else ReportUnmatchedPop("ConstructionScopes: PopShownState without PushShownState (ignored)"); }
85 {
86 uint8_t s = 0;
87 for (uint32_t i = 0; i < m_shownLevel && i < kMaxShownStates; ++i) s = uint8_t(s | m_shownStates[i]);
88 return static_cast<ElementState>(s);
89 }
90
91 bool IsDisabled() const { return m_disabledLevel > 0; }
92 bool IsSelected() const { return m_selectedLevel > 0; }
93 bool IsIndeterminate() const { return m_indeterminateLevel > 0; }
94 bool IsInvalid() const { return m_invalidLevel > 0; }
95
96 void Reset() { m_disabledLevel = 0; m_selectedLevel = 0; m_indeterminateLevel = 0; m_invalidLevel = 0; m_shownLevel = 0; }
99 ConstructionScopes SetAside() { const ConstructionScopes kept = *this; Reset(); return kept; }
100 void Restore(const ConstructionScopes& kept) { *this = kept; }
101 bool IsBalanced() const { return m_disabledLevel == 0 && m_selectedLevel == 0 && m_indeterminateLevel == 0 && m_invalidLevel == 0 && m_shownLevel == 0; }
102
103 private:
105 static void ReportUnmatchedPop(const char* message)
106 {
108 }
109 };
110
111}
Construction-time Push/Pop nesting read by GUIStateManager::GetCurrentState.
Definition gui_state_atomic_values.h:51
void PopDisabled()
Definition gui_state_atomic_values.h:63
void PopShownState()
Definition gui_state_atomic_values.h:82
bool IsDisabled() const
Definition gui_state_atomic_values.h:91
void Restore(const ConstructionScopes &kept)
Definition gui_state_atomic_values.h:100
void PopSelected()
Definition gui_state_atomic_values.h:66
bool IsBalanced() const
Definition gui_state_atomic_values.h:101
void PushIndeterminate()
Definition gui_state_atomic_values.h:71
void PushShownState(ElementState states)
Everything built until PopShownState looks as in states too (Hover, Active, Focused): a picture of a ...
Definition gui_state_atomic_values.h:77
void PopIndeterminate()
Definition gui_state_atomic_values.h:72
void PushDisabled()
Definition gui_state_atomic_values.h:62
void Reset()
Definition gui_state_atomic_values.h:96
void PushInvalid()
Definition gui_state_atomic_values.h:68
bool IsIndeterminate() const
Definition gui_state_atomic_values.h:93
ConstructionScopes SetAside()
Clears the scopes for something built inside them that isn't part of them (a tooltip on a disabled co...
Definition gui_state_atomic_values.h:99
ElementState ShownStates() const
The states the PushShownState scopes add.
Definition gui_state_atomic_values.h:84
bool IsSelected() const
Definition gui_state_atomic_values.h:92
void PopInvalid()
Definition gui_state_atomic_values.h:69
void PushSelected()
Definition gui_state_atomic_values.h:65
bool IsInvalid() const
Definition gui_state_atomic_values.h:94
The mouse cursor requested this frame.
Definition gui_state_atomic_values.h:21
MouseCursor Get() const
Definition gui_state_atomic_values.h:28
void Request(MouseCursor c)
Definition gui_state_atomic_values.h:26
void Clear()
Definition gui_state_atomic_values.h:27
The focused text editor, plus the one as of the last Commit, to detect changes.
Definition gui_state_atomic_values.h:33
void Commit()
Definition gui_state_atomic_values.h:45
ID GetFocusedID() const
Definition gui_state_atomic_values.h:38
void Clear()
Definition gui_state_atomic_values.h:44
ID GetPrevFocusedID() const
The focused editor as of the last Commit, when the text system switched its editor to it: the field t...
Definition gui_state_atomic_values.h:41
void Set(ID id)
Definition gui_state_atomic_values.h:43
constexpr LogCategory MakeLogCategory(std::string_view staticName)
A category named staticName, which must be a static string.
Definition gui_logging.h:41
void ReportMisuse(LogCategory category, const char *message)
API misuse (an unbalanced Begin/End, a call outside its frame, ...) is reported, not fatal: the calle...
MouseCursor
Mouse cursor shown over an element (CSS: cursor).
Definition gui_style.h:481
ElementState
Interaction state bits of an element; they pick the Style::states variant it draws with.
Definition gui_style.h:42
Definition gui_logging.h:24
A 64-bit element ID whose bit layout depends on its IDMode.
Definition gui_id.h:23
static constexpr ID Invalid()
The "no element" ID (all bits zero); also the default for optional ID parameters.
Definition gui_id.h:66