TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
tachyon::MenuManager Class Reference

State of the open menus (menu bar dropdowns, context menus, submenus) and their mouse and keyboard behaviour; one per application. More...

#include <gui_controls/gui_menu_manager.h>

Classes

struct  Level
 One open menu: the root dropdown or a submenu. More...

Public Member Functions

ID PopupWindowFor (ID triggerID, IDManager &idManager)
 The popup window ID of triggerID's menu, created on first use.
bool IsMenuBarTrigger (ID id) const
 True iff id was registered as a menu-bar trigger this frame.
Level & GetOrCreateNextLevel (IDManager &idManager)
 The level below currentDepth, with a window ID assigned on first use.
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 focused trigger.
void EndFrame (ElementStorage &elementStorage, GUIStateManager &guiStateManager)
 Updates the scroll indicators from this frame's layout.
void CloseFromDepth (int fromDepth)
 Closes level fromDepth and every level below it; window IDs are kept for reuse.
bool IsOpen () const
 True while the root menu is open.
bool IsBalanced () const
 True iff every BeginMenu was matched by EndMenu.
void RequestCloseAll ()
 Closes all menus once construction is back outside them (in the outermost EndMenu).
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 toggles it itself).
void PrepareLevelWindow (Level &level, ScrollManagement &scrollManagement)
 Call before BeginWindow(level.windowID): a reopened level starts at the top (its window ID, and so its scroll offset, persists across close/reopen).
void OpenSubmenu (int parentDepth, ID triggerID)
 Opens the level below parentDepth for submenu trigger triggerID, focusing its first item.
void CloseAll (GUIStateManager &guiStateManager)
 Closes all menus and restores prior focus (the only place that does).
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 during the OS modal move/resize loop).
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.
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 (isSubmenu) opens its submenu.
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.
bool NavigateMenuBar (GUIStateManager &guiStateManager, ID currentTriggerID, KeyCode key)
 Left/Right between menu-bar triggers; an open dropdown follows. True if handled.
void EnterMenuFromTrigger (GUIStateManager &guiStateManager, ID triggerID)
 Focuses the first item of the trigger's dropdown, opening it if needed.

Public Attributes

Level levels [kMaxDepth]
int currentDepth = -1
int maxOpenDepth = -1
bool requestCloseAll = false
ID justClosedTriggerID = ID::Invalid()
 Trigger whose menu closed this frame; its own click doesn't reopen it.
ID priorFocusID = ID::Invalid()
 focus to restore when all menus close
int suppressedSubmenuTriggerDepth = -1
 Depth of a submenu the Left key closed; it doesn't auto-reopen until the parent's activeItemID changes.
bool skipActivityCheck = false
 Set when a menu opens: skips the next BeginFrame auto-close (construction hasn't set the triggerIDs yet) and CloseOnInputOutside for the input that opened it.
bool mouseHiddenForMenu = false
 set by keyboard nav, cleared on mouse move
int2 lastMousePos = {0, 0}
 to detect real mouse movement
bool focusSubmenuOnOpen = false
 select and focus the first item of the next opened level
bool navigatedThisFrame = false
 throttle: at most one Up/Down navigation per frame
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 first frame.
std::unordered_map< ID, ID > popupWindowIDs
 Each menu's own popup window (per trigger ID), so switching menus never shows another menu's last frame while the new one renders.
bool buildingMenuBar = false
 true while a menu bar is being built
std::vector< ID > menuBarTriggers
 Menu-bar triggers in order, registered during construction for Left/Right navigation.

Static Public Attributes

static constexpr int kMaxDepth = 8
 deepest submenu nesting, root included

Detailed Description

State of the open menus (menu bar dropdowns, context menus, submenus) and their mouse and keyboard behaviour; one per application.

Member Function Documentation

◆ PopupWindowFor()

ID tachyon::MenuManager::PopupWindowFor ( ID triggerID,
IDManager & idManager )

The popup window ID of triggerID's menu, created on first use.

◆ IsMenuBarTrigger()

bool tachyon::MenuManager::IsMenuBarTrigger ( ID id) const

True iff id was registered as a menu-bar trigger this frame.

◆ GetOrCreateNextLevel()

Level & tachyon::MenuManager::GetOrCreateNextLevel ( IDManager & idManager)

The level below currentDepth, with a window ID assigned on first use.

◆ BeginFrame()

void tachyon::MenuManager::BeginFrame ( GUIStateManager & guiStateManager,
OSWindowManager & windowManager )

Unhides the cursor on real mouse movement and closes all menus once none has an active item or a focused trigger.

◆ EndFrame()

void tachyon::MenuManager::EndFrame ( ElementStorage & elementStorage,
GUIStateManager & guiStateManager )

Updates the scroll indicators from this frame's layout.

◆ CloseFromDepth()

void tachyon::MenuManager::CloseFromDepth ( int fromDepth)

Closes level fromDepth and every level below it; window IDs are kept for reuse.

◆ IsOpen()

bool tachyon::MenuManager::IsOpen ( ) const
inline

True while the root menu is open.

◆ IsBalanced()

bool tachyon::MenuManager::IsBalanced ( ) const
inline

True iff every BeginMenu was matched by EndMenu.

◆ RequestCloseAll()

void tachyon::MenuManager::RequestCloseAll ( )

Closes all menus once construction is back outside them (in the outermost EndMenu).

◆ CloseOnInputOutside()

void tachyon::MenuManager::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 toggles it itself).

