10#include "absl/strings/ascii.h"
11#include "absl/strings/str_cat.h"
12#include "absl/strings/str_format.h"
13#include "absl/strings/str_join.h"
14#include "absl/strings/str_split.h"
15#include "absl/strings/strip.h"
16#include "absl/time/clock.h"
17#include "imgui/imgui_internal.h"
28 ImGuiContext* ctx = ImGui::GetCurrentContext();
29 if (ctx && ctx->CurrentWindow && !ctx->Windows.empty()) {
30 ImGui::PushID(name.c_str());
48 const std::string& widget_name)
const {
53 return absl::StrCat(path, widget_type,
":", widget_name);
64 ImGuiContext* ctx = ImGui::GetCurrentContext();
74 info.seen_in_current_frame =
false;
80 if (!info.seen_in_current_frame) {
83 info.bounds.valid =
false;
84 info.stale_frame_count += 1;
86 info.seen_in_current_frame =
false;
87 info.stale_frame_count = 0;
96 size_t slash = path.find(
'/');
97 if (slash == absl::string_view::npos) {
98 return std::string(path);
100 return std::string(path.substr(0, slash));
104 size_t colon = path.rfind(
':');
105 if (colon == absl::string_view::npos) {
106 size_t slash = path.rfind(
'/');
107 if (slash == absl::string_view::npos) {
108 return std::string(path);
110 return std::string(path.substr(slash + 1));
112 return std::string(path.substr(colon + 1));
116 if (timestamp == absl::Time()) {
120 std::chrono::system_clock::time_point chrono_time =
121 absl::ToChronoTime(timestamp);
122 std::time_t time_value = std::chrono::system_clock::to_time_t(chrono_time);
126 if (gmtime_s(&tm_buffer, &time_value) != 0) {
130 if (gmtime_r(&time_value, &tm_buffer) ==
nullptr) {
136 if (std::snprintf(buffer,
sizeof(buffer),
"%04d-%02d-%02dT%02d:%02d:%02dZ",
137 tm_buffer.tm_year + 1900, tm_buffer.tm_mon + 1,
138 tm_buffer.tm_mday, tm_buffer.tm_hour, tm_buffer.tm_min,
139 tm_buffer.tm_sec) <= 0) {
143 return std::string(buffer);
148 bounds.
min_x = rect.Min.x;
149 bounds.
min_y = rect.Min.y;
150 bounds.
max_x = rect.Max.x;
151 bounds.
max_y = rect.Max.y;
159 const std::string& type,
161 const std::string& description,
169 if (metadata.
label.has_value()) {
174 if (info.
label.empty()) {
175 info.
label = ExtractLabelFromPath(full_path);
184 info.
window_name = ExtractWindowFromPath(full_path);
187 ImGuiContext* ctx = ImGui::GetCurrentContext();
188 absl::Time observed_at = absl::Now();
191 const ImGuiLastItemData& last = ctx->LastItemData;
192 if (metadata.
visible.has_value()) {
195 info.
visible = (last.StatusFlags & ImGuiItemStatusFlags_Visible) != 0;
198 if (metadata.
enabled.has_value()) {
201 info.
enabled = (last.ItemFlags & ImGuiItemFlags_Disabled) == 0;
204 if (metadata.
bounds.has_value()) {
207 info.
bounds = BoundsFromImGui(last.Rect);
214 if (metadata.
bounds.has_value()) {
230 const std::string& pattern)
const {
231 std::vector<std::string> matches;
235 for (
const auto& [path, info] :
widgets_) {
238 if (pattern ==
"*") {
240 }
else if (pattern.find(
'*') != std::string::npos) {
242 std::string search = pattern;
243 search.erase(std::remove(search.begin(), search.end(),
'*'), search.end());
244 if (!search.empty() && path.find(search) != std::string::npos) {
249 if (path == pattern) {
255 matches.push_back(path);
260 std::sort(matches.begin(), matches.end());
267 return it->second.imgui_id;
273 const std::string& full_path)
const {
287 std::ostringstream ss;
289 if (format ==
"json") {
291 ss <<
" \"widgets\": [\n";
294 for (
const auto& [path, info] :
widgets_) {
295 if (!first) ss <<
",\n";
299 ss << absl::StrFormat(
" \"path\": \"%s\",\n", path);
300 ss << absl::StrFormat(
" \"type\": \"%s\",\n", info.type);
301 ss << absl::StrFormat(
" \"imgui_id\": %u,\n", info.imgui_id);
302 ss << absl::StrFormat(
" \"label\": \"%s\",\n", info.label);
303 ss << absl::StrFormat(
" \"window\": \"%s\",\n", info.window_name);
304 ss << absl::StrFormat(
" \"visible\": %s,\n",
305 info.visible ?
"true" :
"false");
306 ss << absl::StrFormat(
" \"enabled\": %s,\n",
307 info.enabled ?
"true" :
"false");
308 if (info.bounds.valid) {
309 ss << absl::StrFormat(
310 " \"bounds\": {\"min\": [%0.1f, %0.1f], \"max\": [%0.1f, %0.1f]},\n",
311 info.bounds.min_x, info.bounds.min_y, info.bounds.max_x,
314 ss <<
" \"bounds\": null,\n";
316 ss << absl::StrFormat(
" \"last_seen_frame\": %d,\n",
317 info.last_seen_frame);
318 std::string iso_timestamp = FormatTimestampUTC(info.last_seen_time);
319 ss << absl::StrFormat(
" \"last_seen_at\": \"%s\",\n",
321 ss << absl::StrFormat(
" \"stale\": %s",
322 info.stale_frame_count > 0 ?
"true" :
"false");
323 if (!info.description.empty()) {
325 ss << absl::StrFormat(
" \"description\": \"%s\"\n",
339 for (
const auto& [path, info] :
widgets_) {
340 ss << absl::StrFormat(
" - path: \"%s\"\n", path);
341 ss << absl::StrFormat(
" type: %s\n", info.type);
342 ss << absl::StrFormat(
" imgui_id: %u\n", info.imgui_id);
343 ss << absl::StrFormat(
" label: \"%s\"\n", info.label);
344 ss << absl::StrFormat(
" window: \"%s\"\n", info.window_name);
345 ss << absl::StrFormat(
" visible: %s\n", info.visible ?
"true" :
"false");
346 ss << absl::StrFormat(
" enabled: %s\n", info.enabled ?
"true" :
"false");
347 if (info.bounds.valid) {
349 ss << absl::StrFormat(
" min: [%0.1f, %0.1f]\n", info.bounds.min_x,
351 ss << absl::StrFormat(
" max: [%0.1f, %0.1f]\n", info.bounds.max_x,
354 ss << absl::StrFormat(
" last_seen_frame: %d\n", info.last_seen_frame);
355 std::string iso_timestamp = FormatTimestampUTC(info.last_seen_time);
356 ss << absl::StrFormat(
" last_seen_at: %s\n", iso_timestamp);
357 ss << absl::StrFormat(
" stale: %s\n",
358 info.stale_frame_count > 0 ?
"true" :
"false");
361 std::vector<std::string> segments = absl::StrSplit(path,
'/');
362 if (!segments.empty()) {
364 if (segments.size() > 0) {
365 ss << absl::StrFormat(
" editor: %s\n", segments[0]);
367 if (segments.size() > 1) {
368 ss << absl::StrFormat(
" tab: %s\n", segments[1]);
370 if (segments.size() > 2) {
371 ss << absl::StrFormat(
" section: %s\n", segments[2]);
375 if (!info.description.empty()) {
376 ss << absl::StrFormat(
" description: %s\n", info.description);
381 if (info.type ==
"button") {
383 }
else if (info.type ==
"input") {
385 }
else if (info.type ==
"canvas") {
386 ss <<
"click, drag, scroll";
387 }
else if (info.type ==
"checkbox") {
389 }
else if (info.type ==
"slider") {
402 const std::string& format)
const {
404 std::ofstream file(output_file);
405 if (file.is_open()) {
412 size_t pos = label.find(
"##");
413 if (pos != absl::string_view::npos) {
414 label = label.substr(0, pos);
416 std::string sanitized = std::string(absl::StripAsciiWhitespace(label));
Main namespace for the application.