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 "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
85 void Draw();
86
90 void Clear();
91
92 private:
93 struct MenuItem {
94 enum class Type {
95 kItem,
100 };
101
103 std::string label;
104 std::string icon;
105 std::string shortcut;
109 };
110
111 struct Menu {
112 std::string label;
113 std::string icon;
114 std::vector<MenuItem> items;
115 };
116
117 std::vector<Menu> menus_;
118 Menu* current_menu_ = nullptr;
119
120 // Track which submenus are actually open during drawing
121 mutable std::vector<bool> submenu_stack_;
122 mutable int skip_depth_ = 0; // Track nesting depth when skipping closed submenus
123
124 void DrawMenuItem(const MenuItem& item);
125};
126
127} // namespace editor
128} // namespace yaze
129
130#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.
Definition controller.cc:20
std::vector< MenuItem > items