ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
ZenitUI::UI::Menu Class Reference

Structured floating menu built on Popup, supporting separators, shortcuts, checkable items, nested submenus, and keyboard navigation. More...

#include <MenuBar.hpp>

Inheritance diagram for ZenitUI::UI::Menu:
[legend]

Public Member Functions

 Menu (std::string title="")
const std::string & getTitle () const noexcept
void setTitle (std::string title)
void populateEntries (std::vector< MenuEntry > entries)
 Populate/append entries from MenuEntry descriptors.
std::shared_ptr< MenuItem > addItem (std::string label, std::function< void()> onTrigger=nullptr, std::string shortcut="", std::string value="")
 Append an action MenuItem and return it.
std::shared_ptr< MenuItem > addCheckItem (std::string label, bool checked, std::function< void(bool)> onToggle=nullptr, std::string shortcut="", std::string value="")
 Append a checkable MenuItem and return it.
std::shared_ptr< MenuSeparator > addSeparator ()
 Append a MenuSeparator and return it.
std::shared_ptr< MenuItem > addSubmenu (std::string label, std::vector< MenuEntry > entries={})
 Append a submenu MenuItem and return it.
void addMenuChild (std::shared_ptr< Layout > child)
 Append an existing MenuItem or MenuSeparator.
void clearItems ()
 Remove all items and close any active submenu.
std::vector< std::shared_ptr< MenuItem > > items () const
 Direct MenuItem children (excluding separators).
int getHighlightedIndex () const noexcept
 Currently highlighted item index among items(), or -1.
std::shared_ptr< Menu > activeSubmenu () const
 Currently open child submenu, or nullptr.
void openBelow (std::shared_ptr< Layout > anchor)
void openAbove (std::shared_ptr< Layout > anchor)
void openAt (Vec2 screenPos)
void close ()
void closeHierarchy ()
 Close this menu and walk up to close the root menu and MenuBar state.
Layout * contentTarget () override
Vec2 measure (float parent_w, float parent_h) override
Public Member Functions inherited from ZenitUI::TLayout< Menu, Popup >
 TLayout (Args &&...args)
 Forward constructor arguments to Base.
std::shared_ptr< Menu > cls (const std::string &name)
 Fluent addClass; returns typed shared_ptr<Derived>.
std::shared_ptr< Menu > id (const std::string &node_id)
 Fluent setId; returns typed shared_ptr<Derived>.
std::shared_ptr< Menu > withRef (const std::string &r)
 Fluent setRef; returns typed shared_ptr<Derived>.
std::shared_ptr< Menu > size (Value w, Value h)
 Fluent setSize; returns typed shared_ptr<Derived>.
std::shared_ptr< Menu > passThrough (bool p=true)
 Fluent setPassThrough; returns typed shared_ptr<Derived>.
std::shared_ptr< Menu > with (std::shared_ptr< Layout > c)
 Fluent addChild; returns typed shared_ptr<Derived>.
std::shared_ptr< Menu > self ()
 Return shared_from_this() statically cast to Derived.

Static Public Member Functions

static std::shared_ptr< Menu > fromEntries (std::vector< MenuEntry > entries, std::string title="")
 Build a Menu populated from declarative MenuEntry descriptors.
Static Public Member Functions inherited from ZenitUI::TLayout< Menu, Popup >
static std::shared_ptr< Menu > create (Args &&...args)
 Construct a shared_ptr<Derived> and call onBuild().

Public Attributes

std::function< void(std::shared_ptr< MenuItem >)> onItemTriggered
 Fired when any leaf item in this menu (or its submenus) is triggered.

Protected Member Functions

void onBuild () override
 Hook: called once after create() finishes constructing the object.
void onUpdate (float dt) override

Friends

class MenuItem
class MenuBar

Detailed Description

Structured floating menu built on Popup, supporting separators, shortcuts, checkable items, nested submenus, and keyboard navigation.

Style tag: "Menu". Can be placed inside a MenuBar or used standalone as a context menu (openAt, openBelow, openAbove).

Member Function Documentation

◆ onBuild()

void ZenitUI::UI::Menu::onBuild ( )
overrideprotectedvirtual

Hook: called once after create() finishes constructing the object.

Reimplemented from ZenitUI::TLayout< Menu, Popup >.


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