Skip to content

Ui::response only works if UiBuilder::id_salt is uniquely set #5190

@emilk

Description

@emilk

The widget id used for the interact/response of Ui is currently Ui::id, which has a problem: is not necessarily unique.

We should instead use an Id that is globally unique, i.e. based on where in the hierarchy the Ui is, i.e. based on next_auto_id_salt. I believe this means we need to store this in Ui so we can use the same Id in remember_min_rect.

To see the problem with the current code, just apply this diff:

--- a/crates/egui_demo_lib/src/demo/interactive_container.rs
+++ b/crates/egui_demo_lib/src/demo/interactive_container.rs
@@ -21,6 +21,7 @@ impl crate::Demo for InteractiveContainerDemo {
             .show(ctx, |ui| {
                 use crate::View as _;
                 self.ui(ui);
+                self.ui(ui);
             });
     }
 }

This also means the drag-and-drop demo uses the same Id for all drag-sources, which exsasserbates

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is broken

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions