egui icon indicating copy to clipboard operation
egui copied to clipboard

Make debugging ids easier

Open lucasmerlin opened this issue 8 months ago • 2 comments

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.

lucasmerlin avatar Mar 27 '25 15:03 lucasmerlin

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.

github-actions[bot] avatar Mar 27 '25 15:03 github-actions[bot]

I love this!

emilk avatar Mar 30 '25 11:03 emilk