diff --git a/crates/ui-panels/src/docking/mod.rs b/crates/ui-panels/src/docking/mod.rs index e978096aaa..24e01613d7 100644 --- a/crates/ui-panels/src/docking/mod.rs +++ b/crates/ui-panels/src/docking/mod.rs @@ -73,9 +73,8 @@ use crate::contract::{ }; use crate::runtime::commands::CommandRef; use crate::runtime::derived::derived; -use crate::runtime::env::Label; +use crate::runtime::env::{AppValues, EnvValue, Label}; use crate::runtime::focus::KeyUse; -use crate::runtime::memory::sub; use crate::style::{ComponentStyle, StyleCx}; use craft_behavior::dock::{DockEdge, Layout, Node, SplitSize}; use craft_behavior::{Axis, EditEvents, Flow, Metrics, PartKey, Sense}; @@ -359,25 +358,25 @@ struct FramesKey { /// A split area's layout laid out in its rect: each group as its anchor panel and rect, each dock as its window edge /// and rect, and each handle with the range its divider can travel. -struct SplitFrames

{ - groups: Vec<(P, Rect)>, - docks: Vec<(DockEdge, Rect)>, +struct SplitFrames { + groups: SplitGroups

, + docks: SplitDocks, handles: Vec<(SplitHandle, (f32, f32))>, } -impl SplitFrames

{ +impl SplitFrames

{ fn of(layout: &Layout

, rect: Rect, sizes: &DockSizes, rules: &FrameRules<'_, P>, rtl: bool) -> Self { - let Some(root) = layout.root.as_ref() else { return SplitFrames { groups: Vec::new(), docks: Vec::new(), handles: Vec::new() } }; + let Some(root) = layout.root.as_ref() else { return Self::none() }; let frames = tree::frames(root, rect, sizes, rules, rtl); - let groups = frames.groups.iter().filter_map(|group| Some((group.anchor()?.clone(), group.rect))).collect(); - let docks = frames + let (anchors, rects): (Vec

, Vec) = frames.groups.iter().filter_map(|group| Some((group.anchor()?.clone(), group.rect))).unzip(); + let (edges, dock_rects): (Vec, Vec) = frames .groups .iter() .filter_map(|group| match group.node { Node::Dock { side, .. } => Some((*side, group.rect)), _ => None, }) - .collect(); + .unzip(); let handles = frames .handles .into_iter() @@ -386,32 +385,58 @@ impl SplitFrames

{ (handle, range) }) .collect(); - SplitFrames { groups, docks, handles } + SplitFrames { + groups: SplitGroups { anchors: Arc::from(anchors), rects: Arc::from(rects) }, + docks: SplitDocks { edges: Arc::from(edges), rects: Arc::from(dock_rects) }, + handles, + } + } + + fn none() -> Self { + SplitFrames { groups: SplitGroups::empty(), docks: SplitDocks::root(), handles: Vec::new() } } } -/// The groups of the layout with the frames the area gave them this pass, for the body. -#[derive(Clone)] -struct PassFrames

(Vec<(P, Rect)>); +/// The groups of the innermost split area, each anchor panel with its rect, as the area lays them out in the run its +/// body runs in: at the measuring run's rect, or at the real run's after its divider edits. +#[derive(Clone, PartialEq, crate::contract::MemoProps)] +struct SplitGroups { + #[memo_props(hash = "a split area's anchors are plain panel values it keys by their hash")] + anchors: Arc<[P]>, + rects: Arc<[Rect]>, +} -impl

Default for PassFrames

{ - fn default() -> Self { - PassFrames(Vec::new()) +impl SplitGroups

{ + fn empty() -> Self { + SplitGroups { anchors: Arc::from(Vec::new()), rects: Arc::from(Vec::new()) } } } -/// The docks of the layout with the frames the area gave them this pass, for the body. -#[derive(Clone, Default)] -struct PassDocks(Vec<(DockEdge, Rect)>); +impl EnvValue for SplitGroups

{ + fn root() -> Self { + Self::empty() + } +} -const FRAMES: &str = "split_frames"; -const DOCKS: &str = "split_docks"; +/// The docks of the innermost split area, each window edge with its rect, laid out as [`SplitGroups`] are. +#[derive(Clone, PartialEq, crate::contract::MemoProps)] +struct SplitDocks { + #[memo_props(hash = "a dock edge is a plain enum")] + edges: Arc<[DockEdge]>, + rects: Arc<[Rect]>, +} + +impl EnvValue for SplitDocks { + fn root() -> Self { + SplitDocks { edges: Arc::from(Vec::new()), rects: Arc::from(Vec::new()) } + } +} /// What a split area's body reads of the area's frames, on its `BodyCx`. pub trait SplitFramesCx { /// The groups of the split area this body belongs to, each as its anchor panel and its rect, with this pass's /// resize edits applied: a panel placed at its group's rect sits against the handle in the same pass. - fn group_frames(&self) -> Vec<(P, Rect)>; + fn group_frames(&self) -> Vec<(P, Rect)>; /// The docks of the split area this body belongs to, each as its window edge and its rect, with this pass's /// resize edits applied. @@ -419,12 +444,14 @@ pub trait SplitFramesCx { } impl SplitFramesCx for BodyCx<'_> { - fn group_frames(&self) -> Vec<(P, Rect)> { - self.memory.recall::>(sub(self.id, FRAMES)).0 + fn group_frames(&self) -> Vec<(P, Rect)> { + let groups = self.env.get::>(); + groups.anchors.iter().cloned().zip(groups.rects.iter().copied()).collect() } fn dock_frames(&self) -> Vec<(DockEdge, Rect)> { - self.memory.recall::(sub(self.id, DOCKS)).0 + let docks = self.env.get::(); + docks.edges.iter().copied().zip(docks.rects.iter().copied()).collect() } } @@ -488,10 +515,7 @@ impl Component for SplitAr } fn update(&mut self, cx: &mut Cx<'_, Self>) { - let Some(layout) = cx.value().cloned() else { - cx.core.memory.shown::>(sub(sub(cx.core.id, "body"), FRAMES)).0.clear(); - return; - }; + let Some(layout) = cx.value().cloned() else { return }; let (rect, rtl, sizes, rules) = (cx.rect, cx.flow.is_rtl(), cx.style.sizes, self.rules); let frames = self.frames_of(&cx.core.ctx, cx.core.id, &layout, rect, &sizes, rtl); let mut edited = false; @@ -526,11 +550,20 @@ impl Component for SplitAr Some(shown) if edited => Arc::new(SplitFrames::of(shown, rect, &sizes, &rules, rtl)), _ => frames, }; - cx.core.memory.shown::(sub(sub(cx.core.id, "body"), DOCKS)).0 = frames.docks.clone(); - cx.core.memory.shown::>(sub(sub(cx.core.id, "body"), FRAMES)).0 = frames.groups.clone(); self.frames = Some(frames); } + /// The body lays the groups and docks out at the frames of this run: in a measuring run at its rect, in the real + /// run after `update`'s divider edits. + fn content_env(&self, cx: &Cx<'_, Self>, values: &mut AppValues) { + let frames = match cx.value() { + Some(layout) => self.frames_of(&cx.core.ctx, cx.core.id, layout, cx.rect, &cx.style.sizes, cx.flow.is_rtl()), + None => Arc::new(SplitFrames::none()), + }; + values.set(frames.groups.clone()); + values.set(frames.docks.clone()); + } + fn paint_over(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) { let Some(layout) = cx.value() else { return }; let (sizes, rtl) = (cx.style.sizes, cx.flow.is_rtl()); diff --git a/crates/ui-patterns/src/patterns/dock/area.rs b/crates/ui-patterns/src/patterns/dock/area.rs index 04ca8cdf6d..482458c4d5 100644 --- a/crates/ui-patterns/src/patterns/dock/area.rs +++ b/crates/ui-patterns/src/patterns/dock/area.rs @@ -1140,7 +1140,7 @@ fn show_area( } /// Registers the outer-edge bands and the new-dock bands as the dock's drop spots for the next pass, from the leaves -/// the split area placed this pass (each as its tree path and rect). A new-dock band runs along a start or end edge +/// the split area placed in this run (each as its tree path and rect). A new-dock band runs along a start or end edge /// that holds no dock. fn register_bands( scene: &Scene<'_, P>, @@ -1671,9 +1671,10 @@ impl Pass<'_, P> { let dock_width = |columns: &[Column

]| scene.natural(columns).iter().map(|(width, _)| *width).sum::(); let stripless = |panel: &P| scene.spec(panel).canvas; let rules = FrameRules::new(&limits).dock_width(&dock_width).stripless(&stripless).dock_gap(scene.sizes.dock_gap); - let mut leaves: Vec<(Vec, Rect)> = Vec::new(); let area = SplitArea::new(at.label.clone(), Bind::given(scene.layout.clone()), rules, at.frames).show(ui, |ui, split| { DockTargets::

::register_room(&ctx, scene.dock, split.rect); + // The leaves of this run only: a measuring run of the area lays them out too, and registers nothing. + let mut leaves: Vec<(Vec, Rect)> = Vec::new(); for (anchor, rect) in split.group_frames::

() { let Some(place) = scene.layout.place(&anchor) else { continue }; let Some(node) = scene.layout.node_of(&place) else { continue }; @@ -1693,6 +1694,7 @@ impl Pass<'_, P> { let (natural, cards) = at.geometry.dock(edge); self.dock(ui, split, DockPlan { edge, columns, rect, flow, open: at.open.clone(), natural, cards }); } + register_bands(scene, &ctx, at.room, &leaves); }); let splits = area .output @@ -1701,7 +1703,6 @@ impl Pass<'_, P> { .map(|(path, rect, node)| DockSource::new(SourceKind::Divider(DividerKind::Split(path.clone())), *rect, *node)); self.report.sources.extend(splits); self.report.split = area.output.edit.events; - register_bands(scene, &ctx, at.room, &leaves); } /// A key fed with what every column and the docked tree read of the area: the pruned layout, the dock their spots diff --git a/crates/ui-patterns/tests/it/docking/runs.rs b/crates/ui-patterns/tests/it/docking/runs.rs index 697dd857e4..7247605e22 100644 --- a/crates/ui-patterns/tests/it/docking/runs.rs +++ b/crates/ui-patterns/tests/it/docking/runs.rs @@ -681,9 +681,9 @@ fn a_replayed_group_reports_the_focus_it_holds() { assert!(focused.borrow().iter().all(|panel| *panel == Some(0)), "every replay reports the focus: {:?}", focused.borrow()); } -/// The docked tree and its columns report each column and gesture source once in every pass: when the replay audit -/// runs the tree in place of its replay, and when the docks' split area measures them before it shows them (a new -/// room). +/// The docked tree and its columns report each column and gesture source once in every pass, and replay what they +/// ran: the replay audit runs the tree in place of each replay, at rest and through new rooms, where the docks' split +/// area measures them before it shows them. #[trial] fn a_measured_versioned_dock_reports_each_column_and_source_once() { let VersionedDock { mut fixture, reported, .. } = versioned_dock(full(2)); @@ -692,8 +692,8 @@ fn a_measured_versioned_dock_reports_each_column_and_source_once() { audit_replays(fixture.ctx(), true); reported.borrow_mut().clear(); fixture.idle(4); - audit_replays(fixture.ctx(), false); fixture.room(Vec2::new(1100.0, 600.0)).idle(4).room(Vec2::new(1200.0, 640.0)).idle(4); + audit_replays(fixture.ctx(), false); let reported = reported.borrow(); assert!(reported.iter().all(|counts| *counts == settled), "every pass reports {settled:?}: {reported:?}"); }