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