feat: Enhance widget discovery with telemetry data and improve output formatting
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
#ifndef YAZE_APP_GUI_WIDGET_ID_REGISTRY_H_
|
||||
#define YAZE_APP_GUI_WIDGET_ID_REGISTRY_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "imgui/imgui.h"
|
||||
|
||||
namespace yaze {
|
||||
@@ -62,20 +66,50 @@ class WidgetIdScope {
|
||||
*/
|
||||
class WidgetIdRegistry {
|
||||
public:
|
||||
struct WidgetBounds {
|
||||
float min_x = 0.0f;
|
||||
float min_y = 0.0f;
|
||||
float max_x = 0.0f;
|
||||
float max_y = 0.0f;
|
||||
bool valid = false;
|
||||
};
|
||||
|
||||
struct WidgetMetadata {
|
||||
std::optional<std::string> label;
|
||||
std::optional<std::string> window_name;
|
||||
std::optional<bool> visible;
|
||||
std::optional<bool> enabled;
|
||||
std::optional<WidgetBounds> bounds;
|
||||
};
|
||||
|
||||
struct WidgetInfo {
|
||||
std::string full_path; // e.g. "Overworld/Canvas/canvas:Map"
|
||||
std::string type; // e.g. "button", "input", "canvas", "table"
|
||||
ImGuiID imgui_id; // ImGui's internal ID
|
||||
std::string description; // Optional human-readable description
|
||||
std::string label; // Sanitized display label (without IDs/icons)
|
||||
std::string window_name; // Window this widget was last seen in
|
||||
bool visible = true; // Visibility in the most recent frame
|
||||
bool enabled = true; // Enabled state in the most recent frame
|
||||
WidgetBounds bounds; // Bounding box in screen space
|
||||
int last_seen_frame = -1;
|
||||
absl::Time last_seen_time;
|
||||
bool seen_in_current_frame = false;
|
||||
int stale_frame_count = 0;
|
||||
};
|
||||
|
||||
static WidgetIdRegistry& Instance();
|
||||
|
||||
// Frame lifecycle - call once per ImGui frame
|
||||
void BeginFrame();
|
||||
void EndFrame();
|
||||
|
||||
// Register a widget for discovery
|
||||
// Should be called after widget is created (when ImGui::GetItemID() is valid)
|
||||
void RegisterWidget(const std::string& full_path, const std::string& type,
|
||||
ImGuiID imgui_id,
|
||||
const std::string& description = "");
|
||||
const std::string& description = "",
|
||||
const WidgetMetadata& metadata = WidgetMetadata());
|
||||
|
||||
// Query widgets for test automation
|
||||
std::vector<std::string> FindWidgets(const std::string& pattern) const;
|
||||
@@ -96,9 +130,19 @@ class WidgetIdRegistry {
|
||||
void ExportCatalogToFile(const std::string& output_file,
|
||||
const std::string& format = "yaml") const;
|
||||
|
||||
// Helper utilities for consistent naming
|
||||
static std::string NormalizeLabel(absl::string_view label);
|
||||
static std::string NormalizePathSegment(absl::string_view segment);
|
||||
|
||||
private:
|
||||
WidgetIdRegistry() = default;
|
||||
void TrimStaleEntries();
|
||||
bool ShouldPrune(const WidgetInfo& info) const;
|
||||
|
||||
std::unordered_map<std::string, WidgetInfo> widgets_;
|
||||
int current_frame_ = -1;
|
||||
absl::Time frame_time_;
|
||||
int stale_frame_limit_ = 600; // frames before pruning a widget
|
||||
};
|
||||
|
||||
// RAII helper macros for convenient scoping
|
||||
|
||||
Reference in New Issue
Block a user