yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::editor::MenuBuilder Class Reference

Fluent interface for building ImGui menus with icons. More...

#include <menu_builder.h>

Collaboration diagram for yaze::editor::MenuBuilder:

Classes

struct  Menu
 
struct  MenuItem
 

Public Types

using Callback = std::function<void()>
 
using EnabledCheck = std::function<bool()>
 

Public Member Functions

 MenuBuilder ()=default
 
MenuBuilder & BeginMenu (const char *label, const char *icon=nullptr)
 Begin a top-level menu.
 
MenuBuilder & BeginSubMenu (const char *label, const char *icon=nullptr, EnabledCheck enabled=nullptr)
 Begin a submenu.
 
MenuBuilder & EndMenu ()
 End the current menu/submenu.
 
MenuBuilder & Item (const char *label, const char *icon, Callback callback, const char *shortcut=nullptr, EnabledCheck enabled=nullptr, EnabledCheck checked=nullptr)
 Add a menu item.
 
MenuBuilder & Item (const char *label, Callback callback, const char *shortcut=nullptr, EnabledCheck enabled=nullptr)
 Add a menu item without icon (convenience)
 
MenuBuilder & Separator ()
 Add a separator.
 
MenuBuilder & DisabledItem (const char *label, const char *icon=nullptr)
 Add a disabled item (grayed out)
 
MenuBuilder & CustomMenu (const char *label, Callback draw_callback)
 Add a custom menu with a callback for drawing dynamic content.
 
MenuBuilder & CustomItems (Callback draw_callback)
 Add items drawn by a callback inside the current menu.
 
void Draw ()
 Draw the menu bar (call in main menu bar)
 
void Clear ()
 Clear all menus.
 

Private Member Functions

void DrawMenuItem (const MenuItem &item)
 

Private Attributes

std::vector< Menu > menus_
 
Menu * current_menu_ = nullptr
 
std::vector< bool > submenu_stack_
 
int skip_depth_
 

Friends

class ProjectUiTestPeer
 

Detailed Description

Fluent interface for building ImGui menus with icons.

Provides a cleaner, more maintainable way to construct menus:

MenuBuilder menu; menu.BeginMenu("File", ICON_MD_FOLDER) .Item("Open", ICON_MD_FILE_OPEN, []() { OpenFile(); }) .Separator() .Item("Quit", ICON_MD_EXIT_TO_APP, []() { Quit(); }) .EndMenu();

Definition at line 34 of file menu_builder.h.

Member Typedef Documentation

◆ Callback

using yaze::editor::MenuBuilder::Callback = std::function<void()>

Definition at line 38 of file menu_builder.h.

◆ EnabledCheck

using yaze::editor::MenuBuilder::EnabledCheck = std::function<bool()>

Definition at line 39 of file menu_builder.h.

Constructor & Destructor Documentation

◆ MenuBuilder()

yaze::editor::MenuBuilder::MenuBuilder ( )
default

Member Function Documentation

◆ BeginMenu()

◆ BeginSubMenu()

◆ EndMenu()

◆ Item() [1/2]

◆ Item() [2/2]

MenuBuilder & yaze::editor::MenuBuilder::Item ( const char * label,
Callback callback,
const char * shortcut = nullptr,
EnabledCheck enabled = nullptr )

Add a menu item without icon (convenience)

Definition at line 93 of file menu_builder.cc.

References yaze::editor::Item.

◆ Separator()

◆ DisabledItem()

◆ CustomMenu()

MenuBuilder & yaze::editor::MenuBuilder::CustomMenu ( const char * label,
Callback draw_callback )

Add a custom menu with a callback for drawing dynamic content.

Use this for menus that need dynamic/runtime-generated content. The callback is responsible for drawing menu items using ImGui directly.

Definition at line 122 of file menu_builder.cc.

References current_menu_, yaze::editor::MenuBuilder::Menu::custom_draw, yaze::editor::MenuBuilder::Menu::is_custom, yaze::editor::MenuBuilder::Menu::label, and menus_.

Referenced by yaze::editor::MenuOrchestrator::BuildEditorMenu(), and yaze::editor::MenuOrchestrator::BuildPanelsMenu().

◆ CustomItems()

MenuBuilder & yaze::editor::MenuBuilder::CustomItems ( Callback draw_callback)

Add items drawn by a callback inside the current menu.

The callback runs where the item sits, inside the open menu scope, and draws its own ImGui menu items (or nothing).

Definition at line 133 of file menu_builder.cc.

References yaze::editor::MenuBuilder::MenuItem::callback, current_menu_, yaze::editor::MenuBuilder::Menu::items, yaze::editor::MenuBuilder::MenuItem::kCustom, and yaze::editor::MenuBuilder::MenuItem::type.

Referenced by yaze::editor::MenuOrchestrator::AddEditMenuItems().

◆ Draw()

void yaze::editor::MenuBuilder::Draw ( )

Draw the menu bar (call in main menu bar)

Definition at line 144 of file menu_builder.cc.

References DrawMenuItem(), yaze::gui::WidgetIdRegistry::Instance(), menus_, yaze::gui::WidgetIdRegistry::RegisterWidget(), skip_depth_, and submenu_stack_.

Referenced by yaze::editor::MenuOrchestrator::BuildMainMenu().

Here is the call graph for this function:

◆ Clear()

void yaze::editor::MenuBuilder::Clear ( )

Clear all menus.

Definition at line 276 of file menu_builder.cc.

References current_menu_, and menus_.

◆ DrawMenuItem()

Friends And Related Symbol Documentation

◆ ProjectUiTestPeer

friend class ProjectUiTestPeer
friend

Definition at line 35 of file menu_builder.h.

Member Data Documentation

◆ menus_

std::vector<Menu> yaze::editor::MenuBuilder::menus_
private

Definition at line 138 of file menu_builder.h.

Referenced by BeginMenu(), Clear(), CustomMenu(), and Draw().

◆ current_menu_

Menu* yaze::editor::MenuBuilder::current_menu_ = nullptr
private

◆ submenu_stack_

std::vector<bool> yaze::editor::MenuBuilder::submenu_stack_
mutableprivate

Definition at line 142 of file menu_builder.h.

Referenced by Draw(), and DrawMenuItem().

◆ skip_depth_

int yaze::editor::MenuBuilder::skip_depth_
mutableprivate
Initial value:
=
0

Definition at line 143 of file menu_builder.h.

Referenced by Draw(), and DrawMenuItem().


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