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_MENU_MENU_BUILDER_H_
2#define YAZE_APP_EDITOR_MENU_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 "absl/container/flat_hash_map.h"
14#include "absl/strings/string_view.h"
15#include "app/gui/core/icons.h"
16#include "imgui/imgui.h"
17
18namespace yaze {
19namespace editor {
20
35 public:
36 using Callback = std::function<void()>;
37 using EnabledCheck = std::function<bool()>;
38
39 MenuBuilder() = default;
40
44 MenuBuilder& BeginMenu(const char* label, const char* icon = nullptr);
45
49 MenuBuilder& BeginSubMenu(const char* label, const char* icon = nullptr,
50 EnabledCheck enabled = nullptr);
51
56
60 MenuBuilder& Item(const char* label, const char* icon, Callback callback,
61 const char* shortcut = nullptr,
62 EnabledCheck enabled = nullptr,
63 EnabledCheck checked = nullptr);
64
68 MenuBuilder& Item(const char* label, Callback callback,
69 const char* shortcut = nullptr,
70 EnabledCheck enabled = nullptr);
71
76
80 MenuBuilder& DisabledItem(const char* label, const char* icon = nullptr);
81
88 MenuBuilder& CustomMenu(const char* label, Callback draw_callback);
89
93 void Draw();
94
98 void Clear();
99
100 private:
101 struct MenuItem {
102 enum class Type {
103 kItem,
108 };
109
111 std::string label;
112 std::string icon;
113 std::string shortcut;
117 };
118
119 struct Menu {
120 std::string label;
121 std::string icon;
122 std::vector<MenuItem> items;
123 Callback custom_draw; // For custom menus with dynamic content
124 bool is_custom = false;
125 };
126
127 std::vector<Menu> menus_;
128 Menu* current_menu_ = nullptr;
129
130 // Track which submenus are actually open during drawing
131 mutable std::vector<bool> submenu_stack_;
132 mutable int skip_depth_ =
133 0; // Track nesting depth when skipping closed submenus
134
135 void DrawMenuItem(const MenuItem& item);
136};
137
138} // namespace editor
139} // namespace yaze
140
141#endif // YAZE_APP_EDITOR_MENU_MENU_BUILDER_H_
Fluent interface for building ImGui menus with icons.
MenuBuilder & CustomMenu(const char *label, Callback draw_callback)
Add a custom menu with a callback for drawing dynamic content.
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_
std::vector< MenuItem > items