FooterBar: lay panel actions out from the reading end

The first action given sits at the end edge, as the old PanelFooter and
Photoshop's panel footers place them; a start group keeps its order.
Callers give their actions from the end edge: Layers, Channels,
Actions, Pages, the styles panel, the preset footer and MediaBin.
The filter gallery keeps Move Up and Move Down at the start edge.
LinkList's actions read as in the old: the menu at the start edge,
Relink at the end edge.
This commit is contained in:
aiongg
2026-11-12 14:32:48 +00:00
parent 8cb7ec3f02
commit 8703a667ba
11 changed files with 109 additions and 92 deletions
+14 -14
View File
@@ -11,16 +11,16 @@ use super::body::{Body, delete_event};
use super::panel::{ActionSelection, ActionsEvent, ActionsPanelState};
use crate::actions::ActionList;
// Reading order of the footer's buttons.
const STOP: usize = 0;
const RECORD: usize = 1;
const PLAY: usize = 2;
// The footer's buttons from its end edge.
const BUTTON_MODE: usize = 0;
const DELETE: usize = 1;
const NEW_ACTION: usize = 2;
const NEW_SET: usize = 3;
const NEW_ACTION: usize = 4;
const DELETE: usize = 5;
const BUTTON_MODE: usize = 6;
const PLAY: usize = 4;
const RECORD: usize = 5;
const STOP: usize = 6;
/// The footer under the list, in this order, each a Tab stop with its name and tooltip:
/// The footer under the list, in this order from the start edge, each a Tab stop with its name and tooltip:
///
/// | Button | Icon | Reports | Enabled |
/// |---|---|---|---|
@@ -46,15 +46,15 @@ pub(super) fn show_footer(ui: &mut Ui, body: &Body<'_>, state: &mut ActionsPanel
record = record.tone(Tone::Bad);
}
let actions = [
FooterAction::new(icon("square"), words.stop.clone()).enabled(hosted && !idle),
record,
FooterAction::new(icon("play"), words.play.clone()).enabled(hosted && idle && target.is_some()),
FooterAction::new(icon("new_folder"), words.new_set.clone()).enabled(idle),
FooterAction::new(icon("plus"), words.new_action.clone()).enabled(hosted && idle),
FooterAction::new(icon("toggle_right"), words.button_mode.clone()).enabled(idle).pressed(state.settings.button_mode),
FooterAction::new(icon("trash"), words.delete.clone()).enabled(delete.is_some()).takes_drops_disabled(true).accepts_drops(
move |drag: &ListDrag<ActionSelection>| !playing && drag.list == list_id && delete_event(&drag.grabbed, recording.is_some()).is_some(),
),
FooterAction::new(icon("toggle_right"), words.button_mode.clone()).enabled(idle).pressed(state.settings.button_mode),
FooterAction::new(icon("plus"), words.new_action.clone()).enabled(hosted && idle),
FooterAction::new(icon("new_folder"), words.new_set.clone()).enabled(idle),
FooterAction::new(icon("play"), words.play.clone()).enabled(hosted && idle && target.is_some()),
record,
FooterAction::new(icon("square"), words.stop.clone()).enabled(hosted && !idle),
];
let out = FooterBar::actions(actions).show_footer(ui);
// The footer runs twice per pass: the sizing pass measures it and must report nothing.
+13 -10
View File
@@ -13,6 +13,9 @@ use egui::Ui;
use super::list::NAME;
use super::{BinEvent, BinState, BinView, BinWords};
/// New Bin's place among the footer's actions: the first, at the end edge.
const NEW_BIN: usize = 0;
/// A pick in the Sort Icons menu.
#[derive(Clone, Debug, PartialEq)]
enum SortPick {
@@ -25,8 +28,8 @@ fn sortable(columns: &[ColumnSpec], words: &BinWords) -> Vec<ColumnSpec> {
if columns.is_empty() { vec![ColumnSpec::new(NAME, words.name.clone(), craft_behavior::ColumnWidth::fill(1.0))] } else { columns.to_vec() }
}
/// Draws the footer: the view `Segmented` (List, Icon, Freeform), a `ThumbnailSlider`, then the actions: the
/// host's, Sort Icons (Icon and Freeform views) and New Bin. Returns the footer's events.
/// Draws the footer: the view `Segmented` (List, Icon, Freeform), a `ThumbnailSlider`, then the actions, from the end
/// edge: New Bin, the host's, Sort Icons (Icon and Freeform views). Returns the footer's events.
pub(super) fn footer<K: TextureKey>(
ui: &mut Ui,
state: &BinState<K>,
@@ -38,13 +41,13 @@ pub(super) fn footer<K: TextureKey>(
let mut events = Vec::new();
let mut view = state.settings.view;
let mut zoom_value = state.settings.zoom;
let mut all: Vec<FooterAction> = actions.to_vec();
let mut all = vec![FooterAction::new(IconId::new("new_folder"), words.new_bin.clone())];
all.extend_from_slice(actions);
let sort_at = (view != BinView::List).then(|| {
all.push(FooterAction::new(IconId::new("more"), words.sort_icons.clone()).popup(PopupKind::Menu));
all.len() - 1
});
let new_bin = all.len();
all.push(FooterAction::new(IconId::new("new_folder"), words.new_bin.clone()));
let host = |at: usize| at.checked_sub(NEW_BIN + 1).filter(|action| *action < actions.len());
let modes = [
Entry::new(BinView::List, words.list_view.clone()).icon(IconId::new("list")),
@@ -64,14 +67,14 @@ pub(super) fn footer<K: TextureKey>(
events.push(BinEvent::Zoom(event));
}
if let Some(drop) = &bar.dropped {
if let Some(drag) = drop.payload::<ListDrag<K>>() {
events.push(BinEvent::FooterDrop { action: drop.index, keys: drag.keys.clone() });
if let (Some(drag), Some(action)) = (drop.payload::<ListDrag<K>>(), host(drop.index)) {
events.push(BinEvent::FooterDrop { action, keys: drag.keys.clone() });
}
} else if let Some(at) = bar.picked {
if at == new_bin {
if at == NEW_BIN {
events.push(BinEvent::NewBin);
} else if Some(at) != sort_at {
events.push(BinEvent::Footer { action: at });
} else if let Some(action) = host(at) {
events.push(BinEvent::Footer { action });
}
}
if let Some(response) = sort_at.and_then(|at| bar.responses.get(at)) {
+2 -1
View File
@@ -520,7 +520,8 @@ where
self
}
/// The host's footer buttons, after the view buttons and slider. An action that takes drops reports
/// The host's footer buttons, placed from the end edge as `FooterBar::actions` places them, after New Bin: the
/// first given sits next to New Bin. An action that takes drops reports
/// `FooterDrop` with the dragged keys when it was built with `accepts_drops::<ListDrag<K>>`.
pub fn footer_actions(mut self, actions: impl IntoIterator<Item = FooterAction>) -> Self {
self.actions = actions.into_iter().collect();
+8 -8
View File
@@ -44,11 +44,11 @@ pub(super) fn accepts_footer_drop(button: ChannelsFooterButton, kind: ChannelKin
}
}
// Photoshop's order from the leading end.
const LOAD: usize = 0;
const SAVE: usize = 1;
const NEW: usize = 2;
const DELETE: usize = 3;
// Photoshop's order from the end edge.
const DELETE: usize = 0;
const NEW: usize = 1;
const SAVE: usize = 2;
const LOAD: usize = 3;
fn button_at(at: usize) -> Option<ChannelsFooterButton> {
match at {
@@ -79,13 +79,13 @@ pub(super) fn show_footer<K: Clone + Eq + Hash + Debug + Send + Sync + 'static>(
let takes = |button: ChannelsFooterButton| move |drag: &ChannelDrag<K>| drag.list == list && accepts_footer_drop(button, drag.kind);
let icon = |name: &'static str| IconSpec::svg(IconId::new(name));
let actions = [
FooterAction::new(icon("ellipse_dashed"), words.load_selection.clone()).accepts_drops(takes(ChannelsFooterButton::LoadSelection)),
FooterAction::new(icon("rect_dashed"), words.save_selection.clone()),
FooterAction::new(icon("plus"), words.new.clone()).accepts_drops(takes(ChannelsFooterButton::New)),
FooterAction::new(icon("trash"), words.delete.clone())
.enabled(delete_enabled)
.takes_drops_disabled(true)
.accepts_drops(takes(ChannelsFooterButton::Delete)),
FooterAction::new(icon("plus"), words.new.clone()).accepts_drops(takes(ChannelsFooterButton::New)),
FooterAction::new(icon("rect_dashed"), words.save_selection.clone()),
FooterAction::new(icon("ellipse_dashed"), words.load_selection.clone()).accepts_drops(takes(ChannelsFooterButton::LoadSelection)),
];
let out = FooterBar::actions(actions).show_footer(ui);
let mut events = Vec::new();
@@ -150,18 +150,19 @@ impl<'a> EffectStack<'a> {
_ => {}
}
}
// Move Up and Move Down at the start edge, then Delete and New from the end edge, as PhotoCraft lays them out.
let actions = [
FooterAction::new(IconId::new("chevron_up"), words.move_up.clone()).enabled(current + 1 < count),
FooterAction::new(IconId::new("chevron_down"), words.move_down.clone()).enabled(current > 0),
FooterAction::new(IconId::new("new_layer"), words.new_layer.clone()),
FooterAction::new(IconId::new("trash"), words.delete_layer.clone()).enabled(count > 1),
FooterAction::new(IconId::new("new_layer"), words.new_layer.clone()),
];
let footer = FooterBar::actions(actions).show_footer(ui);
let footer = FooterBar::actions(actions).at_start(2).show_footer(ui);
let pressed = match footer.picked {
Some(0) => Some(EffectChange::move_to(current, current + 1)),
Some(1) => Some(EffectChange::move_to(current, current.saturating_sub(1))),
Some(2) => Some(EffectChange::Add),
Some(3) => Some(EffectChange::Delete),
Some(2) => Some(EffectChange::Delete),
Some(3) => Some(EffectChange::Add),
_ => None,
};
if pressed.is_some() {
+13 -13
View File
@@ -67,14 +67,14 @@ pub enum LayersFooterAction {
Style(String),
}
// Reading order of the footer's buttons.
const LINK: usize = 0;
const STYLE: usize = 1;
const MASK: usize = 2;
// The footer's buttons from the end edge, as Photoshop's.
const DELETE: usize = 0;
const LAYER: usize = 1;
const GROUP: usize = 2;
const ADJUSTMENT: usize = 3;
const GROUP: usize = 4;
const LAYER: usize = 5;
const DELETE: usize = 6;
const MASK: usize = 4;
const STYLE: usize = 5;
const LINK: usize = 6;
fn button_at(at: usize) -> Option<LayersFooterButton> {
match at {
@@ -104,16 +104,16 @@ pub(super) fn show_footer<T: LayerTree>(ui: &mut Ui, cx: &PanelContext<'_, T>, w
let icon = |name: &'static str| IconSpec::svg(IconId::new(name));
let mask_name = state.mask_label.clone().map_or_else(|| words.add_mask.clone(), craft_ui::runtime::env::Label::from);
let actions = [
FooterAction::new(icon("link"), words.link_layers.clone()).enabled(state.link_enabled),
FooterAction::new(icon("fx"), words.add_style.clone()).popup(PopupKind::Menu),
FooterAction::new(icon("layer_mask"), mask_name).enabled(state.mask_label.is_some()),
FooterAction::new(icon("adjustment_layer"), words.add_adjustment.clone()).popup(PopupKind::Menu),
FooterAction::new(icon("new_folder"), words.new_group.clone()).accepts_drops(takes(LayersFooterButton::NewGroup)),
FooterAction::new(icon("new_layer"), words.new_layer.clone()).accepts_drops(takes(LayersFooterButton::NewLayer)),
FooterAction::new(icon("trash"), craft_ui::runtime::env::Label::from(state.delete_label.clone()))
.enabled(state.delete_enabled)
.takes_drops_disabled(true)
.accepts_drops(takes(LayersFooterButton::Delete)),
FooterAction::new(icon("new_layer"), words.new_layer.clone()).accepts_drops(takes(LayersFooterButton::NewLayer)),
FooterAction::new(icon("new_folder"), words.new_group.clone()).accepts_drops(takes(LayersFooterButton::NewGroup)),
FooterAction::new(icon("adjustment_layer"), words.add_adjustment.clone()).popup(PopupKind::Menu),
FooterAction::new(icon("layer_mask"), mask_name).enabled(state.mask_label.is_some()),
FooterAction::new(icon("fx"), words.add_style.clone()).popup(PopupKind::Menu),
FooterAction::new(icon("link"), words.link_layers.clone()).enabled(state.link_enabled),
];
let out = FooterBar::actions(actions).show_footer(ui);
+9 -5
View File
@@ -58,6 +58,10 @@ const LOCKED: ColumnKey = ColumnKey::new("locked");
const NAME: ColumnKey = ColumnKey::new("name");
const OPTIONS: TrailingPart = TrailingPart::new(0);
// The footer's actions from the end edge: Delete, Duplicate, New.
const DUPLICATE: usize = 1;
const NEW: usize = 2;
/// One row.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
@@ -243,15 +247,15 @@ impl<'a> PageList<'a> {
let list = *list_id.borrow();
let ours = move |drag: &ListDrag<usize>| Some(drag.list) == list;
let actions = [
FooterAction::new(IconId::new("plus"), words.new_artboard.clone()).accepts_drops(ours),
FooterAction::new(IconId::new("copy"), words.duplicate.clone()).enabled(any_picked),
FooterAction::new(IconId::new("trash"), words.delete.clone()).enabled(!deletable.is_empty()).accepts_drops(ours),
FooterAction::new(IconId::new("copy"), words.duplicate.clone()).enabled(any_picked),
FooterAction::new(IconId::new("plus"), words.new_artboard.clone()).accepts_drops(ours),
];
let footer = FooterBar::actions(actions).show_footer(ui);
let mut events = events.borrow_mut();
if let Some(drop) = &footer.dropped {
let Some(drag) = drop.payload::<ListDrag<usize>>() else { return };
if drop.index == 0 {
if drop.index == NEW {
events.push(PageListEvent::New { duplicate: Some(drag.grabbed), options: false });
} else {
let dropped = unlocked(&drag.keys);
@@ -261,8 +265,8 @@ impl<'a> PageList<'a> {
}
} else if let Some(picked_action) = footer.picked {
events.push(match picked_action {
0 => PageListEvent::New { duplicate: None, options: footer.mods.alt },
1 => PageListEvent::New { duplicate: Some(active), options: false },
NEW => PageListEvent::New { duplicate: None, options: footer.mods.alt },
DUPLICATE => PageListEvent::New { duplicate: Some(active), options: false },
_ => PageListEvent::Delete(deletable.clone()),
});
}
+4 -4
View File
@@ -198,14 +198,14 @@ impl Facts {
}
}
/// The footer's buttons in reading order.
/// The footer's buttons: the start group from the start edge, the rest from the end edge.
const FOOTER: [TextStyleCommand; 6] = [
TextStyleCommand::ClearOverride,
TextStyleCommand::Redefine,
TextStyleCommand::Options,
TextStyleCommand::Duplicate,
TextStyleCommand::New,
TextStyleCommand::Delete,
TextStyleCommand::New,
TextStyleCommand::Duplicate,
TextStyleCommand::Options,
];
/// How many of the footer's buttons sit at its start edge: Clear Override and Redefine.
+20 -15
View File
@@ -564,14 +564,17 @@ impl FooterBar {
self
}
/// A footer bar of icon actions, in the given order. Show it with `show_footer`.
/// A footer bar of icon actions laid out from the reading end, as Photoshop's panel footers: the first action given
/// sits at the end edge (Delete), the next one before it, and a panel menu given last at the start of the group.
/// Tab visits them in display order; the indexes the output reports are those of the given order. Show it with
/// `show_footer`.
pub fn actions(actions: impl IntoIterator<Item = FooterAction>) -> Self {
FooterBar { content: Content::Actions(actions.into_iter().collect()), actions: true, ..FooterBar::body() }
}
/// The first `count` actions sit at the start edge and the rest at the end edge, the room left between the two
/// groups (Clear Override and Redefine before a style panel's other actions). The indexes the output reports stay
/// those of the given order.
/// The first `count` actions sit at the start edge in the given order and the rest from the end edge as
/// [`actions`](FooterBar::actions) places them, the room left between the two groups (Clear Override and Redefine
/// before a style panel's other actions). The indexes the output reports stay those of the given order.
#[must_use]
pub fn at_start(mut self, count: usize) -> Self {
self.start = count;
@@ -594,13 +597,14 @@ impl FooterBar {
Content::Actions(actions) => {
let mut shown = Shown::default();
let start = start.min(actions.len());
let from_end = || (start..actions.len()).rev();
if start == 0 {
show_actions(ui, actions, 0, &mut shown);
show_actions(ui, actions, from_end(), &mut shown);
} else {
let (first, rest) = actions.split_at(start);
Row::new().show(ui, |ui, _| show_actions(ui, first, 0, &mut shown));
Row::new().show(ui, |ui, _| show_actions(ui, rest, start, &mut shown));
Row::new().show(ui, |ui, _| show_actions(ui, actions, 0..start, &mut shown));
Row::new().show(ui, |ui, _| show_actions(ui, actions, from_end(), &mut shown));
}
shown.responses.sort_by_key(|(at, _)| *at);
shown
}
Content::Buttons(buttons) => {
@@ -659,16 +663,16 @@ impl FooterBar {
picked: inner.picked,
dropped: inner.dropped,
drop_hint: inner.drop_hint,
responses: inner.responses,
responses: inner.responses.into_iter().map(|(_, response)| response).collect(),
mods,
}
}
}
/// Shows `actions`, the first of them at index `from` of the bar's actions, and collects what happened to them.
fn show_actions(ui: &mut Ui, actions: &[FooterAction], from: usize, shown: &mut Shown) {
for (at, action) in actions.iter().enumerate() {
let at = from + at;
/// Shows the bar's `actions` at the indexes `order`, in display order, and collects what happened to them.
fn show_actions(ui: &mut Ui, actions: &[FooterAction], order: impl Iterator<Item = usize>, shown: &mut Shown) {
for at in order {
let action = &actions[at];
let response = match &action.drops {
Some(drops) => {
let slot = drops(ui, action);
@@ -685,7 +689,7 @@ fn show_actions(ui: &mut Ui, actions: &[FooterAction], from: usize, shown: &mut
if crate::contract::clicked(&response) {
shown.picked = Some(at);
}
shown.responses.push(response);
shown.responses.push((at, response));
}
}
@@ -695,7 +699,8 @@ struct Shown {
picked: Option<usize>,
dropped: Option<FooterDrop>,
drop_hint: Option<Label>,
responses: Vec<Response>,
/// Each action's index in the given order and its response, in display order until the bar sorts them.
responses: Vec<(usize, Response)>,
}
impl Component for FooterBar {
@@ -1,5 +1,5 @@
//! A footer row: a row of view modes, a thumbnail slider and a footer bar narrows its slider to leave the bar its
//! actions; a footer bar with a start group shows it at the start edge and the rest at the end edge.
//! actions; a footer bar with a start group shows it at the start edge and the rest from the end edge.
use craft_behavior::IconId;
use craft_ui::choice::Segmented;
@@ -34,16 +34,17 @@ fn footer(width: f32) -> (Rect, Rect, Vec<Rect>) {
#[trial]
fn a_footer_row_narrows_its_slider_to_leave_the_footer_bar_its_actions() {
let (modes, wide, actions) = footer(900.0);
let span = |rects: &[Rect]| rects.last().map_or(0.0, |last| last.max.x) - rects.first().map_or(0.0, |first| first.min.x);
let start = |rects: &[Rect]| rects.iter().map(|rect| rect.min.x).fold(f32::INFINITY, f32::min);
let end = |rects: &[Rect]| rects.iter().map(|rect| rect.max.x).fold(f32::NEG_INFINITY, f32::max);
let span = |rects: &[Rect]| end(rects) - start(rects);
// A row with room for the modes, the actions and half the slider's natural length, with a member gap at each
// seam: the track gives way to about a control's height, as a media bin's footer in a narrow panel needs.
let gap = wide.min.x - modes.max.x;
let width = (modes.width() + wide.width() / 2.0 + span(&actions) + 3.0 * gap).ceil();
let (_, slider, actions) = footer(width);
let last = actions.last().copied().unwrap_or(Rect::NOTHING);
assert!(last.max.x <= width + 0.5, "the last action ends at {} past a {width}-point row", last.max.x);
assert!(end(&actions) <= width + 0.5, "the actions end at {} past a {width}-point row", end(&actions));
assert!(slider.width() < wide.width() - 0.5, "the slider kept its width {} in a narrow row", slider.width());
assert!(slider.max.x <= actions[0].min.x + 0.5, "the slider {slider:?} runs into the actions {actions:?}");
assert!(slider.max.x <= start(&actions) + 0.5, "the slider {slider:?} runs into the actions {actions:?}");
}
/// The rects of a footer bar's four actions whose first two sit at the start edge, in a bar `WIDE` points wide.
@@ -61,16 +62,18 @@ fn split(direction: craft_ui::runtime::env::Direction) -> Vec<Rect> {
const WIDE: f32 = 400.0;
/// The start group sits at the start edge and the rest at the end edge, the room left between them; right to left
/// the groups trade sides.
/// The start group sits at the start edge in the given order and the rest from the end edge, the first of them at the
/// edge, the room left between them; right to left the groups trade sides.
#[trial]
fn the_start_and_end_groups_of_a_footer_bar_sit_at_their_edges() {
use craft_ui::runtime::env::Direction;
let ltr = split(Direction::Ltr);
assert_eq!(ltr.len(), 4);
let (pair, between) = (ltr[1].min.x - ltr[0].max.x, ltr[2].min.x - ltr[1].max.x);
let (pair, between) = (ltr[1].min.x - ltr[0].max.x, ltr[3].min.x - ltr[1].max.x);
assert!(between > pair + WIDE / 4.0, "the room lies between the groups: {ltr:?}");
assert!(ltr[0].min.x < WIDE / 4.0 && ltr[3].max.x > WIDE * 3.0 / 4.0, "the groups reach the edges: {ltr:?}");
assert!(ltr[0].min.x < WIDE / 4.0 && ltr[2].max.x > WIDE * 3.0 / 4.0, "the groups reach the edges: {ltr:?}");
assert!(ltr[0].max.x < ltr[1].min.x, "the start group reads from the start edge: {ltr:?}");
assert!(ltr[3].max.x < ltr[2].min.x, "the end group reads from the end edge: {ltr:?}");
let rtl = split(Direction::Rtl);
assert!(rtl[0].min.x > rtl[2].max.x, "right to left the start group sits at the right: {rtl:?}");
}
@@ -133,7 +133,7 @@ impl<'a> PresetFooterOptions<'a> {
/// The footer of a preset panel: the host's own controls, the thumbnail size slider and the count, then the action
/// buttons Delete, New and New Group and the host's own actions.
///
/// - **Buttons.** Delete (disabled by `can_delete(false)`), New, New Group
/// - **Buttons.** From the end edge: Delete (disabled by `can_delete(false)`), New, New Group
/// (left out by `new_group(false)`), then the host's [`FooterAction`]s. Their names come from [`PresetWords`].
/// - **Host actions.** A disabled action takes no click. An action that `accepts_drops` takes presets dragged from
/// any preset list and reports [`PresetFooterEvent::CustomDrop`].
@@ -193,18 +193,18 @@ impl<K: Clone + Send + Sync + 'static> PresetFooter<'_, K> {
let words = env.words::<PresetWords>();
let mut shown = Vec::with_capacity(actions.len() + 3);
let mut slots = Vec::with_capacity(actions.len() + 3);
for (index, action) in actions.into_iter().enumerate() {
shown.push(action);
slots.push(Slot::Custom(index));
}
shown.push(FooterAction::new(IconId::new("trash"), words.delete_button.clone()).enabled(can_delete));
slots.push(Slot::Delete);
shown.push(FooterAction::new(IconId::new("plus"), words.new_preset.clone()));
slots.push(Slot::New);
if new_group {
shown.push(FooterAction::new(IconId::new("new_folder"), words.new_group.clone()));
slots.push(Slot::NewGroup);
}
shown.push(FooterAction::new(IconId::new("plus"), words.new_preset.clone()));
slots.push(Slot::New);
shown.push(FooterAction::new(IconId::new("trash"), words.delete_button.clone()).enabled(can_delete));
slots.push(Slot::Delete);
for (index, action) in actions.into_iter().enumerate() {
shown.push(action);
slots.push(Slot::Custom(index));
}
let row = Row::new().fill().align(RowAlign::End).show(ui, |ui, _| {
if let Some(add) = &leading {