LayersPanel::reveal takes the app's rule for closed groups: Groups::Open or Groups::Keep

Groups::Open opens the layer's closed groups and scrolls its row into view; Groups::Keep opens
nothing and scrolls to the row of its outermost closed group, the row that stands for the layer
(PhotoCraft's Move tool pick with "expand group on click" off).
This commit is contained in:
aiongg
2026-11-12 15:12:10 +00:00
parent 74e6a26b18
commit 009eafedae
4 changed files with 51 additions and 25 deletions
+9 -6
View File
@@ -6,10 +6,10 @@ use craft_ui::contract::{OpenChange, SweepApply};
use craft_ui::list::ThumbTarget;
use std::borrow::Cow;
use super::super::Session;
use super::super::context::PanelContext;
use super::super::events::LayerColumn;
use super::super::row::{EYE, LOCK};
use super::super::{Groups, Session};
use crate::ui::filter::LayerFilter;
use crate::ui::tree::{LayerInfo, LayerPart, LayerRowKey, LayerTree, SubRowGroup};
@@ -204,11 +204,14 @@ impl<Id: Clone> RevealPlan<Id> {
}
}
/// The reveal the app named: the layer, past its closed ancestors opened.
pub(in crate::ui::panel) fn reveal_plan<T: LayerTree>(tree: &T, named: Option<T::Id>) -> RevealPlan<T::Id> {
match named {
Some(id) => RevealPlan { opens: closed_ancestor_opens(tree, &id), target: Some(id) },
None => RevealPlan { target: None, opens: Vec::new() },
/// The reveal the app named: with [`Groups::Open`] the layer, past its closed ancestors opened; with [`Groups::Keep`]
/// its outermost closed ancestor, else the layer.
pub(in crate::ui::panel) fn reveal_plan<T: LayerTree>(tree: &T, named: Option<(T::Id, Groups)>) -> RevealPlan<T::Id> {
let Some((id, groups)) = named else { return RevealPlan { target: None, opens: Vec::new() } };
let opens = closed_ancestor_opens(tree, &id);
match groups {
Groups::Open => RevealPlan { target: Some(id), opens },
Groups::Keep => RevealPlan { target: Some(opens.into_iter().next().map_or(id, |open| open.key)), opens: Vec::new() },
}
}
+1 -1
View File
@@ -52,7 +52,7 @@ pub enum LayersEvent<K> {
color: Option<LabelColor>,
},
/// A group asked to open or close: its disclosure (Alt for every group), the arrow keys, a
/// screen reader, or a reveal ([`LayersPanel::reveal`](super::LayersPanel::reveal)). A
/// screen reader, or a reveal with its groups opened ([`LayersPanel::reveal`](super::LayersPanel::reveal)). A
/// view change: no undo step.
Open(OpenChange<K>),
/// A layer's effects and Smart Filter rows asked to open or close: the `fx` disclosure, or the
+15 -5
View File
@@ -173,11 +173,20 @@ pub struct LayersPanel<'a, T: LayerTree> {
find_name: bool,
row_menu: Option<Box<RowMenu<'a, T::Id>>>,
trailing: Option<Box<dyn TrailingCell<T::Id> + 'a>>,
reveal: Option<T::Id>,
reveal: Option<(T::Id, Groups)>,
rename: Option<T::Id>,
document: Option<u64>,
}
/// What a reveal ([`LayersPanel::reveal`]) does with the closed groups that hold the layer.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Groups {
/// They open ([`LayersEvent::Open`]) and the layer's own row scrolls into view.
Open,
/// They stay closed and the row of the outermost one scrolls into view: the row that stands for the layer.
Keep,
}
/// What [`LayersPanel::show`] returns.
#[derive(Debug)]
#[must_use = "the app applies the panel's events"]
@@ -304,10 +313,11 @@ impl<'a, T: LayerTree> LayersPanel<'a, T> {
self
}
/// Reveals `layer` this pass: its closed groups open ([`LayersEvent::Open`]) and its row scrolls into view when it
/// is not wholly in view. The app calls it in the pass its active layer changes.
pub fn reveal(mut self, layer: T::Id) -> Self {
self.reveal = Some(layer);
/// Reveals `layer` this pass: its row, or with [`Groups::Keep`] the row of its outermost closed group, scrolls
/// into view when it is not wholly in view; with [`Groups::Open`] its closed groups open ([`LayersEvent::Open`]).
/// The app calls it in the pass its active layer changes, with the layer and its own rule for the groups.
pub fn reveal(mut self, layer: T::Id, groups: Groups) -> Self {
self.reveal = Some((layer, groups));
self
}
+26 -13
View File
@@ -1,8 +1,8 @@
//! `LayersPanel` reveals: the layer the app names scrolls into view with its closed groups opened, and each document
//! keeps its own scroll position.
//! `LayersPanel` reveals: the layer the app names scrolls into view, its closed groups opened or kept, and each
//! document keeps its own scroll position.
use craft_layers::ui::mock::FakeLayers;
use craft_layers::ui::panel::{LayersEvent, LayersPanel};
use craft_layers::ui::panel::{Groups, LayersEvent, LayersPanel};
use craft_layers::ui::tree::{LayerInfo, LayerKind, LayerPart, LayerSelection};
use craft_ui::testing::{Fixture, trial};
use egui::{Rect, Vec2};
@@ -52,7 +52,7 @@ struct Rig {
docs: Vec<Shared<FakeLayers>>,
/// The document shown, by its position in `docs`.
shown: Rc<Cell<usize>>,
reveal: Rc<Cell<Option<u32>>>,
reveal: Rc<Cell<Option<(u32, Groups)>>>,
seen: Shared<Vec<LayersEvent<u32>>>,
}
@@ -62,7 +62,7 @@ fn rig(docs: Vec<FakeLayers>) -> Rig {
let docs: Vec<Shared<FakeLayers>> = docs.into_iter().map(|tree| Rc::new(RefCell::new(tree))).collect();
let keyed = docs.len() > 1;
let shown: Rc<Cell<usize>> = Rc::default();
let reveal: Rc<Cell<Option<u32>>> = Rc::default();
let reveal: Rc<Cell<Option<(u32, Groups)>>> = Rc::default();
let seen: Shared<Vec<LayersEvent<u32>>> = Rc::default();
let (trees, which, asked, sink) = (docs.clone(), Rc::clone(&shown), Rc::clone(&reveal), Rc::clone(&seen));
let mut fixture = Fixture::new(move |ui| {
@@ -73,8 +73,8 @@ fn rig(docs: Vec<FakeLayers>) -> Rig {
if keyed {
panel = panel.document(which.get());
}
if let Some(id) = asked.take() {
panel = panel.reveal(id);
if let Some((id, groups)) = asked.take() {
panel = panel.reveal(id, groups);
}
panel.show(ui).events
};
@@ -107,9 +107,9 @@ impl Rig {
}
/// One frame that reveals `id`, with what it reported; asserts that the frame ran once and measured no row twice.
fn reveal(&mut self, id: u32) -> Vec<LayersEvent<u32>> {
fn reveal(&mut self, id: u32, groups: Groups) -> Vec<LayersEvent<u32>> {
self.seen.borrow_mut().clear();
self.reveal.set(Some(id));
self.reveal.set(Some((id, groups)));
self.fixture.idle(1);
assert_eq!(self.fixture.passes(), 1, "a reveal runs its frame once");
let measures = craft_ui::runtime::measure::row_measures(self.fixture.ctx());
@@ -132,7 +132,7 @@ fn a_revealed_layer_opens_its_groups_and_scrolls_into_view() {
assert!(rig.fixture.by_label("Inner").is_none(), "Inner is hidden in its closed group");
rig.select(inner);
let events = rig.reveal(inner);
let events = rig.reveal(inner, Groups::Open);
assert!(matches!(events.as_slice(), [LayersEvent::Open(change)] if change.key == group && change.open), "the closed group opens: {events:?}");
assert!(rig.in_view("Inner"), "Inner is scrolled wholly into view");
assert!(!rig.in_view("Stack 29"), "the top scrolled away");
@@ -140,21 +140,34 @@ fn a_revealed_layer_opens_its_groups_and_scrolls_into_view() {
assert!(rig.in_view("Inner") && rig.seen.borrow().is_empty(), "the next passes keep the place and report nothing");
rig.select(top);
rig.reveal(top);
rig.reveal(top, Groups::Open);
assert!(rig.in_view("Stack 29"), "scrolled back to the top");
let before = rig.row("Stack 29");
let events = rig.reveal(top + 1);
let events = rig.reveal(top + 1, Groups::Open);
assert!(events.is_empty(), "a reveal of a layer in view reports nothing: {events:?}");
assert_eq!(rig.row("Stack 29"), before, "no scroll for a row in view");
}
/// With the groups kept, the reveal opens nothing and scrolls the closed group's row into view.
#[trial]
fn a_reveal_that_keeps_the_groups_shows_the_closed_groups_row() {
let (tree, Tall { group, inner, .. }) = tall();
let mut rig = rig(vec![tree]);
rig.select(inner);
let events = rig.reveal(inner, Groups::Keep);
assert!(events.is_empty(), "no group opens: {events:?}");
assert!(!rig.docs[0].borrow_mut().layer_mut(group).open, "the group stays closed");
assert!(rig.in_view("Group"), "the closed group's row is scrolled wholly into view");
assert!(rig.fixture.by_label("Inner").is_none(), "Inner stays hidden");
}
/// Each document keeps its own scroll position: a short document shown between doesn't move the tall one's.
#[trial]
fn each_document_keeps_its_scroll_position() {
let (tree, Tall { inner, .. }) = tall();
let mut rig = rig(vec![tree, short()]);
rig.select(inner);
rig.reveal(inner);
rig.reveal(inner, Groups::Open);
rig.fixture.settle();
let at = rig.row("Inner");
assert!(rig.in_view("Inner"), "the tall document is scrolled to Inner");