diff --git a/crates/ui-panels/src/docking/event.rs b/crates/ui-panels/src/docking/event.rs index 02e7fe009..29042c15a 100644 --- a/crates/ui-panels/src/docking/event.rs +++ b/crates/ui-panels/src/docking/event.rs @@ -1,7 +1,7 @@ //! `DockEvent`, `FloatSpace` and `HidePanels`: what a dock reports to the host and the host tells a dock. use super::{DockCommands, DockSizes, DragUnit, PanelKey}; -use crate::contract::{MemoKey, MemoProps, Tracked}; +use crate::contract::{MemoProps, Tracked}; use egui::{Rect, Vec2}; use std::collections::BTreeSet; @@ -47,7 +47,7 @@ pub enum DockEvent

{ /// /// The set is a `Tracked` value, so a dock keys what it shows by the set's revision and keeps the pruned layout until /// the set, the workspace or the shell's visibility changes. -#[derive(Clone, Copy)] +#[derive(Clone, Copy, MemoProps)] #[non_exhaustive] pub enum HidePanels<'a> { /// Hides none. @@ -58,19 +58,6 @@ pub enum HidePanels<'a> { Except(&'a Tracked>), } -impl MemoProps for HidePanels<'_> { - fn key(&self, key: &mut MemoKey) { - match self { - HidePanels::None => key.write_u32(0), - HidePanels::All => key.write_u32(1), - HidePanels::Except(keep) => { - key.write_u32(2); - keep.key(key); - } - } - } -} - /// Where a docking command floats a panel, group or column when it gives no rect. A dock records one each pass; /// the host reads it to turn a command into placements. #[derive(Clone, Debug, PartialEq)] diff --git a/crates/ui-panels/src/docking/group.rs b/crates/ui-panels/src/docking/group.rs index 16c7f8438..237c1014a 100644 --- a/crates/ui-panels/src/docking/group.rs +++ b/crates/ui-panels/src/docking/group.rs @@ -585,6 +585,7 @@ struct TabRow<'a, P> { /// The group's anchor panel, which names its drop spots. #[memo_props(hash = "a dock's panels are plain values it keys by their hash")] anchor: P, + #[memo_props(hash = "its Hash is the content key taken when the titles were made")] panels: Titles, active: PanelKey, closable: bool, diff --git a/crates/ui-panels/src/docking/mod.rs b/crates/ui-panels/src/docking/mod.rs index 0fc63b564..f6fdc7168 100644 --- a/crates/ui-panels/src/docking/mod.rs +++ b/crates/ui-panels/src/docking/mod.rs @@ -136,9 +136,10 @@ impl Titles { } } -impl crate::contract::MemoProps for Titles { - fn key(&self, key: &mut crate::contract::MemoKey) { - self.key.key(key); +/// Feeds the content key taken when the titles were made, not the titles. +impl Hash for Titles { + fn hash(&self, state: &mut H) { + self.key.hash(state); } } diff --git a/crates/ui-panels/src/rails/tool.rs b/crates/ui-panels/src/rails/tool.rs index 8f68463fe..0e76f6049 100644 --- a/crates/ui-panels/src/rails/tool.rs +++ b/crates/ui-panels/src/rails/tool.rs @@ -120,6 +120,7 @@ pub struct ToolRail<'a, T: Value + MemoProps + PlainData + 'static> { #[prop(flag)] editing: bool, /// The tools the user's toolbar settings hide. + #[prop(into)] hidden: Option<&'a Tracked>>, footer: Option>, /// The columns the rail lays out in this pass. @@ -155,13 +156,6 @@ impl<'a, T: Value + MemoProps + PlainData + 'static> ToolRail<'a, T> { .label(label) } - /// The tools the user's toolbar settings hide. - #[must_use] - pub fn hidden(mut self, hidden: &'a Tracked>) -> Self { - self.hidden = Some(hidden); - self - } - /// The cells the rail lays out: its visible slots and the Edit Toolbar button. fn cells(&self) -> usize { visible_slots(self.slots, hidden_in(self.hidden)).len() + usize::from(self.edit_toolbar.is_some()) @@ -189,10 +183,7 @@ impl<'a, T: Value + MemoProps + PlainData + 'static> ToolRail<'a, T> { } /// The tools a rail hides: the host's, or none. -fn hidden_in<'a, T>(hidden: Option<&'a Tracked>>) -> &'a [T] -where - T: PlainData, -{ +fn hidden_in(hidden: Option<&Tracked>>) -> &[T] { hidden.map_or(&[], |hidden| hidden.as_slice()) } diff --git a/crates/ui-panels/src/rails/tool/trials.rs b/crates/ui-panels/src/rails/tool/trials.rs index 4faa6f1c8..f9b9c2404 100644 --- a/crates/ui-panels/src/rails/tool/trials.rs +++ b/crates/ui-panels/src/rails/tool/trials.rs @@ -284,6 +284,9 @@ fn an_open_flyout_builds_no_derived_values() { } } +/// The room of the key-byte trial. +const KEY_BYTES_ROOM: Vec2 = Vec2::new(120.0, 400.0); + /// The key bytes of an idle pass of a rail of `count` slots, a quarter of whose tools are hidden and half remembered. fn idle_key_bytes(count: u8) -> usize { let slots = Tracked::new((0..count).map(|id| ToolSlot::new(u32::from(id), tools(&[id]))).collect::>()); @@ -296,7 +299,7 @@ fn idle_key_bytes(count: u8) -> usize { let mut fixture = Fixture::new(move |ui| { ToolRail::new("Tools", &slots, &0, &last).hidden(&hidden).show_rail(ui, |_, _| {}); }); - fixture.room(Vec2::new(120.0, 400.0)).settle().idle(1); + fixture.room(KEY_BYTES_ROOM).settle().idle(1); assert_eq!(last_frame_derived_builds(fixture.ctx()), Vec::new(), "an idle rail builds no derived value"); last_pass_memo_key_bytes(fixture.ctx()) }