Skip to content

Make debugging ids easier #5851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

lucasmerlin
Copy link
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.

Copy link

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.

@emilk
Copy link
Owner

emilk commented Mar 30, 2025

I love this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants