TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_menu_manager.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4
6
7#include <gui_core/gui_id.h>
9
10#include <functional>
11#include <unordered_map>
12#include <vector>
13
14namespace tachyon
15{
18
19 class ElementStorage;
20 class GUIStateManager;
21 class InputManager;
22 class IDManager;
23 class OSWindowManager;
24 class ScrollManagement;
25
29 {
30 public:
31 static constexpr int kMaxDepth = 8;
32
34 struct Level
35 {
36 int depth = -1;
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
55 int currentDepth = -1;
56 int maxOpenDepth = -1;
57 bool requestCloseAll = false;
61
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
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
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
158 GUIStateManager& guiStateManager,
159 ElementStorage& elementStorage,
160 MenuManager& menuManager,
161 int depth,
162 std::function<void()> onClick);
163
166 GUIStateManager& guiStateManager,
167 ElementStorage& elementStorage,
168 MenuManager& menuManager,
169 int depth);
170
172} // namespace tachyon
The frame's element tree.
Definition gui_element_storage.h:100
Owns the per-frame state objects and runs their BeginFrame / EndFrame in order.
Definition gui_state_manager.h:65
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
Receives raw OS events, records them, and runs the frame's input pipeline (tab navigation,...
Definition gui_input_manager.h:33
State of the open menus (menu bar dropdowns, context menus, submenus) and their mouse and keyboard be...
Definition gui_menu_manager.h:29
void EnterMenuFromTrigger(GUIStateManager &guiStateManager, ID triggerID)
Focuses the first item of the trigger's dropdown, opening it if needed.
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
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
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...
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).
void OpenMenu(GUIStateManager &guiStateManager, ID id, bool focusIntoMenu=true)
Opens the root menu of trigger id, replacing any open menu.
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
bool focusSubmenuOnOpen
select and focus the first item of the next opened level
Definition gui_menu_manager.h:72
ID PopupWindowFor(ID triggerID, IDManager &idManager)
The popup window ID of triggerID's menu, created on first use.
void OpenSubmenu(int parentDepth, ID triggerID)
Opens the level below parentDepth for submenu trigger triggerID, focusing its first item.
void CloseFromDepth(int fromDepth)
Closes level fromDepth and every level below it; window IDs are kept for reuse.
void RequestCloseAll()
Closes all menus once construction is back outside them (in the outermost EndMenu).
bool IsOpen() const
True while the root menu is open.
Definition gui_menu_manager.h:108
int currentDepth
Definition gui_menu_manager.h:55
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 ...
void PrepareLevelWindow(Level &level, ScrollManagement &scrollManagement)
Call before BeginWindow(level.windowID): a reopened level starts at the top (its window ID,...
static constexpr int kMaxDepth
deepest submenu nesting, root included
Definition gui_menu_manager.h:31
std::vector< ID > menuBarTriggers
Menu-bar triggers in order, registered during construction for Left/Right navigation.
Definition gui_menu_manager.h:87
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
bool IsBalanced() const
True iff every BeginMenu was matched by EndMenu.
Definition gui_menu_manager.h:111
bool buildingMenuBar
true while a menu bar is being built
Definition gui_menu_manager.h:85
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...
ID priorFocusID
focus to restore when all menus close
Definition gui_menu_manager.h:60
Level & GetOrCreateNextLevel(IDManager &idManager)
The level below currentDepth, with a window ID assigned on first use.
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...
bool requestCloseAll
Definition gui_menu_manager.h:57
void EndFrame(ElementStorage &elementStorage, GUIStateManager &guiStateManager)
Updates the scroll indicators from this frame's layout.
int maxOpenDepth
Definition gui_menu_manager.h:56
void CloseAll(GUIStateManager &guiStateManager)
Closes all menus and restores prior focus (the only place that does).
bool mouseHiddenForMenu
set by keyboard nav, cleared on mouse move
Definition gui_menu_manager.h:70
bool NavigateMenuBar(GUIStateManager &guiStateManager, ID currentTriggerID, KeyCode key)
Left/Right between menu-bar triggers; an open dropdown follows. True if handled.
int2 lastMousePos
to detect real mouse movement
Definition gui_menu_manager.h:71
Level levels[kMaxDepth]
Definition gui_menu_manager.h:54
bool IsMenuBarTrigger(ID id) const
True iff id was registered as a menu-bar trigger this frame.
bool navigatedThisFrame
throttle: at most one Up/Down navigation per frame
Definition gui_menu_manager.h:73
ID justClosedTriggerID
Trigger whose menu closed this frame; its own click doesn't reopen it.
Definition gui_menu_manager.h:59
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.
Keeps the OS windows (through an IWindowBackend) and their window contexts for the GUI's window eleme...
Definition gui_os_window_manager.h:61
Scroll containers' offsets (pixels), kept across frames by ID behind handles.
Definition gui_scroll_management.h:33
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.
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.
KeyCode
Keys by what the keyboard layout makes them, not by position.
Definition gui_input_enums.h:106
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
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
One open menu: the root dropdown or a submenu.
Definition gui_menu_manager.h:35
bool canScrollUp
from last frame's layout
Definition gui_menu_manager.h:42
ID scrollUpID
pre-allocated each frame for stable dynamic IDs
Definition gui_menu_manager.h:40
std::string filter
MenuFilter's text; cleared when the menu closes.
Definition gui_menu_manager.h:49
ID scrollDownID
Definition gui_menu_manager.h:41
int depth
root is 0, each submenu level adds 1
Definition gui_menu_manager.h:36
ID windowID
Definition gui_menu_manager.h:37
bool reserveIconColumn
This frame: reserve the icon slot (from last frame's content).
Definition gui_menu_manager.h:47
ID activeItemID
highlighted item (mouse or keyboard)
Definition gui_menu_manager.h:39
bool itemsHaveIcons
this frame: accumulated as items with icons are added
Definition gui_menu_manager.h:48
bool reopened
closed since last shown: start scrolled to the top
Definition gui_menu_manager.h:45
bool canScrollDown
from last frame's layout
Definition gui_menu_manager.h:43
bool filtering
This frame: MenuFilter holds text, so items not matching it hide.
Definition gui_menu_manager.h:51
ID triggerID
Definition gui_menu_manager.h:38
bool isOpen
Definition gui_menu_manager.h:44
Integer 2D vector.
Definition gui_base_types.h:19