From 1992adaf0af31d4ef930fca10ae25fc51f6e1e67 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 18 Sep 2026 11:02:08 +0200 Subject: [PATCH] `Plot::new` now takes an `impl AsIdSalt` A plot's id source only has to be unique within the `Ui` the plot is shown in, which is exactly what an `IdSalt` is. Hashing it into a globally unique `Id` first, only to then use that `Id` as a salt, was both wasteful and the wrong concept. Co-Authored-By: Claude Opus 5 --- egui_plot/src/plot.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/egui_plot/src/plot.rs b/egui_plot/src/plot.rs index 00738336..594e4d24 100644 --- a/egui_plot/src/plot.rs +++ b/egui_plot/src/plot.rs @@ -1,9 +1,11 @@ use std::ops::RangeInclusive; use std::sync::Arc; +use egui::AsIdSalt; use egui::Color32; use egui::CursorIcon; use egui::Id; +use egui::IdSalt; use egui::Layout; use egui::Painter; use egui::PointerButton; @@ -87,7 +89,7 @@ type AxisResponses = [Vec; 2]; /// # }); /// ``` pub struct Plot<'a> { - id_source: Id, + id_salt: IdSalt, id: Option, center_axis: Vec2b, @@ -139,9 +141,11 @@ pub struct Plot<'a> { impl<'a> Plot<'a> { /// Give a unique id for each plot within the same [`Ui`]. - pub fn new(id_source: impl egui::AsId) -> Self { + /// + /// The salt only has to be unique within the [`Ui`] the plot is shown in. + pub fn new(id_salt: impl AsIdSalt) -> Self { Self { - id_source: Id::new(id_source), + id_salt: IdSalt::new(id_salt), id: None, center_axis: false.into(), @@ -1616,7 +1620,7 @@ impl<'a> Plot<'a> { } fn show_dyn(self, ui: &mut Ui, build_fn: Box) -> R + 'a>) -> PlotResponse { - let plot_id = self.id.unwrap_or_else(|| ui.make_persistent_id(self.id_source)); + let plot_id = self.id.unwrap_or_else(|| ui.make_persistent_id(self.id_salt)); // Get complete rect for drawing. let complete_rect = self.calculate_widget_complete_rect(ui);