LayersPanel effects keys: Shift+Left and Right are no moves in stacked rows, and the panel takes Show and Hide Effects on its own scope

This commit is contained in:
aiongg
2026-11-12 14:32:40 +00:00
parent bd04ee8b5e
commit 3a58d2262f
7 changed files with 94 additions and 19 deletions
+13
View File
@@ -39,6 +39,9 @@ pub struct KeyRole {
/// The component acts on Delete and Backspace (text edits, deleting a selection): they reach it as
/// `Intent::Delete`. Any other role leaves them to the command scope chain.
pub deletes: bool,
/// A collection of rows stacked one per line (a list or tree, no cells): Shift with Left or Right is no move, so it
/// stays a shortcut candidate (Photoshop's Show and Hide Effects in the Layers panel).
pub stacked: bool,
/// A collection that leaves its arrow keys to the component around it (`ItemKeys::Owner`): they are no moves
/// of this role.
pub owner_arrows: bool,
@@ -63,6 +66,7 @@ impl KeyRole {
text: false,
moves: false,
deletes: false,
stacked: false,
owner_arrows: false,
home_row: 0,
}
@@ -140,6 +144,12 @@ impl KeyRole {
self
}
/// Shift with Left or Right is no move.
pub const fn stacked(mut self, on: bool) -> Self {
self.stacked = on;
self
}
/// The arrow keys are the enclosing component's, not this role's moves.
pub const fn owner_arrows(mut self, on: bool) -> Self {
self.owner_arrows = on;
@@ -269,6 +279,9 @@ pub fn intent(os: Os, key: Key, mods: Mods, role: KeyRole) -> Option<Intent> {
if role.owner_arrows && is_arrow(key) {
return None;
}
if role.stacked && mods.shift && matches!(key, Key::Left | Key::Right) {
return None;
}
movement(mac, key, mods, role)
}
+15
View File
@@ -28,3 +28,18 @@ fn ctrl_space_toggles_the_pick_only_in_a_multi_select_collection() {
}
assert_eq!(intent(Os::Mac, Key::Space, Mods::CMD, multi), None, "Cmd+Space stays the system's on macOS");
}
/// Shift with Left or Right is no move in rows stacked one per line, so the app's keys get it; a grid keeps it as an
/// extending move.
#[test]
fn shift_left_and_right_are_no_moves_in_stacked_rows() {
let grid = KeyRole::new().space(true).moves(true);
let stacked = grid.stacked(true);
for os in [Os::Mac, Os::Windows] {
for key in [Key::Left, Key::Right] {
assert_eq!(intent(os, key, Mods::SHIFT, stacked), None, "{os:?} {key:?}: stacked rows");
assert!(matches!(intent(os, key, Mods::SHIFT, grid), Some(Intent::Move(_, mods)) if mods.extend), "{os:?} {key:?}: a grid extends");
assert!(matches!(intent(os, key, Mods::NONE, stacked), Some(Intent::Move(..))), "{os:?} {key:?}: plain arrows still move");
}
}
}
+29 -14
View File
@@ -1,4 +1,4 @@
//! The panel's commands, its panel-menu rows, the row menu and the eye's label-colour menu.
//! The panel's commands and keys, its panel-menu rows, the row menu and the eye's label-colour menu.
use craft_theme::{LabelColor, Srgba};
use craft_ui::contract::{CommandSet, Entry};
@@ -17,9 +17,9 @@ use crate::ui::options::LayersSettings;
use crate::ui::thumbs::ThumbContents;
use crate::ui::tree::LayerTree;
/// The commands of the Layers panel: its panel-menu rows, the stacking keys and the effects keys.
/// The commands of the Layers panel: its panel-menu rows and the stacking keys.
///
/// They are the app's commands. Settings commands run with
/// They are the app's commands; the effects keys are the panel's own ([`LayersPanelKeys`]). Settings commands run with
/// [`settings_action`](LayersPanelCommands::settings_action); the others become events with
/// [`event`](LayersPanelCommands::event), which the app applies like the panel's own.
#[derive(Clone, Copy, Debug, PartialEq, Eq, CommandSet)]
@@ -50,6 +50,15 @@ pub enum LayersPanelCommands {
/// Move the selected layers to the bottom.
#[command(label = "Send to Back", default = "Cmd+Shift+[")]
MoveToBottom,
}
/// The effects keys of the Layers panel, on the panel's own scope: they work while focus is anywhere in the panel, and
/// the panel reports them as [`LayersEvent::FxOpen`]. In the rows they are Shift with Left and Right, which the list
/// leaves to the panel.
#[derive(Clone, Copy, Debug, PartialEq, Eq, CommandSet)]
#[command(prefix = "layersPanel", scope = "layersPanel")]
#[non_exhaustive]
pub enum LayersPanelKeys {
/// Open the effects and Smart Filter rows of the active layer.
#[command(label = "Show Effects", default = "Shift+Right")]
ShowEffects,
@@ -97,27 +106,33 @@ impl LayersPanelCommands {
}
}
/// The event a stacking or effects command makes over `tree`'s selection; `None` when there is
/// nothing to do. `label` names the undo step of a move.
/// The event a stacking command makes over `tree`'s selection; `None` when there is nothing to do. `label` names
/// the undo step of a move.
pub fn event<T: LayerTree>(self, tree: &T, label: impl Into<Arc<str>>) -> Option<LayersEvent<T::Id>> {
let fx = |open: bool, all: bool| {
let layer = tree.selection().active?;
let info = tree.info(&layer);
(info.has_effects || info.has_smart_filters).then_some(LayersEvent::FxOpen { layer, open, all })
};
match self {
LayersPanelCommands::MoveUp | LayersPanelCommands::MoveDown | LayersPanelCommands::MoveToTop | LayersPanelCommands::MoveToBottom => {
stacking_event(tree, self, label.into())
}
LayersPanelCommands::ShowEffects => fx(true, false),
LayersPanelCommands::HideEffects => fx(false, false),
LayersPanelCommands::ShowAllEffects => fx(true, true),
LayersPanelCommands::HideAllEffects => fx(false, true),
_ => None,
}
}
}
impl LayersPanelKeys {
/// The event the key makes over `tree`'s active layer; `None` when it has no effects or Smart Filters.
pub(super) fn event<T: LayerTree>(self, tree: &T) -> Option<LayersEvent<T::Id>> {
let (open, all) = match self {
LayersPanelKeys::ShowEffects => (true, false),
LayersPanelKeys::HideEffects => (false, false),
LayersPanelKeys::ShowAllEffects => (true, true),
LayersPanelKeys::HideAllEffects => (false, true),
};
let layer = tree.selection().active?;
let info = tree.info(&layer);
(info.has_effects || info.has_smart_filters).then_some(LayersEvent::FxOpen { layer, open, all })
}
}
/// The rows the panel adds to its panel menu: Filter Options, Panel Options, Collapse All Groups and
/// Clip Thumbnails to Layer Bounds.
pub fn panel_rows(words: &LayersPanelWords) -> Vec<PanelRow> {
+10 -4
View File
@@ -18,11 +18,11 @@ pub use events::{
ActivateOn, LayerColumn, LayerDrop, LayerMove, LayerPosition, LayerSelect, LayerToggle, LayersEvent, MenuTarget, RowTransfer, SubRowMove,
};
pub use footer::{LayersFooterAction, LayersFooterButton};
pub use menu::{LayersMenuAction, LayersPanelCommands, panel_rows};
pub use menu::{LayersMenuAction, LayersPanelCommands, LayersPanelKeys, panel_rows};
use std::cell::RefCell;
use craft_ui::contract::{Bind, NoValue, Outcome, ShowContainer as _};
use craft_ui::contract::{Bind, CommandSet as _, Commands as _, NoValue, Outcome, ShowContainer as _};
use craft_ui::layout_components::Stack;
use craft_ui::list::ListWords;
use craft_ui::primitives::textures::{ThumbSource, Thumbnails};
@@ -138,8 +138,10 @@ impl<Id> Default for Session<Id> {
/// - **Keys**: the rows are one Tab stop (the list's keys: arrows, Home, End and Page with Shift;
/// Cmd/Ctrl moves the lead alone; Left and Right close and open a group, Alt for every group;
/// Cmd/Ctrl+] and [ move the selected layers, Shift to the ends; Enter activates; F2 renames; the app's
/// [`visibility_key`](Self::visibility_key) flips the selected layers' eyes). The panel's
/// commands ([`LayersPanelCommands`]) are the app's: the stacking keys and the effects keys.
/// [`visibility_key`](Self::visibility_key) flips the selected layers' eyes). Shift+Right and Shift+Left open and
/// close the active layer's effects, Alt for every layer ([`LayersPanelKeys`], on the panel's scope, so they work
/// wherever focus is in the panel). The panel-menu rows and the stacking keys outside the rows are the app's
/// commands ([`LayersPanelCommands`]).
/// - **Pointer**: clicks select (Cmd/Ctrl toggles, Shift extends, the empty space clears), the eye
/// and lock columns sweep, Alt-click on an eye shows only that layer, the eye's right-click opens
/// its colour menu, a modified thumbnail click is a [`LayersEvent::ThumbClick`], double clicks
@@ -297,6 +299,7 @@ impl<'a, T: LayerTree> LayersPanel<'a, T> {
let shown = Stack::new()
.fill()
.command_scope(LayersPanelKeys::SCOPE)
.header(|ui, stack| {
let held = |filter: &mut Option<Bind<'_, LayerFilter>>, stack: &mut craft_ui::contract::BodyCx<'_>| -> LayerFilter {
match filter.as_mut() {
@@ -343,6 +346,9 @@ impl<'a, T: LayerTree> LayersPanel<'a, T> {
let menus = show_row_menus(ui, &cx, &body.response, row_menu.as_deref(), session);
let mut reported = body.events;
reported.extend(menus);
while let Some((key, _)) = stack.take_command::<LayersPanelKeys>() {
reported.extend(key.event(tree));
}
reported
});
// Only the real run's result comes back, so the reveal's opens and the list's events are reported once.
+17 -1
View File
@@ -6,7 +6,7 @@ use craft_layers::ui::mock::FakeLayers;
use craft_layers::ui::panel::{LayerColumn, LayerDrop, LayerPosition, LayerToggle, LayersEvent, LayersPanel};
use craft_layers::ui::tree::{LayerKind, LayerPart, LayerSelection};
use craft_ui::testing::{Fixture, Target, pointer, trial};
use egui::{Pos2, Ui, Vec2};
use egui::{Key, Modifiers, Pos2, Ui, Vec2};
use std::cell::RefCell;
use std::rc::Rc;
@@ -226,3 +226,19 @@ fn drop_zones_into_before_and_after_the_last_row() {
let below = Pos2::new(last.rect.center().x, last.rect.bottom() + 20.0);
assert_eq!(dropped(&mut fixture, &app, from, below), Some((vec![8], 9, LayerPosition::After, false)), "the space below the last row");
}
/// With the rows focused on a layer that has effects, Shift+Right opens its effects and Shift+Left closes them.
#[trial]
fn shift_right_and_left_open_and_close_the_active_layers_effects() {
let (mut fixture, app) = rig(FakeLayers::sample());
let styled = row(&fixture, "Styled");
fixture.click(&styled).idle(2);
take(&app);
let fx = |events: Vec<LayersEvent<u32>>| -> Vec<(u32, bool)> {
events.into_iter().filter_map(|event| if let LayersEvent::FxOpen { layer, open, .. } = event { Some((layer, open)) } else { None }).collect()
};
fixture.key(Key::ArrowRight, Modifiers::SHIFT).idle(2);
assert_eq!(fx(take(&app)), [(7, true)], "Shift+Right opens the effects");
fixture.key(Key::ArrowLeft, Modifiers::SHIFT).idle(2);
assert_eq!(fx(take(&app)), [(7, false)], "Shift+Left closes them");
}
@@ -61,6 +61,7 @@ impl<C: Collection> ShapeHooks<C> for ItemsHooks<'_, '_, C> {
.moves(true)
.deletes(props.deletable)
.owner_arrows(props.item_keys == crate::contract::collection::ItemKeys::Owner)
.stacked(self.stacked(comp))
.home_row(self.layout.as_ref().map_or(0, |layout| layout.first_navigable()))
}
@@ -240,6 +240,15 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
pub(super) fn selects_cells(comp: &C) -> bool {
Self::select_mode(comp) == SelectMode::Cells
}
/// Whether the rows stack one per line down the collection: a list or tree laid out vertically whose selection is
/// not of cells, so Left and Right only open and close.
pub(super) fn stacked(&self, comp: &C) -> bool {
let cells = Self::selects_cells(comp) && self.layout.as_ref().is_some_and(|layout| layout.column_count() > 0);
comp.items().overflow != craft_behavior::Axis::X
&& !cells
&& self.layout.as_ref().is_some_and(|layout| matches!(layout.nav(), craft_behavior::NavShape::Flat | craft_behavior::NavShape::Tree))
}
}
/// Whether the move is the one that enters a row's children.