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) "
35 "content=(%.1f,%.1f) cursor_x=%.1f",
38 }
39};
40
42 public:
44 static WidgetMeasurement instance;
45 return instance;
46 }
47
54 WidgetMetrics MeasureLastItem(const std::string& widget_id,
55 const std::string& type = "unknown");
56
60 void BeginToolbarMeasurement(const std::string& toolbar_id);
61
66
70 float GetToolbarWidth(const std::string& toolbar_id) const;
71
75 bool WouldToolbarOverflow(const std::string& toolbar_id,
76 float available_width) const;
77
81 const std::vector<WidgetMetrics>& GetToolbarMetrics(
82 const std::string& toolbar_id) const;
83
87 void ClearFrame();
88
92 std::string ExportMetricsJSON() const;
93
97 void SetEnabled(bool enabled) { enabled_ = enabled; }
98 bool IsEnabled() const { return enabled_; }
99
100 private:
101 WidgetMeasurement() = default;
102
103 bool enabled_ = true;
107
108 // Store measurements per toolbar
109 std::unordered_map<std::string, std::vector<WidgetMetrics>> toolbar_metrics_;
110 std::unordered_map<std::string, float> toolbar_widths_;
111
112 // All measurements from current frame
113 std::vector<WidgetMetrics> frame_metrics_;
114};
115
116} // namespace gui
117} // namespace yaze
118
119#endif // YAZE_APP_GUI_WIDGET_MEASUREMENT_H
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)
std::string ToString() const