TachyonUI
0.1.0
High-performance UI for building tools.
Toggle main menu visibility
Loading...
Searching...
No Matches
gui_menu_manager.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <string>
4
5
#include <
gui_core/input/gui_input_handler_func.h
>
6
7
#include <
gui_core/gui_id.h
>
8
#include <
gui_core/gui_base_types.h
>
9
10
#include <functional>
11
#include <unordered_map>
12
#include <vector>
13
14
namespace
tachyon
15
{
18
19
class
ElementStorage
;
20
class
GUIStateManager
;
21
class
InputManager
;
22
class
IDManager
;
23
class
OSWindowManager
;
24
class
ScrollManagement
;
25
28
class
MenuManager
29
{
30
public
:
31
static
constexpr
int
kMaxDepth
= 8;
32
34
struct
Level
35
{
36
int
depth
= -1;
37
ID
windowID
=
ID::Invalid
();
38
ID
triggerID
=
ID::Invalid
();
39
ID
activeItemID
=
ID::Invalid
();
40
ID
scrollUpID
=
ID::Invalid
();
41
ID
scrollDownID
=
ID::Invalid
();
42
bool
canScrollUp
=
false
;
43
bool
canScrollDown
=
false
;
44
bool
isOpen
=
false
;
45
bool
reopened
=
false
;
47
bool
reserveIconColumn
=
false
;
48
bool
itemsHaveIcons
=
false
;
49
std::string
filter
;
51
bool
filtering
=
false
;
52
};
53
54
Level
levels
[
kMaxDepth
];
55
int
currentDepth
= -1;
56
int
maxOpenDepth
= -1;
57
bool
requestCloseAll
=
false
;
59
ID
justClosedTriggerID
=
ID::Invalid
();
60
ID
priorFocusID
=
ID::Invalid
();
61
64
int
suppressedSubmenuTriggerDepth
= -1;
65
68
bool
skipActivityCheck
=
false
;
69
70
bool
mouseHiddenForMenu
=
false
;
71
int2
lastMousePos
= {0, 0};
72
bool
focusSubmenuOnOpen
=
false
;
73
bool
navigatedThisFrame
=
false
;
74
77
std::unordered_map<ID, bool>
menuItemsHaveIcons
;
78
81
std::unordered_map<ID, ID>
popupWindowIDs
;
83
ID
PopupWindowFor
(
ID
triggerID,
IDManager
& idManager);
84
85
bool
buildingMenuBar
=
false
;
87
std::vector<ID>
menuBarTriggers
;
88
90
bool
IsMenuBarTrigger
(
ID
id
)
const
;
91
92
93
95
Level
&
GetOrCreateNextLevel
(
IDManager
& idManager);
96
97
100
void
BeginFrame
(
GUIStateManager
& guiStateManager,
OSWindowManager
& windowManager);
102
void
EndFrame
(
ElementStorage
& elementStorage,
GUIStateManager
& guiStateManager);
103
105
void
CloseFromDepth
(
int
fromDepth);
106
108
bool
IsOpen
()
const
{
return
levels
[0].
isOpen
; }
109
111
bool
IsBalanced
()
const
{
return
currentDepth
== -1; }
112
114
void
RequestCloseAll
();
115
118
void
CloseOnInputOutside
(
const
InputManager
& inputManager,
const
ElementStorage
& elementStorage,
119
GUIStateManager
& guiStateManager);
120
123
void
PrepareLevelWindow
(
Level
& level,
ScrollManagement
& scrollManagement);
126
void
OpenSubmenu
(
int
parentDepth,
ID
triggerID);
127
129
void
CloseAll
(
GUIStateManager
& guiStateManager);
130
133
void
CloseAll
(
GUIStateManager
& guiStateManager,
OSWindowManager
& windowManager);
134
137
void
ToggleOrOpenMenu
(
GUIStateManager
& guiStateManager,
ID
id
,
bool
focusIntoMenu =
true
);
140
void
OpenMenu
(
GUIStateManager
& guiStateManager,
ID
id
,
bool
focusIntoMenu =
true
);
141
144
bool
ClickMenu
(
GUIStateManager
& guiStateManager,
bool
isSubmenu,
int
depth,
ID
currentItemID, std::function<
void
()> onClick);
145
147
bool
NavigateMenuSibling
(
GUIStateManager
& guiStateManager,
ElementStorage
& elementStorage,
bool
isSubmenu,
int
depth,
ID
currentItemID,
KeyCode
key);
148
150
bool
NavigateMenuBar
(
GUIStateManager
& guiStateManager,
ID
currentTriggerID,
KeyCode
key);
151
153
void
EnterMenuFromTrigger
(
GUIStateManager
& guiStateManager,
ID
triggerID);
154
};
155
157
EventHandler
MakeMenuItemHandler
(
IDManager
& idManager,
158
GUIStateManager
& guiStateManager,
159
ElementStorage
& elementStorage,
160
MenuManager
& menuManager,
161
int
depth,
162
std::function<
void
()> onClick);
163
165
EventHandler
MakeSubmenuTriggerHandler
(
IDManager
& idManager,
166
GUIStateManager
& guiStateManager,
167
ElementStorage
& elementStorage,
168
MenuManager
& menuManager,
169
int
depth);
170
172
}
// namespace tachyon
tachyon::ElementStorage
The frame's element tree.
Definition
gui_element_storage.h:100
tachyon::GUIStateManager
Owns the per-frame state objects and runs their BeginFrame / EndFrame in order.
Definition
gui_state_manager.h:65
tachyon::IDManager
Makes element IDs: per-frame dynamic / ranged IDs (hashed from the call site or a hint and the parent...
Definition
gui_id_manager.h:27
tachyon::InputManager
Receives raw OS events, records them, and runs the frame's input pipeline (tab navigation,...
Definition
gui_input_manager.h:33
tachyon::MenuManager
State of the open menus (menu bar dropdowns, context menus, submenus) and their mouse and keyboard be...
Definition
gui_menu_manager.h:29
tachyon::MenuManager::EnterMenuFromTrigger
void EnterMenuFromTrigger(GUIStateManager &guiStateManager, ID triggerID)
Focuses the first item of the trigger's dropdown, opening it if needed.
tachyon::MenuManager::popupWindowIDs
std::unordered_map< ID, ID > popupWindowIDs
Each menu's own popup window (per trigger ID), so switching menus never shows another menu's last fra...
Definition
gui_menu_manager.h:81
tachyon::MenuManager::skipActivityCheck
bool skipActivityCheck
Set when a menu opens: skips the next BeginFrame auto-close (construction hasn't set the triggerIDs y...
Definition
gui_menu_manager.h:68
tachyon::MenuManager::BeginFrame
void BeginFrame(GUIStateManager &guiStateManager, OSWindowManager &windowManager)
Unhides the cursor on real mouse movement and closes all menus once none has an active item or a focu...
tachyon::MenuManager::ToggleOrOpenMenu
void ToggleOrOpenMenu(GUIStateManager &guiStateManager, ID id, bool focusIntoMenu=true)
Closes the root menu of trigger id when it is open, else opens it (see OpenMenu).
tachyon::MenuManager::OpenMenu
void OpenMenu(GUIStateManager &guiStateManager, ID id, bool focusIntoMenu=true)
Opens the root menu of trigger id, replacing any open menu.
tachyon::MenuManager::menuItemsHaveIcons
std::unordered_map< ID, bool > menuItemsHaveIcons
Per trigger ID: whether the menu had icons last time, so a reopen reserves the icon column on its fir...
Definition
gui_menu_manager.h:77
tachyon::MenuManager::focusSubmenuOnOpen
bool focusSubmenuOnOpen
select and focus the first item of the next opened level
Definition
gui_menu_manager.h:72
tachyon::MenuManager::PopupWindowFor
ID PopupWindowFor(ID triggerID, IDManager &idManager)
The popup window ID of triggerID's menu, created on first use.
tachyon::MenuManager::OpenSubmenu
void OpenSubmenu(int parentDepth, ID triggerID)
Opens the level below parentDepth for submenu trigger triggerID, focusing its first item.
tachyon::MenuManager::CloseFromDepth
void CloseFromDepth(int fromDepth)
Closes level fromDepth and every level below it; window IDs are kept for reuse.
tachyon::MenuManager::RequestCloseAll
void RequestCloseAll()
Closes all menus once construction is back outside them (in the outermost EndMenu).
tachyon::MenuManager::IsOpen
bool IsOpen() const
True while the root menu is open.
Definition
gui_menu_manager.h:108
tachyon::MenuManager::currentDepth
int currentDepth
Definition
gui_menu_manager.h:55
tachyon::MenuManager::CloseAll
void CloseAll(GUIStateManager &guiStateManager, OSWindowManager &windowManager)
As CloseAll(), and also hides the OS windows at once, for when the frame loop isn't running (such as ...
tachyon::MenuManager::PrepareLevelWindow
void PrepareLevelWindow(Level &level, ScrollManagement &scrollManagement)
Call before BeginWindow(level.windowID): a reopened level starts at the top (its window ID,...
tachyon::MenuManager::kMaxDepth
static constexpr int kMaxDepth
deepest submenu nesting, root included
Definition
gui_menu_manager.h:31
tachyon::MenuManager::menuBarTriggers
std::vector< ID > menuBarTriggers
Menu-bar triggers in order, registered during construction for Left/Right navigation.
Definition
gui_menu_manager.h:87
tachyon::MenuManager::suppressedSubmenuTriggerDepth
int suppressedSubmenuTriggerDepth
Depth of a submenu the Left key closed; it doesn't auto-reopen until the parent's activeItemID change...
Definition
gui_menu_manager.h:64
tachyon::MenuManager::IsBalanced
bool IsBalanced() const
True iff every BeginMenu was matched by EndMenu.
Definition
gui_menu_manager.h:111
tachyon::MenuManager::buildingMenuBar
bool buildingMenuBar
true while a menu bar is being built
Definition
gui_menu_manager.h:85
tachyon::MenuManager::CloseOnInputOutside
void CloseOnInputOutside(const InputManager &inputManager, const ElementStorage &elementStorage, GUIStateManager &guiStateManager)
Closes all menus on a press or scroll this frame outside them and the open menu's trigger (which togg...
tachyon::MenuManager::priorFocusID
ID priorFocusID
focus to restore when all menus close
Definition
gui_menu_manager.h:60
tachyon::MenuManager::GetOrCreateNextLevel
Level & GetOrCreateNextLevel(IDManager &idManager)
The level below currentDepth, with a window ID assigned on first use.
tachyon::MenuManager::ClickMenu
bool ClickMenu(GUIStateManager &guiStateManager, bool isSubmenu, int depth, ID currentItemID, std::function< void()> onClick)
Activates item currentItemID at depth: runs onClick and closes all menus, or for a submenu trigger (i...
tachyon::MenuManager::requestCloseAll
bool requestCloseAll
Definition
gui_menu_manager.h:57
tachyon::MenuManager::EndFrame
void EndFrame(ElementStorage &elementStorage, GUIStateManager &guiStateManager)
Updates the scroll indicators from this frame's layout.
tachyon::MenuManager::maxOpenDepth
int maxOpenDepth
Definition
gui_menu_manager.h:56
tachyon::MenuManager::CloseAll
void CloseAll(GUIStateManager &guiStateManager)
Closes all menus and restores prior focus (the only place that does).
tachyon::MenuManager::mouseHiddenForMenu
bool mouseHiddenForMenu
set by keyboard nav, cleared on mouse move
Definition
gui_menu_manager.h:70
tachyon::MenuManager::NavigateMenuBar
bool NavigateMenuBar(GUIStateManager &guiStateManager, ID currentTriggerID, KeyCode key)
Left/Right between menu-bar triggers; an open dropdown follows. True if handled.
tachyon::MenuManager::lastMousePos
int2 lastMousePos
to detect real mouse movement
Definition
gui_menu_manager.h:71
tachyon::MenuManager::levels
Level levels[kMaxDepth]
Definition
gui_menu_manager.h:54
tachyon::MenuManager::IsMenuBarTrigger
bool IsMenuBarTrigger(ID id) const
True iff id was registered as a menu-bar trigger this frame.
tachyon::MenuManager::navigatedThisFrame
bool navigatedThisFrame
throttle: at most one Up/Down navigation per frame
Definition
gui_menu_manager.h:73
tachyon::MenuManager::justClosedTriggerID
ID justClosedTriggerID
Trigger whose menu closed this frame; its own click doesn't reopen it.
Definition
gui_menu_manager.h:59
tachyon::MenuManager::NavigateMenuSibling
bool NavigateMenuSibling(GUIStateManager &guiStateManager, ElementStorage &elementStorage, bool isSubmenu, int depth, ID currentItemID, KeyCode key)
Handles Escape, Left/Right or Up/Down key on item currentItemID at depth. True if handled.
tachyon::OSWindowManager
Keeps the OS windows (through an IWindowBackend) and their window contexts for the GUI's window eleme...
Definition
gui_os_window_manager.h:61
tachyon::ScrollManagement
Scroll containers' offsets (pixels), kept across frames by ID behind handles.
Definition
gui_scroll_management.h:33
tachyon::MakeSubmenuTriggerHandler
EventHandler MakeSubmenuTriggerHandler(IDManager &idManager, GUIStateManager &guiStateManager, ElementStorage &elementStorage, MenuManager &menuManager, int depth)
Like MakeMenuItemHandler, but Right arrow or activation opens a submenu instead of closing.
tachyon::MakeMenuItemHandler
EventHandler MakeMenuItemHandler(IDManager &idManager, GUIStateManager &guiStateManager, ElementStorage &elementStorage, MenuManager &menuManager, int depth, std::function< void()> onClick)
Menu item event handler - fires the onClick callback on click/activation.
tachyon::KeyCode
KeyCode
Keys by what the keyboard layout makes them, not by position.
Definition
gui_input_enums.h:106
tachyon::EventHandler
std::function< bool(ElementEvent &&input)> EventHandler
Element-level input handler used by the immediate-mode dispatcher; returns true when it consumed the ...
Definition
gui_input_handler_func.h:35
gui_base_types.h
gui_id.h
gui_input_handler_func.h
tachyon
Definition
gui_logging.h:24
tachyon::ID
A 64-bit element ID whose bit layout depends on its IDMode.
Definition
gui_id.h:23
tachyon::ID::Invalid
static constexpr ID Invalid()
The "no element" ID (all bits zero); also the default for optional ID parameters.
Definition
gui_id.h:66
tachyon::MenuManager::Level
One open menu: the root dropdown or a submenu.
Definition
gui_menu_manager.h:35
tachyon::MenuManager::Level::canScrollUp
bool canScrollUp
from last frame's layout
Definition
gui_menu_manager.h:42
tachyon::MenuManager::Level::scrollUpID
ID scrollUpID
pre-allocated each frame for stable dynamic IDs
Definition
gui_menu_manager.h:40
tachyon::MenuManager::Level::filter
std::string filter
MenuFilter's text; cleared when the menu closes.
Definition
gui_menu_manager.h:49
tachyon::MenuManager::Level::scrollDownID
ID scrollDownID
Definition
gui_menu_manager.h:41
tachyon::MenuManager::Level::depth
int depth
root is 0, each submenu level adds 1
Definition
gui_menu_manager.h:36
tachyon::MenuManager::Level::windowID
ID windowID
Definition
gui_menu_manager.h:37
tachyon::MenuManager::Level::reserveIconColumn
bool reserveIconColumn
This frame: reserve the icon slot (from last frame's content).
Definition
gui_menu_manager.h:47
tachyon::MenuManager::Level::activeItemID
ID activeItemID
highlighted item (mouse or keyboard)
Definition
gui_menu_manager.h:39
tachyon::MenuManager::Level::itemsHaveIcons
bool itemsHaveIcons
this frame: accumulated as items with icons are added
Definition
gui_menu_manager.h:48
tachyon::MenuManager::Level::reopened
bool reopened
closed since last shown: start scrolled to the top
Definition
gui_menu_manager.h:45
tachyon::MenuManager::Level::canScrollDown
bool canScrollDown
from last frame's layout
Definition
gui_menu_manager.h:43
tachyon::MenuManager::Level::filtering
bool filtering
This frame: MenuFilter holds text, so items not matching it hide.
Definition
gui_menu_manager.h:51
tachyon::MenuManager::Level::triggerID
ID triggerID
Definition
gui_menu_manager.h:38
tachyon::MenuManager::Level::isOpen
bool isOpen
Definition
gui_menu_manager.h:44
tachyon::int2
Integer 2D vector.
Definition
gui_base_types.h:19
gui_controls
gui_menu_manager.h
Generated by
1.18.0