diff --git a/crates/ui-patterns/src/patterns/dock/area.rs b/crates/ui-patterns/src/patterns/dock/area.rs index 66a18d3f90..04ca8cdf6d 100644 --- a/crates/ui-patterns/src/patterns/dock/area.rs +++ b/crates/ui-patterns/src/patterns/dock/area.rs @@ -1617,8 +1617,11 @@ impl Pass<'_, P> { // A docked column takes the dock's height, a stepped one (a tool rail) too: the references' docked // toolbar keeps its column's surface down to the dock's foot, with the tools at the top // (photocraft#16461). Content taller than the dock scrolls inside. Only a floating stepped window is as - // tall as its content. - self.report.placed.push(Placed { panel: first.clone(), rect: cell }); + // tall as its content. A measuring run of the container around the dock places it too; the dock reports + // its columns from the pass's real run only, once. + if crate::runtime::measure::effect(ui.ctx(), "dock::placed_report") { + self.report.placed.push(Placed { panel: first.clone(), rect: cell }); + } let card = plan.cards.get(at).copied().flatten(); let place = ("docked", plan.edge, at); let at = ColumnAt { cell, edge: plan.edge, bar: ColumnBar::Own, within: body.rect, open: plan.open.clone(), card }; @@ -1640,7 +1643,7 @@ impl Pass<'_, P> { // The view's room is the column's cell, so the pointer over the cell, and nowhere else, runs it. let drawn = ui.scope_builder(UiBuilder::new().max_rect(cell), |ui| MemoView::new(id, view, column_view::

).show(ui)).inner; if let Some(drawn) = drawn { - self.add_drawn(drawn); + self.add_drawn(ui, drawn); } } @@ -1655,7 +1658,7 @@ impl Pass<'_, P> { let rail_footer = self.scene.rail_footer.cloned(); let view = TreeView { key, rail_footer, pass: &mut *self, at }; if let Some(drawn) = MemoView::new(id, view, tree_view::

).show(ui) { - self.add_drawn(drawn); + self.add_drawn(ui, drawn); } } @@ -1788,8 +1791,12 @@ impl Pass<'_, P> { } } - /// Adds what a view drew, by its run or its replay, to the report. - fn add_drawn(&mut self, drawn: Drawn

) { + /// Adds what a view drew, by its run or its replay, to the report: in the pass's real run only. A measuring run's + /// replay returns the kept real run's report, which the real run adds once. + fn add_drawn(&mut self, ui: &Ui, drawn: Drawn

) { + if !crate::runtime::measure::effect(ui.ctx(), "dock::drawn_report") { + return; + } self.report.sources.extend(drawn.sources); self.report.shown.extend(drawn.shown); self.report.placed.extend(drawn.placed); @@ -1972,8 +1979,10 @@ impl Pass<'_, P> { let output = shown.show_groups_at(ui, cell, |group, rect, ui, body| { self.group_of(ui, body, group, GroupAt::Show(rect), in_window); }); - let dividers = output.dividers.into_iter().map(|(divider, rect, node)| DockSource::new(SourceKind::Divider(divider), rect, node)); - self.report.sources.extend(dividers); + if crate::runtime::measure::effect(ui.ctx(), "dock::divider_report") { + let dividers = output.dividers.into_iter().map(|(divider, rect, node)| DockSource::new(SourceKind::Divider(divider), rect, node)); + self.report.sources.extend(dividers); + } let width = output.width.map(|width| width - inset); ColumnWork { iconic: output.iconic, picked: output.picked, resized: output.resized, width, flyout: None } }; diff --git a/crates/ui-patterns/tests/it/docking/runs.rs b/crates/ui-patterns/tests/it/docking/runs.rs index 04175fb38f..697dd857e4 100644 --- a/crates/ui-patterns/tests/it/docking/runs.rs +++ b/crates/ui-patterns/tests/it/docking/runs.rs @@ -11,12 +11,12 @@ use craft_ui::docking::{DockConfig, DockPanels, PanelDrag, PanelSpec, PanelSpecs use craft_ui::menu::PanelRow; use craft_ui::patterns::dock::DockArea; use craft_ui::runtime::drag; -use craft_ui::testing::in_audit_run; use craft_ui::testing::pointer::{moved, press}; use craft_ui::testing::{ Fixture, MemoRun, last_frame_derived_builds, last_frame_memo_runs, last_pass_derived_builds, last_pass_memo_key_bytes, last_pass_memo_runs, last_pass_runs, trial, }; +use craft_ui::testing::{audit_replays, in_audit_run}; use egui::{Pos2, Rect, Ui, Vec2}; use std::cell::{Cell, RefCell}; use std::rc::Rc; @@ -574,6 +574,8 @@ struct VersionedDock { versions: Rc>>, workspace: Rc>>>, focused: Rc>>>, + /// How many docked columns and gesture sources each pass reported. + reported: Rc>>, } fn versioned_dock(layout: Layout) -> VersionedDock { @@ -581,17 +583,19 @@ fn versioned_dock(layout: Layout) -> VersionedDock { let versions = Rc::new(RefCell::new(vec![0; 32])); let workspace = Rc::new(RefCell::new(Arc::new(Workspace::new(layout)))); let focused = Rc::new(RefCell::new(Vec::new())); + let reported = Rc::new(RefCell::new(Vec::new())); let mut panels = Versioned { versions: Rc::clone(&versions) }; - let (shown, seen) = (Rc::clone(&workspace), Rc::clone(&focused)); + let (shown, seen, counts) = (Rc::clone(&workspace), Rc::clone(&focused), Rc::clone(&reported)); let mut fixture = Fixture::new(move |ui| { let output = DockArea::new("Dock", Bind::bound(&mut *shown.borrow_mut()), &labels, &mut panels, DockConfig::default()).show(ui); seen.borrow_mut().push(output.focused); + counts.borrow_mut().push((output.columns.len(), output.sources.len())); }); fixture.room(Vec2::new(1200.0, 600.0)).settle().idle(SETTLE); body_runs(); spec_reads(); focused.borrow_mut().clear(); - VersionedDock { fixture, versions, workspace, focused } + VersionedDock { fixture, versions, workspace, focused, reported } } /// The dock's containers: what a settled dock whose panels all have versions runs none of. @@ -676,3 +680,20 @@ fn a_replayed_group_reports_the_focus_it_holds() { assert_eq!(runs_of(&fixture, &CONTAINERS), 0, "the focused dock replays"); 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). +#[trial] +fn a_measured_versioned_dock_reports_each_column_and_source_once() { + let VersionedDock { mut fixture, reported, .. } = versioned_dock(full(2)); + let settled = *reported.borrow().last().expect("the dock reported"); + assert_eq!(settled.0, 2, "the dock's two columns are placed"); + 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); + let reported = reported.borrow(); + assert!(reported.iter().all(|counts| *counts == settled), "every pass reports {settled:?}: {reported:?}"); +}