27 ImGuiTestContext* ctx,
const DiscoverWidgetsRequest& request,
28 DiscoverWidgetsResponse* response)
const {
33 response->clear_windows();
34 response->set_total_widgets(0);
35 response->set_generated_at_ms(absl::ToUnixMillis(absl::Now()));
38 if (registry.empty()) {
42 const std::string window_filter_lower =
43 absl::AsciiStrToLower(std::string(request.window_filter()));
44 const std::string path_prefix_lower =
45 absl::AsciiStrToLower(std::string(request.path_prefix()));
46 const bool include_invisible = request.include_invisible();
47 const bool include_disabled = request.include_disabled();
49 std::map<std::string, WindowEntry> window_lookup;
50 int total_widgets = 0;
52 for (
const auto& [path, info] : registry) {
53 if (!
MatchesType(info.type, request.type_filter())) {
61 const std::string window_name =
67 const std::string label =
70 bool widget_enabled = info.enabled;
71 bool widget_visible = info.visible;
73#if defined(YAZE_ENABLE_IMGUI_TEST_ENGINE) && YAZE_ENABLE_IMGUI_TEST_ENGINE
74 bool has_item_info =
false;
75 ImGuiTestItemInfo item_info;
77 item_info = ctx->ItemInfo(label.c_str(), ImGuiTestOpFlags_NoError);
78 if (item_info.ID != 0) {
80 widget_visible = item_info.RectClipped.GetWidth() > 0.0f &&
81 item_info.RectClipped.GetHeight() > 0.0f;
82 widget_enabled = (item_info.ItemFlags & ImGuiItemFlags_Disabled) == 0;
89 auto [it, inserted] = window_lookup.emplace(window_name, WindowEntry{});
90 WindowEntry& entry = it->second;
92 entry.visible = widget_visible;
94 entry.visible = entry.visible || widget_visible;
97 if (!include_invisible && !widget_visible) {
100 if (!include_disabled && !widget_enabled) {
104 if (entry.index == -1) {
105 DiscoveredWindow* window_proto = response->add_windows();
106 entry.index = response->windows_size() - 1;
107 window_proto->set_name(window_name);
108 window_proto->set_visible(entry.visible);
111 auto* window_proto = response->mutable_windows(entry.index);
112 window_proto->set_visible(entry.visible);
114 auto* widget_proto = window_proto->add_widgets();
115 widget_proto->set_path(path);
116 widget_proto->set_label(label);
117 widget_proto->set_type(info.type);
119 widget_proto->set_visible(widget_visible);
120 widget_proto->set_enabled(widget_enabled);
121 widget_proto->set_widget_id(info.imgui_id);
123 if (!info.description.empty()) {
124 widget_proto->set_description(info.description);
127 if (info.bounds.valid) {
128 WidgetBounds* bounds = widget_proto->mutable_bounds();
129 bounds->set_min_x(info.bounds.min_x);
130 bounds->set_min_y(info.bounds.min_y);
131 bounds->set_max_x(info.bounds.max_x);
132 bounds->set_max_y(info.bounds.max_y);
133#if defined(YAZE_ENABLE_IMGUI_TEST_ENGINE) && YAZE_ENABLE_IMGUI_TEST_ENGINE
134 }
else if (ctx && has_item_info) {
135 WidgetBounds* bounds = widget_proto->mutable_bounds();
136 bounds->set_min_x(item_info.RectFull.Min.x);
137 bounds->set_min_y(item_info.RectFull.Min.y);
138 bounds->set_max_x(item_info.RectFull.Max.x);
139 bounds->set_max_y(item_info.RectFull.Max.y);
148 widget_proto->set_last_seen_frame(info.last_seen_frame);
149 int64_t last_seen_ms = 0;
150 if (info.last_seen_time != absl::Time()) {
151 last_seen_ms = absl::ToUnixMillis(info.last_seen_time);
153 widget_proto->set_last_seen_at_ms(last_seen_ms);
154 widget_proto->set_stale(info.stale_frame_count > 0);
159 response->set_total_widgets(total_widgets);