yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
widget_auto_register.h
Go to the documentation of this file.
1#ifndef YAZE_APP_GUI_WIDGETS_WIDGET_AUTO_REGISTER_H_
2#define YAZE_APP_GUI_WIDGETS_WIDGET_AUTO_REGISTER_H_
3
4#include <string>
5
6#include "imgui/imgui.h"
8#include "absl/strings/str_cat.h"
9
30namespace yaze {
31namespace gui {
32
42 public:
43 explicit AutoWidgetScope(const std::string& name);
45
46 // Get current scope path
47 std::string GetPath() const { return scope_.GetFullPath(); }
48
49 private:
51 std::string name_;
52};
53
64void AutoRegisterLastItem(const std::string& widget_type,
65 const std::string& explicit_label = "",
66 const std::string& description = "");
67
68// ============================================================================
69// Automatic Registration Wrappers for Common ImGui Widgets
70// ============================================================================
71// These wrappers call the standard ImGui functions and automatically register
72// the widget with the WidgetIdRegistry for test automation.
73//
74// They preserve the exact same API and return values as ImGui, so they can be
75// drop-in replacements in existing code.
76
77inline bool AutoButton(const char* label, const ImVec2& size = ImVec2(0, 0)) {
78 bool clicked = ImGui::Button(label, size);
79 AutoRegisterLastItem("button", label);
80 return clicked;
81}
82
83inline bool AutoSmallButton(const char* label) {
84 bool clicked = ImGui::SmallButton(label);
85 AutoRegisterLastItem("button", label, "Small button");
86 return clicked;
87}
88
89inline bool AutoCheckbox(const char* label, bool* v) {
90 bool changed = ImGui::Checkbox(label, v);
91 AutoRegisterLastItem("checkbox", label);
92 return changed;
93}
94
95inline bool AutoRadioButton(const char* label, bool active) {
96 bool clicked = ImGui::RadioButton(label, active);
97 AutoRegisterLastItem("radio", label);
98 return clicked;
99}
100
101inline bool AutoRadioButton(const char* label, int* v, int v_button) {
102 bool clicked = ImGui::RadioButton(label, v, v_button);
103 AutoRegisterLastItem("radio", label);
104 return clicked;
105}
106
107inline bool AutoInputText(const char* label, char* buf, size_t buf_size,
108 ImGuiInputTextFlags flags = 0,
109 ImGuiInputTextCallback callback = nullptr,
110 void* user_data = nullptr) {
111 bool changed = ImGui::InputText(label, buf, buf_size, flags, callback, user_data);
112 AutoRegisterLastItem("input", label);
113 return changed;
114}
115
116inline bool AutoInputTextMultiline(const char* label, char* buf, size_t buf_size,
117 const ImVec2& size = ImVec2(0, 0),
118 ImGuiInputTextFlags flags = 0,
119 ImGuiInputTextCallback callback = nullptr,
120 void* user_data = nullptr) {
121 bool changed = ImGui::InputTextMultiline(label, buf, buf_size, size, flags, callback, user_data);
122 AutoRegisterLastItem("textarea", label);
123 return changed;
124}
125
126inline bool AutoInputInt(const char* label, int* v, int step = 1, int step_fast = 100,
127 ImGuiInputTextFlags flags = 0) {
128 bool changed = ImGui::InputInt(label, v, step, step_fast, flags);
129 AutoRegisterLastItem("input_int", label);
130 return changed;
131}
132
133inline bool AutoInputFloat(const char* label, float* v, float step = 0.0f,
134 float step_fast = 0.0f, const char* format = "%.3f",
135 ImGuiInputTextFlags flags = 0) {
136 bool changed = ImGui::InputFloat(label, v, step, step_fast, format, flags);
137 AutoRegisterLastItem("input_float", label);
138 return changed;
139}
140
141inline bool AutoSliderInt(const char* label, int* v, int v_min, int v_max,
142 const char* format = "%d", ImGuiSliderFlags flags = 0) {
143 bool changed = ImGui::SliderInt(label, v, v_min, v_max, format, flags);
144 AutoRegisterLastItem("slider", label);
145 return changed;
146}
147
148inline bool AutoSliderFloat(const char* label, float* v, float v_min, float v_max,
149 const char* format = "%.3f", ImGuiSliderFlags flags = 0) {
150 bool changed = ImGui::SliderFloat(label, v, v_min, v_max, format, flags);
151 AutoRegisterLastItem("slider", label);
152 return changed;
153}
154
155inline bool AutoCombo(const char* label, int* current_item, const char* const items[],
156 int items_count, int popup_max_height_in_items = -1) {
157 bool changed = ImGui::Combo(label, current_item, items, items_count, popup_max_height_in_items);
158 AutoRegisterLastItem("combo", label);
159 return changed;
160}
161
162inline bool AutoSelectable(const char* label, bool selected = false,
163 ImGuiSelectableFlags flags = 0,
164 const ImVec2& size = ImVec2(0, 0)) {
165 bool clicked = ImGui::Selectable(label, selected, flags, size);
166 AutoRegisterLastItem("selectable", label);
167 return clicked;
168}
169
170inline bool AutoSelectable(const char* label, bool* p_selected,
171 ImGuiSelectableFlags flags = 0,
172 const ImVec2& size = ImVec2(0, 0)) {
173 bool clicked = ImGui::Selectable(label, p_selected, flags, size);
174 AutoRegisterLastItem("selectable", label);
175 return clicked;
176}
177
178inline bool AutoMenuItem(const char* label, const char* shortcut = nullptr,
179 bool selected = false, bool enabled = true) {
180 bool activated = ImGui::MenuItem(label, shortcut, selected, enabled);
181 AutoRegisterLastItem("menuitem", label);
182 return activated;
183}
184
185inline bool AutoMenuItem(const char* label, const char* shortcut, bool* p_selected,
186 bool enabled = true) {
187 bool activated = ImGui::MenuItem(label, shortcut, p_selected, enabled);
188 AutoRegisterLastItem("menuitem", label);
189 return activated;
190}
191
192inline bool AutoBeginMenu(const char* label, bool enabled = true) {
193 bool opened = ImGui::BeginMenu(label, enabled);
194 if (opened) {
195 AutoRegisterLastItem("menu", label, "Submenu");
196 }
197 return opened;
198}
199
200inline bool AutoBeginTabItem(const char* label, bool* p_open = nullptr,
201 ImGuiTabItemFlags flags = 0) {
202 bool selected = ImGui::BeginTabItem(label, p_open, flags);
203 if (selected) {
204 AutoRegisterLastItem("tab", label);
205 }
206 return selected;
207}
208
209inline bool AutoTreeNode(const char* label) {
210 bool opened = ImGui::TreeNode(label);
211 if (opened) {
212 AutoRegisterLastItem("treenode", label);
213 }
214 return opened;
215}
216
217inline bool AutoTreeNodeEx(const char* label, ImGuiTreeNodeFlags flags = 0) {
218 bool opened = ImGui::TreeNodeEx(label, flags);
219 if (opened) {
220 AutoRegisterLastItem("treenode", label);
221 }
222 return opened;
223}
224
225inline bool AutoCollapsingHeader(const char* label, ImGuiTreeNodeFlags flags = 0) {
226 bool opened = ImGui::CollapsingHeader(label, flags);
227 if (opened) {
228 AutoRegisterLastItem("collapsing", label);
229 }
230 return opened;
231}
232
233// ============================================================================
234// Canvas-specific registration helpers
235// ============================================================================
236
246inline void RegisterCanvas(const char* canvas_name, const std::string& description = "") {
247 AutoRegisterLastItem("canvas", canvas_name, description);
248}
249
256inline void RegisterTable(const char* table_name, const std::string& description = "") {
257 AutoRegisterLastItem("table", table_name, description);
258}
259
260} // namespace gui
261} // namespace yaze
262
263#endif // YAZE_APP_GUI_WIDGETS_WIDGET_AUTO_REGISTER_H_
264
RAII scope that enables automatic widget registration.
RAII helper for managing hierarchical ImGui ID scopes.
std::string GetFullPath() const
void RegisterTable(const char *table_name, const std::string &description="")
Register a table after BeginTable.
bool AutoBeginTabItem(const char *label, bool *p_open=nullptr, ImGuiTabItemFlags flags=0)
void AutoRegisterLastItem(const std::string &widget_type, const std::string &explicit_label, const std::string &description)
Automatically register the last ImGui item.
bool AutoInputFloat(const char *label, float *v, float step=0.0f, float step_fast=0.0f, const char *format="%.3f", ImGuiInputTextFlags flags=0)
bool AutoInputTextMultiline(const char *label, char *buf, size_t buf_size, const ImVec2 &size=ImVec2(0, 0), ImGuiInputTextFlags flags=0, ImGuiInputTextCallback callback=nullptr, void *user_data=nullptr)
bool AutoInputInt(const char *label, int *v, int step=1, int step_fast=100, ImGuiInputTextFlags flags=0)
bool AutoTreeNode(const char *label)
bool AutoSelectable(const char *label, bool selected=false, ImGuiSelectableFlags flags=0, const ImVec2 &size=ImVec2(0, 0))
bool AutoSliderFloat(const char *label, float *v, float v_min, float v_max, const char *format="%.3f", ImGuiSliderFlags flags=0)
bool AutoCheckbox(const char *label, bool *v)
bool AutoRadioButton(const char *label, bool active)
bool AutoTreeNodeEx(const char *label, ImGuiTreeNodeFlags flags=0)
bool AutoButton(const char *label, const ImVec2 &size=ImVec2(0, 0))
bool AutoSmallButton(const char *label)
void RegisterCanvas(const char *canvas_name, const std::string &description="")
Register a canvas widget after BeginChild or similar.
bool AutoCombo(const char *label, int *current_item, const char *const items[], int items_count, int popup_max_height_in_items=-1)
bool AutoMenuItem(const char *label, const char *shortcut=nullptr, bool selected=false, bool enabled=true)
bool AutoCollapsingHeader(const char *label, ImGuiTreeNodeFlags flags=0)
bool AutoInputText(const char *label, char *buf, size_t buf_size, ImGuiInputTextFlags flags=0, ImGuiInputTextCallback callback=nullptr, void *user_data=nullptr)
bool AutoSliderInt(const char *label, int *v, int v_min, int v_max, const char *format="%d", ImGuiSliderFlags flags=0)
bool AutoBeginMenu(const char *label, bool enabled=true)
Main namespace for the application.