Skip to content

Make debugging ids easier#5851

Open
lucasmerlin wants to merge 13 commits intomainfrom
lucas/experiments/helpful-id-debug
Open

Make debugging ids easier#5851
lucasmerlin wants to merge 13 commits intomainfrom
lucas/experiments/helpful-id-debug

Conversation

@lucasmerlin
Copy link
Copy Markdown
Collaborator

@lucasmerlin lucasmerlin commented Mar 27, 2025

Eguis Ids are awesome, but sometimes it's a pain to figure out where a particular Id is coming from. This is an experiment at improving the situation by requiring the Id's source to implemnt Debug, storing the Debug representation as a string and the Ids optional parent in a global map, and showing the additional info it in the Debug implementation. Since most Ids are derived from a string this works really well:

Screenshot 2025-03-27 at 16 12 21

I also plan on adding a Id::ui that always shows the source and parent and more info on hover (the parents parent and maybe it could also look for widget rects with the Id and higlight those).

Since the String only has to be created once for each unique Id this doesn't seem to have a huge performance impact, so I feel we can always enable this in debug builds.

The downside is of course that creating an Id from something now requires that thing to implement debug, but I don't think it would be a huge problem in practise. We could also add a Id::new_without_debug_info() that just requires the Hash trait.

Also, the current Ui auto ids don't work well with this since they just implement an u64, but I'm sure there is a nice way to make that work.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 27, 2025

Preview available at https://egui-pr-preview.github.io/pr/5851-lucasexperimentshelpful-id-debug
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

View snapshot changes at kitdiff

@emilk
Copy link
Copy Markdown
Owner

emilk commented Mar 30, 2025

I love this!

lucasmerlin and others added 7 commits February 17, 2026 17:13
# Conflicts:
#	crates/egui/src/containers/combo_box.rs
#	crates/egui/src/id.rs
#	crates/egui/src/lib.rs
#	crates/egui/src/ui.rs
#	crates/egui/src/ui_builder.rs
# Conflicts:
#	crates/egui/src/ui_builder.rs
@lucasmerlin lucasmerlin marked this pull request as ready for review March 19, 2026 12:05
@lucasmerlin
Copy link
Copy Markdown
Collaborator Author

It's currently gated behind debug_assertions, but maybe it should be a feature flag instead? Or both?

Copy link
Copy Markdown
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! I think having this always-on in debug builds makes sense. The overhead is one extra lookup in a hashmap, which should be fine (at least once you change it from ahash::HashMap to an IdMap.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not much of a hierarchy though. What is even 152204… there?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that the auto-id? If so, we should maybe create a special path for creating auto-ids just to improve this formatting

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be fixed by #7988.

We could also add a extra Id constructor to pass more metadata, so we could display if it's an auto id, or the id for a Ui or Layer (some of this could also be derived by looking if any of those exist in the egui context for the id)

@emilk
Copy link
Copy Markdown
Owner

emilk commented Mar 20, 2026

Crossposting this comment:

Adding DNM until we have a screenshot test with a nicer UI :]

@emilk emilk added the do-not-merge Do not merge yet, but you can still review it label Mar 20, 2026
@emilk emilk added this to the 0.34.0 milestone Mar 24, 2026
@lucasmerlin lucasmerlin modified the milestones: 0.34.0, 0.35.0 Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dev-experience do-not-merge Do not merge yet, but you can still review it egui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants