yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
widget_measurement.h
Go to the documentation of this file.
1#ifndef YAZE_APP_GUI_WIDGET_MEASUREMENT_H
2#define YAZE_APP_GUI_WIDGET_MEASUREMENT_H
3
4#include <string>
5#include <unordered_map>
6#include <vector>
7
8#include "absl/strings/str_format.h"
9#include "imgui/imgui.h"
10
11namespace yaze {
12namespace gui {
13
23 ImVec2 size; // Width and height
24 ImVec2 position; // Screen position
25 ImVec2 content_size; // Available content region
26 ImVec2 rect_min; // Bounding box min
27 ImVec2 rect_max; // Bounding box max
28 float cursor_pos_x; // Cursor X after rendering
29 std::string widget_id; // Widget identifier
30 std::string type; // Widget type (button, input, combo, etc.)
31
32 std::string ToString() const {
33 return absl::StrFormat(
34 "Widget '%s' (%s): size=(%.1f,%.1f) pos=(%.1f,%.1f) content=(%.1f,%.1f) cursor_x=%.1f",
37 }
38};
39
41 public:
43 static WidgetMeasurement instance;
44 return instance;
45 }
46
53 WidgetMetrics MeasureLastItem(const std::string& widget_id,
54 const std::string& type = "unknown");
55
59 void BeginToolbarMeasurement(const std::string& toolbar_id);
60
65
69 float GetToolbarWidth(const std::string& toolbar_id) const;
70
74 bool WouldToolbarOverflow(const std::string& toolbar_id,
75 float available_width) const;
76
80 const std::vector<WidgetMetrics>& GetToolbarMetrics(
81 const std::string& toolbar_id) const;
82
86 void ClearFrame();
87
91 std::string ExportMetricsJSON() const;
92
96 void SetEnabled(bool enabled) { enabled_ = enabled; }
97 bool IsEnabled() const { return enabled_; }
98
99 private:
100 WidgetMeasurement() = default;
101
102 bool enabled_ = true;
106
107 // Store measurements per toolbar
108 std::unordered_map<std::string, std::vector<WidgetMetrics>> toolbar_metrics_;
109 std::unordered_map<std::string, float> toolbar_widths_;
110
111 // All measurements from current frame
112 std::vector<WidgetMetrics> frame_metrics_;
113};
114
115} // namespace gui
116} // namespace yaze
117
118#endif // YAZE_APP_GUI_WIDGET_MEASUREMENT_H
119
Tracks widget dimensions for debugging and test automation.
bool WouldToolbarOverflow(const std::string &toolbar_id, float available_width) const
Check if toolbar would overflow given window width.
float GetToolbarWidth(const std::string &toolbar_id) const
Get total measured width of a toolbar.
std::unordered_map< std::string, std::vector< WidgetMetrics > > toolbar_metrics_
std::vector< WidgetMetrics > frame_metrics_
void SetEnabled(bool enabled)
Enable/disable measurement (performance option)
void EndToolbarMeasurement()
End measuring a toolbar section and store total width.
std::unordered_map< std::string, float > toolbar_widths_
static WidgetMeasurement & Instance()
const std::vector< WidgetMetrics > & GetToolbarMetrics(const std::string &toolbar_id) const
Get all measurements for a specific toolbar.
WidgetMetrics MeasureLastItem(const std::string &widget_id, const std::string &type="unknown")
Measure the last rendered ImGui item.
void BeginToolbarMeasurement(const std::string &toolbar_id)
Begin measuring a toolbar section.
std::string ExportMetricsJSON() const
Export measurements for test automation.
void ClearFrame()
Clear all measurements (call once per frame)
Main namespace for the application.
Definition controller.cc:20
std::string ToString() const