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
95 void Draw();
96
100 void Clear();
101
102 private:
103 struct MenuItem {
104 enum class Type {
105 kItem,
110 };
111
113 std::string label;
114 std::string icon;
115 std::string shortcut;
119 };
120
121 struct Menu {
122 std::string label;
123 std::string icon;
124 std::vector<MenuItem> items;
125 Callback custom_draw; // For custom menus with dynamic content
126 bool is_custom = false;
127 };
128
129 std::vector<Menu> menus_;
130 Menu* current_menu_ = nullptr;
131
132 // Track which submenus are actually open during drawing
133 mutable std::vector<bool> submenu_stack_;
134 mutable int skip_depth_ =
135 0; // Track nesting depth when skipping closed submenus
136
137 void DrawMenuItem(const MenuItem& item);
138};
139
140} // namespace editor
141} // namespace yaze
142
143#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.
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