Layers panel: an effects or Smart Filter row can be selected on its own

LayerSelection.sub_row is the sub-row the app keeps selected: the list highlights it beside its layer and gives it
the lead. LayerSelect.row names the sub-row a click, right-click or selection key picked. The Background's doc names
ActivateOn::Row, which a double click on its name reports.
This commit is contained in:
aiongg
2026-11-12 14:32:51 +00:00
parent 36de7bed8d
commit f409970b13
6 changed files with 46 additions and 19 deletions
+7 -2
View File
@@ -47,8 +47,13 @@ pub(super) fn show_body<T: LayerTree>(
let tree = cx.tree;
let order = rows.keys();
let mut selection = list_selection(cx, session);
let reveal_key =
reveal.target.clone().filter(|id| order.iter().any(|key| matches!(key, LayerRowKey::Layer(k) if k == id))).map(LayerRowKey::Layer);
// The reveal moves the lead, so a layer revealed with a sub-row of its own selected reveals that row.
let reveal_key = reveal.target.clone().filter(|id| order.iter().any(|key| matches!(key, LayerRowKey::Layer(k) if k == id))).map(|id| {
match &cx.selection.sub_row {
Some(row) if *row.layer() == id && order.contains(row) => row.clone(),
_ => LayerRowKey::Layer(id),
}
});
let eye = cx.visibility_key.map_or(ToggleColumn::sweepable(), |key| ToggleColumn::sweepable().key(key));
let mut columns = vec![ColumnSpec::new(EYE, Label::Empty, ColumnWidth::Controls(1.0)).kind(ColumnKind::Toggle(eye)).icon(IconId::new("eye"))];
+12 -7
View File
@@ -49,10 +49,11 @@ pub(super) fn map_events<T: LayerTree>(
for event in list {
match event {
CollectionEvent::Selection(change) => {
let (row, mapped) = match change {
SelectionChange::Set(keys) => (keys.last().cloned(), SelectionChange::Set(layers_of(&keys))),
SelectionChange::Toggle(key) => (Some(key.clone()), SelectionChange::Toggle(key.layer().clone())),
SelectionChange::Clear => (None, SelectionChange::Clear),
// A set made on an effects or Smart Filter row names that row; a toggle acts on its layer only.
let (row, set, mapped) = match change {
SelectionChange::Set(keys) => (keys.last().cloned(), true, SelectionChange::Set(layers_of(&keys))),
SelectionChange::Toggle(key) => (Some(key.clone()), false, SelectionChange::Toggle(key.layer().clone())),
SelectionChange::Clear => (None, false, SelectionChange::Clear),
_ => continue,
};
let mut part = None;
@@ -68,7 +69,11 @@ pub(super) fn map_events<T: LayerTree>(
}
part = Some(hit);
}
events.push(LayersEvent::Select(LayerSelect::new(mapped, part)));
let mut select = LayerSelect::new(mapped, part);
if set && let Some(row) = &row {
select = select.on_row(row);
}
events.push(LayersEvent::Select(select));
}
CollectionEvent::Activate(row) => {
let on = clicks
@@ -100,7 +105,7 @@ pub(super) fn map_events<T: LayerTree>(
session.menu = Some(OpenMenu::Eye { rows, current });
} else if plain {
if !selected {
events.push(LayersEvent::Select(LayerSelect::new(SelectionChange::Set(vec![layer.clone()]), None)));
events.push(LayersEvent::Select(LayerSelect::new(SelectionChange::Set(vec![layer.clone()]), None).on_row(&request.key)));
session.produced = vec![layer.clone()];
session.anchor = Some(LayerRowKey::Layer(layer));
}
@@ -154,7 +159,7 @@ pub(super) fn map_events<T: LayerTree>(
events.push(if thumb_click_replaces_select(part, *mods, &info) {
LayersEvent::ThumbClick { layer: row.layer().clone(), part, mods: *mods }
} else {
LayersEvent::Select(LayerSelect::new(SelectionChange::Set(vec![row.layer().clone()]), Some(part)))
LayersEvent::Select(LayerSelect::new(SelectionChange::Set(vec![row.layer().clone()]), Some(part)).on_row(row))
});
}
}
+6 -4
View File
@@ -224,11 +224,13 @@ pub(in crate::ui::panel) fn reveal_plan<T: LayerTree>(
RevealPlan { target: active.cloned().filter(|_| changed), opens }
}
/// The tree's selection as the list holds it: the selected layers, the active one as the lead, and the
/// anchor the last pick left while the selection is still what that pick produced.
/// The tree's selection as the list holds it: the selected layers and the sub-row selected on its own, that row or
/// else the active layer as the lead, and the anchor the last pick left while the selection is still what that pick
/// produced.
pub(super) fn list_selection<T: LayerTree>(cx: &PanelContext<'_, T>, session: &Session<T::Id>) -> Selection<LayerRowKey<T::Id>> {
let items: Vec<LayerRowKey<T::Id>> = cx.selection.layers.iter().cloned().map(LayerRowKey::Layer).collect();
let lead = cx.selection.active.clone().map(LayerRowKey::Layer);
let mut items: Vec<LayerRowKey<T::Id>> = cx.selection.layers.iter().cloned().map(LayerRowKey::Layer).collect();
items.extend(cx.selection.sub_row.clone());
let lead = cx.selection.sub_row.clone().or_else(|| cx.selection.active.clone().map(LayerRowKey::Layer));
let same = session.produced.len() == cx.selection.layers.len() && session.produced.iter().all(|id| cx.selection.layers.contains(id));
let anchor = session.anchor.clone().filter(|_| same).or_else(|| lead.clone());
Selection::new(items, lead, anchor)
+14 -2
View File
@@ -145,12 +145,24 @@ pub struct LayerSelect<Id> {
/// The thumbnail the click landed on, which becomes the target; `None` elsewhere on the row
/// and for keys (the target stays).
pub part: Option<LayerPart>,
/// The effects or Smart Filter row a click, a right-click or a selection key picked, which the app may select on
/// its own ([`LayerSelection::sub_row`](crate::ui::tree::LayerSelection::sub_row)); `None` on a layer row.
pub row: Option<LayerRowKey<Id>>,
}
impl<Id> LayerSelect<Id> {
/// A selection change with an optional thumbnail target.
/// A selection change with an optional thumbnail target, made on a layer row.
pub fn new(change: SelectionChange<Id>, part: Option<LayerPart>) -> Self {
Self { change, part }
Self { change, part, row: None }
}
/// The change made on `row`; a layer row leaves [`row`](Self::row) `None`.
pub fn on_row(mut self, row: &LayerRowKey<Id>) -> Self
where
Id: Clone,
{
self.row = (!row.is_layer()).then(|| row.clone());
self
}
}
+1 -1
View File
@@ -16,7 +16,7 @@ use craft_ui::primitives::IconSpec;
/// The sample tree with the masked layer active and its mask targeted.
fn selected() -> FakeLayers {
let mut tree = FakeLayers::sample();
tree.selection = LayerSelection { layers: vec![3], active: Some(3), target: LayerPart::LayerMask };
tree.selection = LayerSelection::new(vec![3], Some(3), LayerPart::LayerMask);
tree
}
+6 -3
View File
@@ -118,7 +118,7 @@ pub struct LayerInfo {
/// The layer's locks: any of them shows the lock indicator.
pub locks: LayerLocks,
/// The Background: it can't move below another layer, isn't renamed in place (a double click
/// on its name reports [`ActivateOn::Name`](super::panel::ActivateOn::Name)) and greys blend,
/// on its name reports [`ActivateOn::Row`](super::panel::ActivateOn::Row)) and greys blend,
/// opacity and fill.
pub background: bool,
/// Whether a double click or F2 renames the layer in place.
@@ -317,18 +317,21 @@ pub struct LayerSelection<Id> {
pub active: Option<Id>,
/// The active layer's part edits go to: its thumbnail gets the target brackets.
pub target: LayerPart,
/// An effects or Smart Filter row selected on its own (PhotoCraft's selected Smart Filter, which Delete removes):
/// highlighted beside its layer's row and holding the lead. `None` when only layers are selected.
pub sub_row: Option<LayerRowKey<Id>>,
}
impl<Id> LayerSelection<Id> {
/// The `layers` selected, `active` the one the property rows show, edits going to `target`.
pub fn new(layers: Vec<Id>, active: Option<Id>, target: LayerPart) -> Self {
Self { layers, active, target }
Self { layers, active, target, sub_row: None }
}
}
impl<Id> Default for LayerSelection<Id> {
fn default() -> Self {
Self { layers: Vec::new(), active: None, target: LayerPart::Pixels }
Self { layers: Vec::new(), active: None, target: LayerPart::Pixels, sub_row: None }
}
}