From 0f8614d69eee66d32ba153d949c50a79602a9960 Mon Sep 17 00:00:00 2001 From: Hrafn Orri Hrafnkelsson Date: Tue, 27 Aug 2024 07:43:57 +0000 Subject: [PATCH] Avoid some `Id` clashes by seeding auto-ids with child id (#4840) I was having trouble with id collisions and was not able to resolve it using `push_id` and `child_ui_with_id_source`. When investigating the issue I found https://github.com/emilk/egui/pull/2262 which matched the issues I had so I forked egui and implemented the changes from that PR for the latest version. It solved the issue for me. I did not notice any regressions in my project or the egui web viewer. Co-authored-by: Emil Ernerfeldt --- crates/egui/src/ui.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/egui/src/ui.rs b/crates/egui/src/ui.rs index 7e180a8fc88..ca024a9c5e2 100644 --- a/crates/egui/src/ui.rs +++ b/crates/egui/src/ui.rs @@ -225,10 +225,11 @@ impl Ui { } debug_assert!(!max_rect.any_nan()); - let next_auto_id_source = Id::new(self.next_auto_id_source).with("child").value(); + let new_id = self.id.with(id_source); + let next_auto_id_source = new_id.with(self.next_auto_id_source).value(); + self.next_auto_id_source = self.next_auto_id_source.wrapping_add(1); - let new_id = self.id.with(id_source); let placer = Placer::new(max_rect, layout); let ui_stack = UiStack { id: new_id,