yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
canvas_menu.cc
Go to the documentation of this file.
1#include "canvas_menu.h"
2
3namespace yaze {
4namespace gui {
5
7 std::function<void(const std::string&, std::function<void()>)>
8 popup_opened_callback) {
9 // Check visibility
10 if (!item.visible_condition()) {
11 return;
12 }
13
14 // Apply disabled state if needed
15 if (!item.enabled_condition()) {
16 ImGui::BeginDisabled();
17 }
18
19 // Build label with icon if present
20 std::string display_label = item.label;
21 if (!item.icon.empty()) {
22 display_label = item.icon + " " + item.label;
23 }
24
25 // Render menu item based on type
26 if (item.subitems.empty()) {
27 // Simple menu item
28 bool selected = false;
29 if (item.color.x != 1.0f || item.color.y != 1.0f ||
30 item.color.z != 1.0f || item.color.w != 1.0f) {
31 // Render with custom color
32 ImGui::PushStyleColor(ImGuiCol_Text, item.color);
33 selected = ImGui::MenuItem(display_label.c_str(),
34 item.shortcut.empty() ? nullptr : item.shortcut.c_str());
35 ImGui::PopStyleColor();
36 } else {
37 selected = ImGui::MenuItem(display_label.c_str(),
38 item.shortcut.empty() ? nullptr : item.shortcut.c_str());
39 }
40
41 if (selected) {
42 // Invoke callback
43 if (item.callback) {
44 item.callback();
45 }
46
47 // Handle popup if defined
48 if (item.popup.has_value() &&
49 item.popup->auto_open_on_select &&
50 popup_opened_callback) {
51 popup_opened_callback(item.popup->popup_id, item.popup->render_callback);
52 }
53 }
54 } else {
55 // Submenu
56 if (ImGui::BeginMenu(display_label.c_str())) {
57 for (const auto& subitem : item.subitems) {
58 RenderMenuItem(subitem, popup_opened_callback);
59 }
60 ImGui::EndMenu();
61 }
62 }
63
64 // Restore enabled state
65 if (!item.enabled_condition()) {
66 ImGui::EndDisabled();
67 }
68
69 // Render separator if requested
70 if (item.separator_after) {
71 ImGui::Separator();
72 }
73}
74
76 std::function<void(const std::string&, std::function<void()>)>
77 popup_opened_callback) {
78 // Skip empty sections
79 if (section.items.empty()) {
80 return;
81 }
82
83 // Render section title if present
84 if (!section.title.empty()) {
85 ImGui::TextColored(section.title_color, "%s", section.title.c_str());
86 ImGui::Separator();
87 }
88
89 // Render all items in section
90 for (const auto& item : section.items) {
91 RenderMenuItem(item, popup_opened_callback);
92 }
93
94 // Render separator after section if requested
95 if (section.separator_after) {
96 ImGui::Separator();
97 }
98}
99
101 std::function<void(const std::string&, std::function<void()>)>
102 popup_opened_callback) {
103 // Skip disabled menus
104 if (!menu.enabled) {
105 return;
106 }
107
108 // Render all sections
109 for (const auto& section : menu.sections) {
110 RenderMenuSection(section, popup_opened_callback);
111 }
112}
113
114} // namespace gui
115} // namespace yaze
116
void RenderCanvasMenu(const CanvasMenuDefinition &menu, std::function< void(const std::string &, std::function< void()>)> popup_opened_callback)
Render a complete menu definition.
void RenderMenuSection(const CanvasMenuSection &section, std::function< void(const std::string &, std::function< void()>)> popup_opened_callback)
Render a menu section.
void RenderMenuItem(const CanvasMenuItem &item, std::function< void(const std::string &, std::function< void()>)> popup_opened_callback)
Render a single menu item.
Definition canvas_menu.cc:6
Main namespace for the application.
Definition controller.cc:20
Complete menu definition.
std::vector< CanvasMenuSection > sections
Declarative menu item definition.
Definition canvas_menu.h:63
std::vector< CanvasMenuItem > subitems
Definition canvas_menu.h:86
std::function< bool()> enabled_condition
Definition canvas_menu.h:80
std::function< void()> callback
Definition canvas_menu.h:74
std::optional< CanvasPopupDefinition > popup
Definition canvas_menu.h:77
std::function< bool()> visible_condition
Definition canvas_menu.h:83
Menu section grouping related menu items.
std::vector< CanvasMenuItem > items