TachyonUI 1.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_tab_chain_manager.h
Go to the documentation of this file.
1#pragma once
2
3#include <gui_core/gui_id.h>
4
5#include <vector>
6
7namespace tachyon
8{
11
12 class GUIStateManager;
13
18 {
19 ID m_currentFocusedID = ID::Invalid();
20 ID m_currentWindowID = ID::Invalid();
21 ID m_activeWindowID = ID::Invalid();
24 std::vector<ID> m_outerWindowIDs;
25
27 ID m_nextTabTarget = ID::Invalid();
28 ID m_prevTabTarget = ID::Invalid();
29
31 ID m_firstTabTarget = ID::Invalid();
32 ID m_lastTabTarget = ID::Invalid();
33 ID m_defaultFocusID = ID::Invalid();
34
36 bool m_spanOpen = false;
37 ID m_spanFirst = ID::Invalid();
38 ID m_spanLast = ID::Invalid();
39
40 public:
41 void BeginFrame(const GUIStateManager& guiStateManager);
42
45 void SetDefaultFocusID(ID defaultID)
46 {
47 m_defaultFocusID = defaultID;
48 }
49
52 void BeginWindow(ID windowID)
53 {
54 m_outerWindowIDs.push_back(m_currentWindowID);
55 m_currentWindowID = windowID;
56 if (m_currentWindowID == m_activeWindowID)
57 {
58 m_firstTabTarget = ID::Invalid();
59 m_lastTabTarget = ID::Invalid();
60 }
61 }
62
64 void RegisterTabTarget(ID elementID)
65 {
66 // Only the active window gets a tab chain.
67 if (m_currentWindowID != m_activeWindowID)
68 return;
69
70 if (m_firstTabTarget == ID::Invalid())
71 {
72 m_firstTabTarget = elementID;
73 }
74
75 if (m_lastTabTarget == m_currentFocusedID)
76 {
77 m_nextTabTarget = elementID;
78 }
79
80 if (elementID == m_currentFocusedID)
81 {
82 m_prevTabTarget = m_lastTabTarget;
83 }
84
85 m_lastTabTarget = elementID;
86
87 if (m_spanOpen)
88 {
89 if (m_spanFirst == ID::Invalid())
90 m_spanFirst = elementID;
91 m_spanLast = elementID;
92 }
93 }
94
97 void BeginSpan()
98 {
99 m_spanOpen = true;
100 m_spanFirst = ID::Invalid();
101 m_spanLast = ID::Invalid();
102 }
103 void EndSpan() { m_spanOpen = false; }
105 ID SpanFirst() const { return m_spanFirst; }
106 ID SpanLast() const { return m_spanLast; }
107
110 {
111 if (m_currentWindowID == m_activeWindowID)
112 {
113 // Wrap around.
114 if (m_nextTabTarget == ID::Invalid() && m_firstTabTarget != ID::Invalid())
115 {
116 m_nextTabTarget = m_firstTabTarget;
117 }
118
119 if (m_prevTabTarget == ID::Invalid() && m_lastTabTarget != ID::Invalid())
120 {
121 m_prevTabTarget = m_lastTabTarget;
122 }
123 }
124
125 // Back to the window this one was made inside, whose targets continue after it.
126 if (!m_outerWindowIDs.empty())
127 {
128 m_currentWindowID = m_outerWindowIDs.back();
129 m_outerWindowIDs.pop_back();
130 }
131 }
132
133 void EndFrame()
134 {
135 if (m_currentFocusedID == ID::Invalid())
136 {
137 if (m_defaultFocusID != ID::Invalid())
138 {
139 m_prevTabTarget =
140 m_nextTabTarget = m_defaultFocusID;
141 } else
142 if (m_firstTabTarget != ID::Invalid())
143 {
144 m_prevTabTarget =
145 m_nextTabTarget = m_firstTabTarget;
146 } else
147 {
148 m_prevTabTarget =
149 m_nextTabTarget = ID::Invalid();
150 }
151 } else
152 {
153 if (m_nextTabTarget == ID::Invalid())
154 {
155 m_nextTabTarget = m_firstTabTarget;
156 }
157 }
158 }
159
160 ID GetNextTabTarget() const { return m_nextTabTarget; }
161 ID GetPrevTabTarget() const { return m_prevTabTarget; }
162 ID GetDefaultFocus() const { return m_defaultFocusID != ID::Invalid() ? m_defaultFocusID : m_firstTabTarget; }
163 };
164
166} // namespace tachyon
Owns the per-frame state objects and runs their BeginFrame / EndFrame in order.
Definition gui_state_manager.h:65
Tracks the next/prev tab targets around the focused element, rebuilt each frame during construction a...
Definition gui_tab_chain_manager.h:18
ID GetPrevTabTarget() const
Definition gui_tab_chain_manager.h:161
ID SpanFirst() const
The first and last targets of the last span; Invalid when it had none.
Definition gui_tab_chain_manager.h:105
void EndSpan()
Definition gui_tab_chain_manager.h:103
ID GetDefaultFocus() const
Definition gui_tab_chain_manager.h:162
ID SpanLast() const
Definition gui_tab_chain_manager.h:106
void BeginWindow(ID windowID)
Starts collecting windowID's tab targets until EndWindow; only the active window builds a chain.
Definition gui_tab_chain_manager.h:52
void EndWindow()
Ends the window begun by BeginWindow; its chain wraps around.
Definition gui_tab_chain_manager.h:109
void RegisterTabTarget(ID elementID)
Adds elementID to the current window's tab chain, in call order.
Definition gui_tab_chain_manager.h:64
void SetDefaultFocusID(ID defaultID)
The target Tab moves to when nothing has focus, e.g.
Definition gui_tab_chain_manager.h:45
void EndFrame()
Definition gui_tab_chain_manager.h:133
ID GetNextTabTarget() const
Definition gui_tab_chain_manager.h:160
void BeginFrame(const GUIStateManager &guiStateManager)
void BeginSpan()
Notes the first and last targets the active window registers until EndSpan, e.g.
Definition gui_tab_chain_manager.h:97
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