From 07da54ad08b985009437ec0a5e2531be567ce294 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 21 Apr 2021 22:19:51 +0200 Subject: [PATCH] Refactor Ui::next_auto_id_source --- egui/src/ui.rs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/egui/src/ui.rs b/egui/src/ui.rs index eb255cce..e91e38d2 100644 --- a/egui/src/ui.rs +++ b/egui/src/ui.rs @@ -38,7 +38,7 @@ pub struct Ui { /// and the value is increment with each added child widget. /// This works as an Id source only as long as new widgets aren't added or removed. /// They are therefore only good for Id:s that has no state. - next_auto_id: u64, + next_auto_id_source: u64, /// Specifies paint layer, clip rectangle and a reference to `Context`. painter: Painter, @@ -64,7 +64,7 @@ impl Ui { let style = ctx.style(); Ui { id, - next_auto_id: id.with("auto").value(), + next_auto_id_source: id.with("auto").value(), painter: Painter::new(ctx, layer_id, clip_rect), style, placer: Placer::new(max_rect, Layout::default()), @@ -74,11 +74,12 @@ impl Ui { pub fn child_ui(&mut self, max_rect: Rect, layout: Layout) -> Self { debug_assert!(!max_rect.any_nan()); - self.next_auto_id = self.next_auto_id.wrapping_add(1); + let next_auto_id_source = Id::new(self.next_auto_id_source).with("child").value(); + self.next_auto_id_source = self.next_auto_id_source.wrapping_add(1); Ui { id: self.id.with("child"), - next_auto_id: Id::new(self.next_auto_id).with("child").value(), + next_auto_id_source, painter: self.painter.clone(), style: self.style.clone(), placer: Placer::new(max_rect, layout), @@ -457,20 +458,15 @@ impl Ui { self.id.with(&id_source) } - #[deprecated = "This id now returned from ui.allocate_space"] - pub fn make_position_id(&self) -> Id { - Id::new(self.next_auto_id) - } - pub(crate) fn next_auto_id(&self) -> Id { - Id::new(self.next_auto_id.wrapping_add(1)) + Id::new(self.next_auto_id_source) } pub(crate) fn auto_id_with(&self, id_source: IdSource) -> Id where IdSource: Hash + std::fmt::Debug, { - Id::new(self.next_auto_id).with(id_source) + Id::new(self.next_auto_id_source).with(id_source) } } @@ -633,8 +629,8 @@ impl Ui { } } - self.next_auto_id = self.next_auto_id.wrapping_add(1); - let id = Id::new(self.next_auto_id); + let id = Id::new(self.next_auto_id_source); + self.next_auto_id_source = self.next_auto_id_source.wrapping_add(1); (id, rect) } @@ -671,8 +667,9 @@ impl Ui { self.placer.debug_paint_cursor(&painter); } - self.next_auto_id = self.next_auto_id.wrapping_add(1); - Id::new(self.next_auto_id) + let id = Id::new(self.next_auto_id_source); + self.next_auto_id_source = self.next_auto_id_source.wrapping_add(1); + id } pub(crate) fn placer(&self) -> &Placer {