yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
menu_builder.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_UI_MENU_BUILDER_H_
2#define YAZE_APP_EDITOR_UI_MENU_BUILDER_H_
3
4#include <functional>
5#include <string>
6#include <vector>
7
8// Must define before including imgui.h
9#ifndef IMGUI_DEFINE_MATH_OPERATORS
10#define IMGUI_DEFINE_MATH_OPERATORS
11#endif
12
13#include "app/gui/icons.h"
14#include "imgui/imgui.h"
15
16namespace yaze {
17namespace editor {
18
33 public:
34 using Callback = std::function<void()>;
35 using EnabledCheck = std::function<bool()>;
36
37 MenuBuilder() = default;
38
42 MenuBuilder& BeginMenu(const char* label, const char* icon = nullptr);
43
47 MenuBuilder& BeginSubMenu(const char* label, const char* icon = nullptr,
48 EnabledCheck enabled = nullptr);
49
54
58 MenuBuilder& Item(const char* label, const char* icon, Callback callback,
59 const char* shortcut = nullptr,
60 EnabledCheck enabled = nullptr,
61 EnabledCheck checked = nullptr);
62
66 MenuBuilder& Item(const char* label, Callback callback,
67 const char* shortcut = nullptr,
68 EnabledCheck enabled = nullptr);
69
74
78 MenuBuilder& DisabledItem(const char* label, const char* icon = nullptr);
79
83 void Draw();
84
88 void Clear();
89
90 private:
91 struct MenuItem {
92 enum class Type {
93 kItem,
98 };
99
101 std::string label;
102 std::string icon;
103 std::string shortcut;
107 };
108
109 struct Menu {
110 std::string label;
111 std::string icon;
112 std::vector<MenuItem> items;
113 };
114
115 std::vector<Menu> menus_;
116 Menu* current_menu_ = nullptr;
117
118 // Track which submenus are actually open during drawing
119 mutable std::vector<bool> submenu_stack_;
120 mutable int skip_depth_ = 0; // Track nesting depth when skipping closed submenus
121
122 void DrawMenuItem(const MenuItem& item);
123};
124
125} // namespace editor
126} // namespace yaze
127
128#endif // YAZE_APP_EDITOR_UI_MENU_BUILDER_H_
Fluent interface for building ImGui menus with icons.
MenuBuilder & Item(const char *label, const char *icon, Callback callback, const char *shortcut=nullptr, EnabledCheck enabled=nullptr, EnabledCheck checked=nullptr)
Add a menu item.
void Draw()
Draw the menu bar (call in main menu bar)
void Clear()
Clear all menus.
std::function< bool()> EnabledCheck
MenuBuilder & BeginMenu(const char *label, const char *icon=nullptr)
Begin a top-level menu.
MenuBuilder & Separator()
Add a separator.
MenuBuilder & EndMenu()
End the current menu/submenu.
MenuBuilder & BeginSubMenu(const char *label, const char *icon=nullptr, EnabledCheck enabled=nullptr)
Begin a submenu.
std::function< void()> Callback
void DrawMenuItem(const MenuItem &item)
std::vector< Menu > menus_
MenuBuilder & DisabledItem(const char *label, const char *icon=nullptr)
Add a disabled item (grayed out)
std::vector< bool > submenu_stack_
Main namespace for the application.
std::vector< MenuItem > items