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 friend class ProjectUiTestPeer;
36
37 public:
38 using Callback = std::function<void()>;
39 using EnabledCheck = std::function<bool()>;
40
41 MenuBuilder() = default;
42
46 MenuBuilder& BeginMenu(const char* label, const char* icon = nullptr);
47
51 MenuBuilder& BeginSubMenu(const char* label, const char* icon = nullptr,
52 EnabledCheck enabled = nullptr);
53
58
62 MenuBuilder& Item(const char* label, const char* icon, Callback callback,
63 const char* shortcut = nullptr,
64 EnabledCheck enabled = nullptr,
65 EnabledCheck checked = nullptr);
66
70 MenuBuilder& Item(const char* label, Callback callback,
71 const char* shortcut = nullptr,
72 EnabledCheck enabled = nullptr);
73
78
82 MenuBuilder& DisabledItem(const char* label, const char* icon = nullptr);
83
90 MenuBuilder& CustomMenu(const char* label, Callback draw_callback);
91
98 MenuBuilder& CustomItems(Callback draw_callback);
99
103 void Draw();
104
108 void Clear();
109
110 private:
111 struct MenuItem {
112 enum class Type {
113 kItem,
117 kDisabled,
118 kCustom
119 };
120
122 std::string label;
123 std::string icon;
124 std::string shortcut;
128 };
129
130 struct Menu {
131 std::string label;
132 std::string icon;
133 std::vector<MenuItem> items;
134 Callback custom_draw; // For custom menus with dynamic content
135 bool is_custom = false;
136 };
137
138 std::vector<Menu> menus_;
139 Menu* current_menu_ = nullptr;
140
141 // Track which submenus are actually open during drawing
142 mutable std::vector<bool> submenu_stack_;
143 mutable int skip_depth_ =
144 0; // Track nesting depth when skipping closed submenus
145
146 void DrawMenuItem(const MenuItem& item);
147};
148
149} // namespace editor
150} // namespace yaze
151
152#endif // YAZE_APP_EDITOR_MENU_MENU_BUILDER_H_
Fluent interface for building ImGui menus with icons.
MenuBuilder & CustomItems(Callback draw_callback)
Add items drawn by a callback inside the current menu.
MenuBuilder & CustomMenu(const char *label, Callback draw_callback)
Add a custom menu with a callback for drawing dynamic content.
friend class ProjectUiTestPeer
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