merge-fwd: item 5: FW15: the mock counts sub_rows calls; trial: a long layer list asks only for the rows in view

This commit is contained in:
aiongg
2026-11-16 12:43:51 +00:00
parent c081a17fed
commit 54f9aa1b0d
2 changed files with 60 additions and 1 deletions
+8 -1
View File
@@ -53,6 +53,7 @@ pub struct FakeLayers {
/// filter's Missing.
pub missing: Vec<u32>,
info_calls: Cell<usize>,
sub_rows_calls: Cell<usize>,
}
impl FakeLayers {
@@ -254,7 +255,7 @@ impl FakeLayers {
tree
}
/// `count` pixel layers at the top level, for the 10,000-row test; counts the `info` calls.
/// `count` pixel layers at the top level, for the long-list trials; counts the `info` and `sub_rows` calls.
pub fn flat(count: usize) -> Self {
let mut tree = Self::default();
for n in 0..count {
@@ -305,6 +306,11 @@ impl FakeLayers {
pub fn take_info_calls(&self) -> usize {
self.info_calls.replace(0)
}
/// How many times `sub_rows` was called since the last [`take_sub_rows_calls`](Self::take_sub_rows_calls).
pub fn take_sub_rows_calls(&self) -> usize {
self.sub_rows_calls.replace(0)
}
}
impl FakeLayers {
@@ -394,6 +400,7 @@ impl LayerTree for FakeLayers {
}
fn sub_rows(&self, id: &u32, group: SubRowGroup) -> Option<SubRows> {
self.sub_rows_calls.set(self.sub_rows_calls.get() + 1);
let layer = self.layer(id)?;
match group {
SubRowGroup::Effects => layer.effects.clone(),
+52
View File
@@ -386,3 +386,55 @@ fn a_stacking_key_on_a_selected_smart_filter_row_moves_the_filter() {
.collect();
assert_eq!(moves, [(SMART, SubRowGroup::SmartFilters, 0, 1)], "{events:?}");
}
/// `count` pixel layers above a closed group and a smart object with two Smart Filters shown, at a fixed revision;
/// returns the tree and the smart object.
fn long(count: usize) -> (FakeLayers, u32) {
let mut tree = FakeLayers::flat(count);
let group = tree.add(None, LayerInfo::new("Closed Group", LayerKind::Group), false);
tree.add(Some(group), LayerInfo::new("Inside", LayerKind::Pixel), false);
let mut smart = LayerInfo::new("Smart Object", LayerKind::SmartObject);
smart.has_smart_filters = true;
let id = tree.add(None, smart, false);
let layer = tree.layer_mut(id);
layer.effects_open = true;
layer.smart_filters = Some(SubRows::new(SubRow::new("Smart Filters"), vec![sub_row("Gaussian Blur"), sub_row("Sharpen")]));
tree.selection = LayerSelection::new(vec![1], Some(1), LayerPart::Pixels);
tree.revision = Some(1);
(tree, id)
}
/// FW15: a long layer list asks the app only for the rows in view: a settled frame makes as many `info` and
/// `sub_rows` calls for 2,000 layers as for 200, and an off-screen group or Smart Filter row lays out nothing.
/// Scrolled into view they show; a filter selected there stays selected after it scrolls away again.
#[trial]
fn a_long_layer_list_asks_only_for_the_rows_in_view() {
let mut calls = Vec::new();
for count in [200, 2_000] {
let (tree, smart) = long(count);
let (mut fixture, app) = rig(tree);
let _ = (app.borrow().tree.take_info_calls(), app.borrow().tree.take_sub_rows_calls());
fixture.frame(vec![]);
calls.push((app.borrow().tree.take_info_calls(), app.borrow().tree.take_sub_rows_calls()));
for name in ["Closed Group", "Smart Object", "Gaussian Blur", "Sharpen"] {
assert!(fixture.by_label(name).is_none(), "{count} layers: the off-screen row {name:?} lays out nothing");
}
let list = node(&fixture, "Layers").center();
fixture.frame(vec![pointer::moved(list)]);
fixture.frame(vec![pointer::wheel(-1.0e7)]).settle();
for name in ["Closed Group", "Smart Object", "Gaussian Blur", "Sharpen"] {
assert!(fixture.by_label(name).is_some(), "{count} layers: scrolled to the bottom, {name:?} shows");
}
let blur = node(&fixture, "Gaussian Blur");
fixture.click(&blur).settle();
let selected = Some(LayerRowKey::Filters(smart, Some(0)));
assert_eq!(app.borrow().tree.selection.sub_row, selected, "{count} layers: the filter is selected");
take(&app);
fixture.frame(vec![pointer::wheel(1.0e7)]).settle();
assert!(fixture.by_label("Gaussian Blur").is_none(), "{count} layers: scrolled back to the top");
assert!(take(&app).iter().all(|event| !matches!(event, LayersEvent::Select(_))), "{count} layers: scrolling selects nothing");
assert_eq!(app.borrow().tree.selection.sub_row, selected, "{count} layers: the filter stays selected");
}
assert_eq!(calls[0], calls[1], "a settled frame asks for as many rows for 2,000 layers as for 200 (info, sub_rows)");
}