TachyonUI 0.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
35 public:
36 void BeginFrame(const GUIStateManager& guiStateManager);
37
40 void SetDefaultFocusID(ID defaultID)
41 {
42 m_defaultFocusID = defaultID;
43 }
44
47 void BeginWindow(ID windowID)
48 {
49 m_outerWindowIDs.push_back(m_currentWindowID);
50 m_currentWindowID = windowID;
51 if (m_currentWindowID == m_activeWindowID)
52 {
53 m_firstTabTarget = ID::Invalid();
54 m_lastTabTarget = ID::Invalid();
55 }
56 }
57
59 void RegisterTabTarget(ID elementID)
60 {
61 // Only the active window gets a tab chain.
62 if (m_currentWindowID != m_activeWindowID)
63 return;
64
65 if (m_firstTabTarget == ID::Invalid())
66 {
67 m_firstTabTarget = elementID;
68 }
69
70 if (m_lastTabTarget == m_currentFocusedID)
71 {
72 m_nextTabTarget = elementID;
73 }
74
75 if (elementID == m_currentFocusedID)
76 {
77 m_prevTabTarget = m_lastTabTarget;
78 }
79
80 m_lastTabTarget = elementID;
81 }
82
84 void EndWindow()
85 {
86 if (m_currentWindowID == m_activeWindowID)
87 {
88 // Wrap around.
89 if (m_nextTabTarget == ID::Invalid() && m_firstTabTarget != ID::Invalid())
90 {
91 m_nextTabTarget = m_firstTabTarget;
92 }
93
94 if (m_prevTabTarget == ID::Invalid() && m_lastTabTarget != ID::Invalid())
95 {
96 m_prevTabTarget = m_lastTabTarget;
97 }
98 }
99
100 // Back to the window this one was made inside, whose targets continue after it.
101 if (!m_outerWindowIDs.empty())
102 {
103 m_currentWindowID = m_outerWindowIDs.back();
104 m_outerWindowIDs.pop_back();
105 }
106 }
107
108 void EndFrame()
109 {
110 if (m_currentFocusedID == ID::Invalid())
111 {
112 if (m_defaultFocusID != ID::Invalid())
113 {
114 m_prevTabTarget =
115 m_nextTabTarget = m_defaultFocusID;
116 } else
117 if (m_firstTabTarget != ID::Invalid())
118 {
119 m_prevTabTarget =
120 m_nextTabTarget = m_firstTabTarget;
121 } else
122 {
123 m_prevTabTarget =
124 m_nextTabTarget = ID::Invalid();
125 }
126 } else
127 {
128 if (m_nextTabTarget == ID::Invalid())
129 {
130 m_nextTabTarget = m_firstTabTarget;
131 }
132 }
133 }
134
135 ID GetNextTabTarget() const { return m_nextTabTarget; }
136 ID GetPrevTabTarget() const { return m_prevTabTarget; }
137 ID GetDefaultFocus() const { return m_defaultFocusID != ID::Invalid() ? m_defaultFocusID : m_firstTabTarget; }
138 };
139
141} // 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:136
ID GetDefaultFocus() const
Definition gui_tab_chain_manager.h:137
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:47
void EndWindow()
Ends the window begun by BeginWindow; its chain wraps around.
Definition gui_tab_chain_manager.h:84
void RegisterTabTarget(ID elementID)
Adds elementID to the current window's tab chain, in call order.
Definition gui_tab_chain_manager.h:59
void SetDefaultFocusID(ID defaultID)
The target Tab moves to when nothing has focus, e.g.
Definition gui_tab_chain_manager.h:40
void EndFrame()
Definition gui_tab_chain_manager.h:108
ID GetNextTabTarget() const
Definition gui_tab_chain_manager.h:135
void BeginFrame(const GUIStateManager &guiStateManager)
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