Call before the input is dispatched.

◆ PrepareLevelWindow()

void tachyon::MenuManager::PrepareLevelWindow ( Level & level,
ScrollManagement & scrollManagement )

Call before BeginWindow(level.windowID): a reopened level starts at the top (its window ID, and so its scroll offset, persists across close/reopen).

◆ OpenSubmenu()

void tachyon::MenuManager::OpenSubmenu ( int parentDepth,
ID triggerID )

Opens the level below parentDepth for submenu trigger triggerID, focusing its first item.

◆ CloseAll() [1/2]

void tachyon::MenuManager::CloseAll ( GUIStateManager & guiStateManager)

Closes all menus and restores prior focus (the only place that does).

◆ CloseAll() [2/2]

void tachyon::MenuManager::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 during the OS modal move/resize loop).

◆ ToggleOrOpenMenu()

void tachyon::MenuManager::ToggleOrOpenMenu ( GUIStateManager & guiStateManager,
ID id,
bool focusIntoMenu = true )

Closes the root menu of trigger id when it is open, else opens it (see OpenMenu).

Does nothing for the trigger whose menu closed this frame.

◆ OpenMenu()

void tachyon::MenuManager::OpenMenu ( GUIStateManager & guiStateManager,
ID id,
bool focusIntoMenu = true )

Opens the root menu of trigger id, replacing any open menu.

focusIntoMenu focuses the first item (context menus, dropdowns); false keeps focus on the trigger (menu bar).

◆ ClickMenu()

bool tachyon::MenuManager::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 (isSubmenu) opens its submenu.

Returns true.

◆ NavigateMenuSibling()

bool tachyon::MenuManager::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.

◆ NavigateMenuBar()

bool tachyon::MenuManager::NavigateMenuBar ( GUIStateManager & guiStateManager,
ID currentTriggerID,
KeyCode key )

Left/Right between menu-bar triggers; an open dropdown follows. True if handled.

◆ EnterMenuFromTrigger()

void tachyon::MenuManager::EnterMenuFromTrigger ( GUIStateManager & guiStateManager,
ID triggerID )

Focuses the first item of the trigger's dropdown, opening it if needed.

Member Data Documentation

◆ kMaxDepth

int tachyon::MenuManager::kMaxDepth = 8
staticconstexpr

deepest submenu nesting, root included

◆ levels

Level tachyon::MenuManager::levels[kMaxDepth]

◆ currentDepth

int tachyon::MenuManager::currentDepth = -1

◆ maxOpenDepth

int tachyon::MenuManager::maxOpenDepth = -1

◆ requestCloseAll

bool tachyon::MenuManager::requestCloseAll = false

◆ justClosedTriggerID

ID tachyon::MenuManager::justClosedTriggerID = ID::Invalid()

Trigger whose menu closed this frame; its own click doesn't reopen it.

◆ priorFocusID

ID tachyon::MenuManager::priorFocusID = ID::Invalid()

focus to restore when all menus close

◆ suppressedSubmenuTriggerDepth

int tachyon::MenuManager::suppressedSubmenuTriggerDepth = -1

Depth of a submenu the Left key closed; it doesn't auto-reopen until the parent's activeItemID changes.

-1 = none.

◆ skipActivityCheck

bool tachyon::MenuManager::skipActivityCheck = false

Set when a menu opens: skips the next BeginFrame auto-close (construction hasn't set the triggerIDs yet) and CloseOnInputOutside for the input that opened it.

◆ mouseHiddenForMenu

bool tachyon::MenuManager::mouseHiddenForMenu = false

set by keyboard nav, cleared on mouse move

◆ lastMousePos

int2 tachyon::MenuManager::lastMousePos = {0, 0}

to detect real mouse movement

◆ focusSubmenuOnOpen

bool tachyon::MenuManager::focusSubmenuOnOpen = false

select and focus the first item of the next opened level

◆ navigatedThisFrame

bool tachyon::MenuManager::navigatedThisFrame = false

throttle: at most one Up/Down navigation per frame

◆ menuItemsHaveIcons

std::unordered_map<ID, bool> tachyon::MenuManager::menuItemsHaveIcons

Per trigger ID: whether the menu had icons last time, so a reopen reserves the icon column on its first frame.

◆ popupWindowIDs

std::unordered_map<ID, ID> tachyon::MenuManager::popupWindowIDs

Each menu's own popup window (per trigger ID), so switching menus never shows another menu's last frame while the new one renders.

◆ buildingMenuBar

bool tachyon::MenuManager::buildingMenuBar = false

true while a menu bar is being built

◆ menuBarTriggers

std::vector<ID> tachyon::MenuManager::menuBarTriggers

Menu-bar triggers in order, registered during construction for Left/Right navigation.


The documentation for this class was generated from the following file: