mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 23:24:24 +00:00
Row drags from any part, a text face for trailing parts, thumbnail cursors and the empty space's menu
- ListRow::part_drag(RowDragSpot, payload) replaces thumb_drag: a thumbnail or a trailing part drags instead of the row (RowEvent::PartDrag). A trailing part that drags is a handle: its click is the row's. - TrailingFace::Strong: a text face for a trailing part. - ListRow::thumb_cursor: the cursor over a thumbnail. - CollectionEvent::EmptyContextMenu: a secondary click on a collection's empty space. - craft-layers: the fx badge drags every effect of its layer onto another layer (a transfer, Alt copies) and a click on it selects the row; MenuTarget.row is None for the empty space's menu; the load-selection cursor over thumbnails while Cmd/Ctrl is held; LayerTree::label_colors_in_menu decides per target whether the row menu gets the Label Color submenu.
This commit is contained in:
@@ -6,7 +6,7 @@ mod rows;
|
||||
|
||||
use map::map_events;
|
||||
pub(in crate::ui::panel) use map::start_rename;
|
||||
pub(in crate::ui::panel) use rows::{LayerRows, ToggleSweeps, extra_parts, reveal_plan};
|
||||
pub(in crate::ui::panel) use rows::{LayerRows, ToggleSweeps, extra_parts, reveal_plan, thumb_click_replaces_select};
|
||||
use rows::{RevealPlan, list_selection};
|
||||
|
||||
use craft_behavior::{ColumnWidth, IconId};
|
||||
@@ -20,7 +20,7 @@ use egui::Ui;
|
||||
|
||||
use super::Session;
|
||||
use super::context::PanelContext;
|
||||
use super::drag::{LayersDrag, accepts_drop, accepts_mask_drop, layer_drop};
|
||||
use super::drag::{LayersDrag, accepts_drop, accepts_part_drop, layer_drop};
|
||||
use super::events::{LayerDrop, LayerMove, LayersEvent};
|
||||
use super::row::{EYE, LOCK, NAME, build_row};
|
||||
use crate::ui::tree::{LayerRowKey, LayerTree};
|
||||
@@ -85,7 +85,7 @@ pub(super) fn show_body<T: LayerTree>(
|
||||
})
|
||||
.drag_payload(|drag: &ListDrag<LayerRowKey<T::Id>>| Some(LayersDrag::of_rows(drag)))
|
||||
.takes_drop(DropKind::new(DropPlace::Onto, move |drag: &LayersDrag<T::Id>, at: &DropAt<LayerRowKey<T::Id>>| {
|
||||
accepts_mask_drop(tree, list_id, drag, at)
|
||||
accepts_part_drop(tree, list_id, drag, at)
|
||||
}));
|
||||
if let Some(key) = reveal_key {
|
||||
list = list.reveal(key);
|
||||
|
||||
@@ -10,7 +10,7 @@ use std::sync::Arc;
|
||||
|
||||
use super::super::Session;
|
||||
use super::super::context::PanelContext;
|
||||
use super::super::drag::{LayersDrag, drop_event, mask_drop_event};
|
||||
use super::super::drag::{LayersDrag, drop_event, part_drop_event};
|
||||
use super::super::events::{ActivateOn, LayerColumn, LayerSelect, LayerToggle, LayersEvent, MenuTarget};
|
||||
use super::super::menu::{OpenMenu, shared_label};
|
||||
use super::super::row::{EYE, FX_PART, LOCK_PART, NAME, OPTIONS_PART};
|
||||
@@ -111,13 +111,16 @@ pub(super) fn map_events<T: LayerTree>(
|
||||
// A right-click on a thumbnail opens the menu for what it shows (a mask).
|
||||
let part =
|
||||
request.part.and_then(ThumbTarget::of_part).map(|which| thumb_part(&request.key, &tree.info(request.key.layer()), which));
|
||||
session.menu = Some(OpenMenu::Row(MenuTarget { row: request.key.clone(), part, on_selection }));
|
||||
session.menu = Some(OpenMenu::Row(MenuTarget { row: Some(request.key.clone()), part, on_selection }));
|
||||
}
|
||||
}
|
||||
CollectionEvent::EmptyContextMenu { .. } => {
|
||||
session.menu = Some(OpenMenu::Row(MenuTarget { row: None, part: None, on_selection: false }));
|
||||
}
|
||||
CollectionEvent::Reorder(edit) => events.extend(drop_event(edit, order, parent_of, filtered)),
|
||||
CollectionEvent::Dropped { at, op, payload, .. } => {
|
||||
if let Some(drag) = payload.get::<LayersDrag<T::Id>>() {
|
||||
events.extend(mask_drop_event(cx.list, drag, &at, op, Arc::from(cx.words.list.as_str())));
|
||||
events.extend(part_drop_event(cx.list, drag, &at, op, Arc::from(cx.words.list.as_str())));
|
||||
}
|
||||
}
|
||||
CollectionEvent::Toggle(edit) => toggle_events(edit, &mut session.sweeps, &mut toggle_label, events),
|
||||
|
||||
@@ -61,4 +61,6 @@ pub(super) struct PanelContext<'a, T: LayerTree> {
|
||||
pub(super) visibility_key: Option<craft_keymap::Chord>,
|
||||
/// The host's component at each layer row's trailing end.
|
||||
pub(super) trailing: Option<&'a (dyn TrailingCell<T::Id> + 'a)>,
|
||||
/// The modifiers held this pass: the thumbnails' load cursor follows them.
|
||||
pub(super) held: craft_keymap::Mods,
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use std::sync::Arc;
|
||||
|
||||
use super::LayersPanelCommands;
|
||||
use super::events::{LayerDrop, LayerMove, LayerPosition, LayersEvent, MaskMove, RowTransfer, SubRowMove};
|
||||
use crate::ui::tree::{LayerKind, LayerPart, LayerRowKey, LayerTree, SubRowGroup};
|
||||
use crate::ui::tree::{LayerKind, LayerRowKey, LayerTree, SubRowGroup};
|
||||
|
||||
/// What a drag from the Layers panel carries for the drop targets outside its rows: the footer buttons, the rows
|
||||
/// that take a mask, and the app's own targets (a document tab that copies the dragged layers into its document).
|
||||
@@ -155,27 +155,41 @@ pub(super) fn accepts_drop<T: LayerTree>(
|
||||
}
|
||||
}
|
||||
|
||||
/// The mask a drag of `list` carries and the layer row it is over, when that row is another layer's.
|
||||
fn mask_onto<'d, K: PartialEq>(list: egui::Id, drag: &'d LayersDrag<K>, at: &'d DropAt<LayerRowKey<K>>) -> Option<(&'d K, LayerPart, &'d K)> {
|
||||
let (DropAt::Onto(LayerRowKey::Layer(to)), [LayerRowKey::Mask(from, part)]) = (at, drag.keys.as_slice()) else { return None };
|
||||
(drag.list == list && to != from).then_some((from, *part, to))
|
||||
/// What a drag of the panel's own part (a mask thumbnail, the `fx` badge) means over the row `at`: the drop it makes
|
||||
/// there, `None` unless the row is another layer's and the drag started in `list`.
|
||||
fn part_drop<K: Clone + PartialEq>(list: egui::Id, drag: &LayersDrag<K>, at: &DropAt<LayerRowKey<K>>, copy: bool) -> Option<LayerDrop<K>> {
|
||||
let DropAt::Onto(LayerRowKey::Layer(to)) = at else { return None };
|
||||
if drag.list != list {
|
||||
return None;
|
||||
}
|
||||
match drag.keys.as_slice() {
|
||||
[LayerRowKey::Mask(from, part)] if from != to => Some(LayerDrop::Mask(MaskMove::new(from.clone(), *part, to.clone(), copy))),
|
||||
[effects @ LayerRowKey::Effects(from, None)] if from != to => {
|
||||
Some(LayerDrop::Transfer(RowTransfer { rows: vec![effects.clone()], to: to.clone(), copy }))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the mask thumbnail a drag of the rows' list `list` carries may land on the row under the pointer.
|
||||
pub(super) fn accepts_mask_drop<T: LayerTree>(tree: &T, list: egui::Id, drag: &LayersDrag<T::Id>, at: &DropAt<LayerRowKey<T::Id>>) -> bool {
|
||||
mask_onto(list, drag, at).is_some_and(|(from, part, to)| tree.accepts_mask_drop(from, part, to))
|
||||
/// Whether the row under the pointer takes a drag of the rows' list `list` that is not a row drag: a mask thumbnail
|
||||
/// where the tree takes the mask, the `fx` badge on any other layer.
|
||||
pub(super) fn accepts_part_drop<T: LayerTree>(tree: &T, list: egui::Id, drag: &LayersDrag<T::Id>, at: &DropAt<LayerRowKey<T::Id>>) -> bool {
|
||||
match part_drop(list, drag, at, false) {
|
||||
Some(LayerDrop::Mask(mv)) => tree.accepts_mask_drop(&mv.layer, mv.part, &mv.to),
|
||||
Some(_) => true,
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// The drop a mask thumbnail makes on the row it was released over, one `Set` named `label`.
|
||||
pub(super) fn mask_drop_event<K: Clone + PartialEq>(
|
||||
/// The drop a mask thumbnail or the `fx` badge makes on the row it was released over, one `Set` named `label`.
|
||||
pub(super) fn part_drop_event<K: Clone + PartialEq>(
|
||||
list: egui::Id,
|
||||
drag: &LayersDrag<K>,
|
||||
at: &DropAt<LayerRowKey<K>>,
|
||||
op: DropOperation,
|
||||
label: Arc<str>,
|
||||
) -> Option<LayersEvent<K>> {
|
||||
let (from, part, to) = mask_onto(list, drag, at)?;
|
||||
let drop = LayerDrop::Mask(MaskMove::new(from.clone(), part, to.clone(), op == DropOperation::Copy));
|
||||
let drop = part_drop(list, drag, at, op == DropOperation::Copy)?;
|
||||
Some(LayersEvent::Drop(EditEvent::set(Mixed::Mixed, drop, label, None)))
|
||||
}
|
||||
|
||||
|
||||
@@ -315,8 +315,9 @@ impl<Id> MaskMove<Id> {
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub struct MenuTarget<Id> {
|
||||
/// The row.
|
||||
pub row: LayerRowKey<Id>,
|
||||
/// The row; `None` for the empty space below the rows, or the whole list when no row is shown (the host's
|
||||
/// thumbnail size and clipping menu).
|
||||
pub row: Option<LayerRowKey<Id>>,
|
||||
/// The thumbnail the press landed on, if known.
|
||||
pub part: Option<LayerPart>,
|
||||
/// The row is one of several selected rows: the command applies to all of them.
|
||||
|
||||
@@ -189,24 +189,23 @@ enum RowPick {
|
||||
}
|
||||
|
||||
/// The layers the row menu's Label Color submenu colours: every selected layer when the menu acts on the selection,
|
||||
/// else the row's layer. `None` where the submenu is not shown: on a thumbnail, whose menu is the host's own, and on
|
||||
/// effects and Smart Filter rows.
|
||||
fn label_rows<Id: Clone>(target: &MenuTarget<Id>, selected: &[Id]) -> Option<Vec<Id>> {
|
||||
let LayerRowKey::Layer(layer) = &target.row else { return None };
|
||||
if target.part.is_some() {
|
||||
/// else the row's layer. `None` where the submenu is not shown: on effects and Smart Filter rows, the empty space, and
|
||||
/// where the tree leaves it out ([`LayerTree::label_colors_in_menu`]).
|
||||
fn label_rows<T: LayerTree>(tree: &T, target: &MenuTarget<T::Id>, selected: &[T::Id]) -> Option<Vec<T::Id>> {
|
||||
let Some(LayerRowKey::Layer(layer)) = &target.row else { return None };
|
||||
if !tree.label_colors_in_menu(target) {
|
||||
return None;
|
||||
}
|
||||
Some(if target.on_selection { selected.to_vec() } else { vec![layer.clone()] })
|
||||
}
|
||||
|
||||
/// Shows the menu the last context request chose, hanging from `opener` (the list). A right-click
|
||||
/// on a row opens it at the pointer. With `label_colors`, a layer row's menu ends with the Label Color submenu.
|
||||
/// on a row opens it at the pointer; a layer row's menu ends with the Label Color submenu where the tree asks for it.
|
||||
pub(super) fn show_row_menus<T: LayerTree>(
|
||||
ui: &mut Ui,
|
||||
cx: &PanelContext<'_, T>,
|
||||
opener: &Response,
|
||||
row_menu: Option<&RowMenu<'_, T::Id>>,
|
||||
label_colors: bool,
|
||||
session: &Session<T::Id>,
|
||||
) -> Vec<LayersEvent<T::Id>> {
|
||||
let words = cx.words;
|
||||
@@ -214,7 +213,7 @@ pub(super) fn show_row_menus<T: LayerTree>(
|
||||
Some(OpenMenu::Row(target)) => {
|
||||
let Some(menu) = row_menu else { return Vec::new() };
|
||||
let entries = menu(&target);
|
||||
let colored = if label_colors { label_rows(&target, &cx.selection.layers) } else { None };
|
||||
let colored = label_rows(cx.tree, &target, &cx.selection.layers);
|
||||
let current = colored.as_deref().and_then(|rows| shared_label(cx.tree, rows));
|
||||
let shown = Menu::context(words.row_menu.clone(), opener).show(ui, |ui, _| {
|
||||
let ran = entry_rows(ui, &entries).and_then(|at| entries.get(at)).and_then(Entry::value).cloned();
|
||||
|
||||
@@ -152,8 +152,10 @@ impl<Id> Default for Session<Id> {
|
||||
/// - **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
|
||||
/// rename or activate, rows drag to reorder (Alt copies) and onto the footer, and a mask thumbnail drags onto
|
||||
/// another layer's row to move the mask there (Alt copies).
|
||||
/// rename or activate, rows drag to reorder (Alt copies) and onto the footer, a mask thumbnail drags onto
|
||||
/// another layer's row to move the mask there and the `fx` badge to move every effect (Alt copies). The empty space's
|
||||
/// right-click opens the host's menu for no row ([`MenuTarget::row`] `None`). With Cmd/Ctrl held over a thumbnail
|
||||
/// that loads a selection, the cursor is the pointing hand with the operation's mark.
|
||||
/// - **Right to left**: the list and the footer mirror.
|
||||
#[must_use = "show the panel with `show`"]
|
||||
#[derive(craft_ui::contract::Pattern)]
|
||||
@@ -169,7 +171,6 @@ pub struct LayersPanel<'a, T: LayerTree> {
|
||||
filter_bar: bool,
|
||||
find_name: bool,
|
||||
row_menu: Option<Box<RowMenu<'a, T::Id>>>,
|
||||
row_label_colors: bool,
|
||||
trailing: Option<Box<dyn TrailingCell<T::Id> + 'a>>,
|
||||
reveal: Option<T::Id>,
|
||||
rename: Option<T::Id>,
|
||||
@@ -214,7 +215,6 @@ impl<'a, T: LayerTree> LayersPanel<'a, T> {
|
||||
filter_bar: true,
|
||||
find_name: false,
|
||||
row_menu: None,
|
||||
row_label_colors: true,
|
||||
trailing: None,
|
||||
reveal: None,
|
||||
rename: None,
|
||||
@@ -284,14 +284,6 @@ impl<'a, T: LayerTree> LayersPanel<'a, T> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Ends the row menu of a layer row with the Label Color submenu (default on): the eye menu's colours, for the
|
||||
/// selected layers when the menu acts on the selection; a pick is [`LayersEvent::LabelColor`]. A thumbnail's menu
|
||||
/// and the effects and Smart Filter rows' menus have none.
|
||||
pub fn row_label_colors(mut self, on: bool) -> Self {
|
||||
self.row_label_colors = on;
|
||||
self
|
||||
}
|
||||
|
||||
/// The host's component at each layer row's trailing end, after the indicators and never dropped for the name
|
||||
/// (Illustrator's target circle, a selection square): `build` makes the layer's component and `output` gets what
|
||||
/// it reports, with the layer, in the pass it is shown.
|
||||
@@ -328,7 +320,6 @@ impl<'a, T: LayerTree> LayersPanel<'a, T> {
|
||||
filter_bar,
|
||||
find_name,
|
||||
row_menu,
|
||||
row_label_colors,
|
||||
trailing,
|
||||
reveal,
|
||||
rename,
|
||||
@@ -350,6 +341,7 @@ impl<'a, T: LayerTree> LayersPanel<'a, T> {
|
||||
lock_column,
|
||||
visibility_key,
|
||||
trailing: trailing.as_deref(),
|
||||
held: craft_ui::runtime::pointer::frame(ui.ctx()).mods,
|
||||
};
|
||||
let events = RefCell::new(Vec::new());
|
||||
let current = RefCell::new(LayerFilter::default());
|
||||
@@ -401,7 +393,7 @@ impl<'a, T: LayerTree> LayersPanel<'a, T> {
|
||||
start_rename(ui, list, layer);
|
||||
}
|
||||
let body = show_body(ui, &cx, &rows, session, &plan, rows.filtered, &unlock_label);
|
||||
let menus = show_row_menus(ui, &cx, &body.response, row_menu.as_deref(), row_label_colors, session);
|
||||
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>() {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
//! One layer row: `LayerInfo` to `ListRow` (eye, thumbnails, kind icon, masks, brackets, trailing
|
||||
//! parts, sub-rows).
|
||||
|
||||
use craft_behavior::{ColumnKey, IconId};
|
||||
use craft_behavior::{ColumnKey, Cursor, CursorBadge, CursorIcon, IconId, PaintedCursor};
|
||||
use craft_keymap::Mods;
|
||||
use craft_theme::{LabelColor, Rgba, Srgba};
|
||||
use craft_ui::contract::Props as _;
|
||||
use craft_ui::list::{ListRow, RowInk, ThumbSize, ThumbTarget, ToggleCell, TrailingFace, TrailingPart};
|
||||
use craft_ui::list::{ListRow, RowDragSpot, RowInk, ThumbSize, ThumbTarget, ToggleCell, TrailingFace, TrailingPart};
|
||||
use craft_ui::primitives::textures::{Priority, ThumbPaint as PicturePaint, ThumbRequest};
|
||||
use craft_ui::primitives::{ContentPainterCx, IconSpec};
|
||||
use craft_ui::runtime::env::Label;
|
||||
@@ -13,7 +14,7 @@ use egui::emath::GuiRounding as _;
|
||||
use egui::{Color32, Rect, Stroke, pos2, vec2};
|
||||
|
||||
use super::LayersPanelWords;
|
||||
use super::body::extra_parts;
|
||||
use super::body::{extra_parts, thumb_click_replaces_select};
|
||||
use super::context::{PanelContext, ThumbHost};
|
||||
use super::drag::LayersDrag;
|
||||
use crate::ui::thumbs::LayerThumb;
|
||||
@@ -32,6 +33,8 @@ pub(super) const LOCK_PART: u16 = 0;
|
||||
pub(super) const FX_PART: u16 = 1;
|
||||
/// A Smart Filter's trailing Blending Options button.
|
||||
pub(super) const OPTIONS_PART: u16 = 2;
|
||||
/// The trailing `fx` badge: a drag handle that carries the layer's effects.
|
||||
pub(super) const FX_BADGE: u16 = 3;
|
||||
|
||||
/// The cross over a disabled mask is a fixed data colour, like the label colours.
|
||||
const DISABLED_MASK: LabelColor = LabelColor::Red;
|
||||
@@ -49,6 +52,24 @@ pub(super) fn paint_color(color: Rgba) -> Color32 {
|
||||
Color32::from(Srgba::from(color))
|
||||
}
|
||||
|
||||
/// The cursor over a thumbnail a Cmd/Ctrl click with `mods` loads as a selection: the pointing hand, with the mark of
|
||||
/// the operation Shift and Alt pick (add, subtract, intersect).
|
||||
fn load_cursor(mods: Mods) -> Cursor {
|
||||
let badge = match (mods.shift, mods.alt) {
|
||||
(true, true) => CursorBadge::Intersect,
|
||||
(true, false) => CursorBadge::Add,
|
||||
(false, true) => CursorBadge::Subtract,
|
||||
(false, false) => return Cursor::System(CursorIcon::PointingHand),
|
||||
};
|
||||
Cursor::Painted(PaintedCursor::badged(CursorIcon::PointingHand, badge))
|
||||
}
|
||||
|
||||
/// `row` with the load cursor on its thumbnail `target` showing `part`, while Cmd/Ctrl is held and a click there loads
|
||||
/// a selection.
|
||||
fn with_load_cursor<'r>(row: ListRow<'r>, held: Mods, target: ThumbTarget, part: LayerPart, info: &LayerInfo) -> ListRow<'r> {
|
||||
if held.cmd && thumb_click_replaces_select(part, held, info) { row.thumb_cursor(target, load_cursor(held)) } else { row }
|
||||
}
|
||||
|
||||
/// `pattern` with `{row}` replaced by `row`.
|
||||
pub(super) fn named(pattern: &Label, row: &str) -> Label {
|
||||
Label::from(craft_i18n::fmt(pattern.as_str(), &[("row", row)]))
|
||||
@@ -243,6 +264,8 @@ fn layer_row<'r, T: LayerTree>(cx: &'r PanelContext<'r, T>, id: &T::Id) -> ListR
|
||||
}
|
||||
});
|
||||
let frame = info.kind == LayerKind::Frame;
|
||||
let first = if frame { LayerPart::FrameShape } else { LayerPart::Pixels };
|
||||
row = with_load_cursor(row, cx.held, ThumbTarget::First, first, &info);
|
||||
if frame {
|
||||
let layer = id.clone();
|
||||
row = row.extra_thumb(move |painter, rect| {
|
||||
@@ -250,6 +273,7 @@ fn layer_row<'r, T: LayerTree>(cx: &'r PanelContext<'r, T>, id: &T::Id) -> ListR
|
||||
paint_kind_tile(painter, rect, LayerKind::Frame);
|
||||
}
|
||||
});
|
||||
row = with_load_cursor(row, cx.held, ThumbTarget::Extra(0), LayerPart::FrameContent, &info);
|
||||
}
|
||||
let masks_from = usize::from(frame);
|
||||
for (at, mask) in info.masks.iter().enumerate() {
|
||||
@@ -261,7 +285,9 @@ fn layer_row<'r, T: LayerTree>(cx: &'r PanelContext<'r, T>, id: &T::Id) -> ListR
|
||||
let word = if part == LayerPart::VectorMask { &words.vector_mask } else { &words.layer_mask };
|
||||
let pattern = if mask.linked { &words.unlink_mask } else { &words.link_mask };
|
||||
row = row.thumb_link(mask.linked, craft_i18n::fmt(pattern.as_str(), &[("mask", word.as_str()), ("layer", info.name.as_str())]));
|
||||
row = row.thumb_drag(ThumbTarget::Extra(masks_from + at), LayersDrag::new(cx.list, vec![LayerRowKey::Mask(id.clone(), part)]));
|
||||
let target = ThumbTarget::Extra(masks_from + at);
|
||||
row = row.part_drag(RowDragSpot::Thumb(target), LayersDrag::new(cx.list, vec![LayerRowKey::Mask(id.clone(), part)]));
|
||||
row = with_load_cursor(row, cx.held, target, part, &info);
|
||||
}
|
||||
if active {
|
||||
let extra = |part: LayerPart| extra_parts(&info).iter().position(|held| *held == part).map(ThumbTarget::Extra);
|
||||
@@ -293,7 +319,11 @@ fn layer_row<'r, T: LayerTree>(cx: &'r PanelContext<'r, T>, id: &T::Id) -> ListR
|
||||
row = row.trailing_icon(IconSpec::svg(IconId::new("smart_filters")), words.smart_filters.clone());
|
||||
}
|
||||
if info.has_effects {
|
||||
row = row.trailing_strong(words.fx.clone(), words.has_effects.clone());
|
||||
// The badge drags every effect of the layer (Photoshop); a click on it is a click on the row.
|
||||
let badge = TrailingPart::new(FX_BADGE);
|
||||
row = row
|
||||
.trailing_part(badge, TrailingFace::Strong(words.fx.clone()), words.has_effects.clone())
|
||||
.part_drag(RowDragSpot::Trailing(badge), LayersDrag::new(cx.list, vec![LayerRowKey::Effects(id.clone(), None)]));
|
||||
}
|
||||
if info.linked {
|
||||
row = row.trailing_icon(IconSpec::svg(IconId::new("link")), words.linked.clone());
|
||||
@@ -336,6 +366,7 @@ fn sub_row<'r, T: LayerTree>(cx: &'r PanelContext<'r, T>, id: &T::Id, group: Sub
|
||||
if cx.selection.active.as_ref() == Some(id) && cx.selection.target == LayerPart::FilterMask {
|
||||
row = row.thumb_target(ThumbTarget::First);
|
||||
}
|
||||
row = with_load_cursor(row, cx.held, ThumbTarget::First, LayerPart::FilterMask, &cx.tree.info(id));
|
||||
} else if let Some(icon) = sub.icon {
|
||||
row = row.icon(IconSpec::svg(icon));
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ use craft_theme::LabelColor;
|
||||
use craft_ui::contract::{Entry, ReorderMove};
|
||||
|
||||
use super::filter::{EffectKind, LayerFilter, SmartSource};
|
||||
use super::panel::MenuTarget;
|
||||
|
||||
/// The app's view of its layers, built per pass over its document (no copies of the layers).
|
||||
///
|
||||
@@ -94,6 +95,13 @@ pub trait LayerTree {
|
||||
!self.info(to).masks.iter().any(|mask| mask.part == part)
|
||||
}
|
||||
|
||||
/// Whether the row menu opened at `target`, a layer row, ends with the Label Color submenu (the eye menu's
|
||||
/// colours). By default the row's own menu has it and a thumbnail's menu, which is the host's own, has none;
|
||||
/// PhotoCraft keeps it on the thumbnails of layers whose thumbnail opens the layer menu (type, shape, fill).
|
||||
fn label_colors_in_menu(&self, target: &MenuTarget<Self::Id>) -> bool {
|
||||
target.part.is_none()
|
||||
}
|
||||
|
||||
/// The layer under the pointer on the canvas, drawn with the list's hover look.
|
||||
fn hovered(&self) -> Option<Self::Id> {
|
||||
None
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
//! `LayersPanel` drags and menus: a mask thumbnail dropped on another layer, what a drag carries for the app's own
|
||||
//! drop targets, and the row menu's Label Color submenu.
|
||||
//! `LayersPanel` drags, menus and cursors: a mask thumbnail or the `fx` badge dropped on another layer, what a drag
|
||||
//! carries for the app's own drop targets, the row menu's Label Color submenu, the menu of the empty space and the
|
||||
//! load-selection cursor over a thumbnail.
|
||||
|
||||
use craft_behavior::EditEvent;
|
||||
use craft_behavior::{Cursor, CursorBadge, CursorIcon, PaintedCursor, SelectionChange};
|
||||
use craft_layers::ui::mock::FakeLayers;
|
||||
use craft_layers::ui::panel::{LayerDrop, LayersDrag, LayersEvent, LayersPanel, MaskMove};
|
||||
use craft_layers::ui::tree::LayerPart;
|
||||
use craft_layers::ui::panel::{LayerDrop, LayerSelect, LayersDrag, LayersEvent, LayersPanel, MaskMove};
|
||||
use craft_layers::ui::tree::{LayerPart, LayerRowKey};
|
||||
use craft_theme::LabelColor;
|
||||
use craft_ui::contract::Entry;
|
||||
use craft_ui::testing::{Fixture, Target, pointer, trial};
|
||||
@@ -13,22 +15,45 @@ use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
type Seen = Rc<RefCell<Vec<LayersEvent<u32>>>>;
|
||||
/// The rows the host's row menu was asked for, `None` for the empty space.
|
||||
type Asked = Rc<RefCell<Vec<Option<LayerRowKey<u32>>>>>;
|
||||
|
||||
/// The room of the panel: wide enough for a row's parts, tall enough for the sample tree and the footer.
|
||||
const PANEL: Vec2 = Vec2::new(420.0, 560.0);
|
||||
|
||||
/// The panel over the sample tree, with a row menu of one entry, and the events it reports.
|
||||
fn rig() -> (Fixture, Seen) {
|
||||
let seen: Seen = Rc::default();
|
||||
let sink = Rc::clone(&seen);
|
||||
/// The panel over the sample tree, with a row menu of one entry, the events it reports and the rows its menu was
|
||||
/// asked for.
|
||||
fn rig() -> (Fixture, Seen, Asked) {
|
||||
let (seen, asked): (Seen, Asked) = (Rc::default(), Rc::default());
|
||||
let (sink, menus) = (Rc::clone(&seen), Rc::clone(&asked));
|
||||
let tree = FakeLayers::sample();
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let out = LayersPanel::new(&tree).row_menu(|_| vec![Entry::new(String::from("rename"), "Rename Layer…")]).show(ui);
|
||||
let out = LayersPanel::new(&tree)
|
||||
.row_menu(|target| {
|
||||
menus.borrow_mut().push(target.row.clone());
|
||||
vec![Entry::new(String::from("rename"), "Rename Layer…")]
|
||||
})
|
||||
.show(ui);
|
||||
sink.borrow_mut().extend(out.events);
|
||||
});
|
||||
fixture.room(PANEL);
|
||||
fixture.settle();
|
||||
(fixture, seen)
|
||||
(fixture, seen, asked)
|
||||
}
|
||||
|
||||
/// A right-click at `at`.
|
||||
fn right_click(fixture: &mut Fixture, at: Pos2) {
|
||||
fixture.frame(vec![pointer::moved(at)]);
|
||||
fixture.frame(vec![pointer::secondary(at, true)]);
|
||||
fixture.frame(vec![pointer::secondary(at, false)]);
|
||||
fixture.idle(3);
|
||||
}
|
||||
|
||||
/// The middle of the painted `fx` badge of the row named `layer`.
|
||||
fn fx_badge(fixture: &Fixture, layer: &str) -> Pos2 {
|
||||
let row = node(fixture, layer).rect;
|
||||
let badge = fixture.texts().iter().find(|text| text.text == "fx" && row.contains(text.rect.center())).expect("the row's fx badge");
|
||||
badge.rect.center()
|
||||
}
|
||||
|
||||
fn node(fixture: &Fixture, label: &str) -> Target {
|
||||
@@ -58,11 +83,22 @@ fn mask_drops(seen: &Seen) -> Vec<MaskMove<u32>> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The effects transfers among the events reported since the last call: the rows, the layer they go to and the copy flag.
|
||||
fn transfers(seen: &Seen) -> Vec<(Vec<LayerRowKey<u32>>, u32, bool)> {
|
||||
seen.borrow_mut()
|
||||
.drain(..)
|
||||
.filter_map(|event| match event {
|
||||
LayersEvent::Drop(EditEvent::Set { after: LayerDrop::Transfer(t), .. }) => Some((t.rows, t.to, t.copy)),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// A layer mask's thumbnail dropped on another layer's row moves the mask there and Alt copies it; a layer that has a
|
||||
/// layer mask already takes none.
|
||||
#[trial]
|
||||
fn a_mask_thumbnail_dropped_on_another_layer_moves_the_mask_there() {
|
||||
let (mut fixture, seen) = rig();
|
||||
let (mut fixture, seen, _) = rig();
|
||||
let from = mask_thumb(&fixture, "Masked");
|
||||
drag_onto(&mut fixture, from, "Title");
|
||||
assert_eq!(mask_drops(&seen), [MaskMove::new(3, LayerPart::LayerMask, 4, false)], "onto Title");
|
||||
@@ -78,7 +114,7 @@ fn a_mask_thumbnail_dropped_on_another_layer_moves_the_mask_there() {
|
||||
/// document tab); a mask's drag carries no layers.
|
||||
#[trial]
|
||||
fn a_row_drag_carries_its_layers_for_targets_outside_the_panel() {
|
||||
let (mut fixture, _) = rig();
|
||||
let (mut fixture, ..) = rig();
|
||||
let held = |fixture: &Fixture| craft_ui::runtime::drag::active::<LayersDrag<u32>>(fixture.ctx()).expect("a drag of the panel is held");
|
||||
let title = node(&fixture, "Title").center();
|
||||
let away = Vec2::new(0.0, 40.0);
|
||||
@@ -94,12 +130,9 @@ fn a_row_drag_carries_its_layers_for_targets_outside_the_panel() {
|
||||
/// The row menu ends with the Label Color submenu, whose pick colours the row's layer as the eye's menu does.
|
||||
#[trial]
|
||||
fn the_row_menus_label_color_submenu_colours_the_layer() {
|
||||
let (mut fixture, seen) = rig();
|
||||
let (mut fixture, seen, _) = rig();
|
||||
let title = node(&fixture, "Title").center();
|
||||
fixture.frame(vec![pointer::moved(title)]);
|
||||
fixture.frame(vec![pointer::secondary(title, true)]);
|
||||
fixture.frame(vec![pointer::secondary(title, false)]);
|
||||
fixture.idle(3);
|
||||
right_click(&mut fixture, title);
|
||||
let submenu = node(&fixture, "Label Color");
|
||||
fixture.click(&submenu).idle(3);
|
||||
let red = node(&fixture, "Red");
|
||||
@@ -114,3 +147,52 @@ fn the_row_menus_label_color_submenu_colours_the_layer() {
|
||||
.collect();
|
||||
assert_eq!(picked, [(vec![4], Some(LabelColor::Red))]);
|
||||
}
|
||||
|
||||
/// A right-click on the empty space below the rows opens the host's menu for no row.
|
||||
#[trial]
|
||||
fn a_right_click_below_the_rows_opens_the_menu_of_the_empty_space() {
|
||||
let (mut fixture, seen, asked) = rig();
|
||||
let last = node(&fixture, "Background").rect;
|
||||
right_click(&mut fixture, Pos2::new(last.center().x, last.bottom() + 20.0));
|
||||
assert_eq!(asked.borrow().last(), Some(&None), "the host's menu is asked for the empty space");
|
||||
assert!(!seen.borrow().iter().any(|event| matches!(event, LayersEvent::Select(_))), "the selection is left alone");
|
||||
}
|
||||
|
||||
/// The `fx` badge drags every effect of its layer onto another layer, Alt copies; a click on it selects the row.
|
||||
#[trial]
|
||||
fn the_fx_badge_drags_the_layers_effects_and_a_click_on_it_selects_the_row() {
|
||||
let (mut fixture, seen, _) = rig();
|
||||
let badge = fx_badge(&fixture, "Styled");
|
||||
drag_onto(&mut fixture, badge, "Title");
|
||||
assert_eq!(transfers(&seen), [(vec![LayerRowKey::Effects(7, None)], 4, false)], "onto Title");
|
||||
fixture.hold(Modifiers::ALT);
|
||||
drag_onto(&mut fixture, badge, "Title");
|
||||
fixture.hold(Modifiers::NONE);
|
||||
assert_eq!(transfers(&seen), [(vec![LayerRowKey::Effects(7, None)], 4, true)], "Alt copies");
|
||||
fixture.click_at(badge).idle(2);
|
||||
let selects: Vec<LayerSelect<u32>> =
|
||||
seen.borrow().iter().filter_map(|event| if let LayersEvent::Select(select) = event { Some(select.clone()) } else { None }).collect();
|
||||
assert_eq!(selects.last().map(|select| &select.change), Some(&SelectionChange::Set(vec![7])), "the click selects Styled");
|
||||
}
|
||||
|
||||
/// With Cmd/Ctrl held over a thumbnail a click would load as a selection, the cursor is the pointing hand, with the
|
||||
/// mark of the operation Shift or Alt picks; without Cmd/Ctrl it is not.
|
||||
#[trial]
|
||||
fn cmd_over_a_thumbnail_shows_the_load_cursor() {
|
||||
let (mut fixture, ..) = rig();
|
||||
let cursor_over = |fixture: &mut Fixture, at: Pos2, mods: Modifiers| {
|
||||
fixture.hold(mods);
|
||||
fixture.frame(vec![pointer::moved(at)]).idle(2);
|
||||
let cursor = craft_ui::runtime::cursor::current(fixture.ctx());
|
||||
fixture.hold(Modifiers::NONE);
|
||||
cursor
|
||||
};
|
||||
let mask = mask_thumb(&fixture, "Masked");
|
||||
assert_eq!(cursor_over(&mut fixture, mask, Modifiers::COMMAND), Some(Cursor::System(CursorIcon::PointingHand)), "a new selection");
|
||||
assert_eq!(
|
||||
cursor_over(&mut fixture, mask, Modifiers::COMMAND | Modifiers::SHIFT),
|
||||
Some(Cursor::Painted(PaintedCursor::badged(CursorIcon::PointingHand, CursorBadge::Add))),
|
||||
"Shift adds"
|
||||
);
|
||||
assert_ne!(cursor_over(&mut fixture, mask, Modifiers::NONE), Some(Cursor::System(CursorIcon::PointingHand)), "no Cmd, no load cursor");
|
||||
}
|
||||
|
||||
@@ -198,6 +198,14 @@ pub enum CollectionEvent<K, E> {
|
||||
/// A primary double click on the collection's empty space, below or between its items (FilmCraft's media bin
|
||||
/// imports).
|
||||
EmptyActivated,
|
||||
/// A secondary click on the collection's empty space, below or between its items, or anywhere in an empty
|
||||
/// collection: the app opens the collection's own menu (Photoshop's Layers panel: the thumbnail sizes). The
|
||||
/// selection is unchanged.
|
||||
#[non_exhaustive]
|
||||
EmptyContextMenu {
|
||||
/// Where the menu opens: the pointer, in screen space.
|
||||
at: Pos2,
|
||||
},
|
||||
/// Space on the lead of a collection whose Space previews (`SpaceAction::Preview`).
|
||||
Preview(K),
|
||||
/// The user asked for an item's context menu.
|
||||
|
||||
@@ -268,11 +268,20 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
|
||||
// it.
|
||||
let released = crate::runtime::pointer::frame(&ctx);
|
||||
let hover = crate::primitives::sensing::read_outcome(&ctx, ArenaId::new(cx.core.id)).hover;
|
||||
if released.release == Some(craft_behavior::PointerButton::Secondary)
|
||||
let menu_at = if released.release == Some(craft_behavior::PointerButton::Secondary)
|
||||
&& cx.core.response.hovered()
|
||||
&& hover.is_none_or(|hit| hit.part.is_none() || !hit.sense.takes_press() || hit.sense.contains(Sense::PICKS_ITEM))
|
||||
&& let Some(pos) = released.pos.filter(|pos| rect.contains(xf.map_or(*pos, |map| map.to_layer(*pos))))
|
||||
&& let Some(at) = layout.hit(local(pos), offset)
|
||||
{
|
||||
released.pos.filter(|pos| rect.contains(xf.map_or(*pos, |map| map.to_layer(*pos))))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let menu_row = menu_at.map(|pos| (pos, layout.hit(local(pos), offset)));
|
||||
// A secondary release on the empty space asks for the collection's own menu.
|
||||
if let Some((pos, None)) = menu_row {
|
||||
self.events.push(CollectionEvent::EmptyContextMenu { at: pos });
|
||||
}
|
||||
if let Some((pos, Some(at))) = menu_row
|
||||
&& self.source.enabled(at)
|
||||
{
|
||||
if !self.holds(at) && self.toggle_cell(props, layout, at, offset, local(pos)).is_none() {
|
||||
|
||||
@@ -420,6 +420,8 @@ pub enum CollectionKind {
|
||||
Activate,
|
||||
/// A double click on the empty space.
|
||||
EmptyActivated,
|
||||
/// A secondary click on the empty space.
|
||||
EmptyContextMenu,
|
||||
/// Space previewed the lead.
|
||||
Preview,
|
||||
/// A context menu was asked for.
|
||||
@@ -456,6 +458,7 @@ impl CollectionKind {
|
||||
CollectionEvent::LeadMoved { .. } => CollectionKind::LeadMoved,
|
||||
CollectionEvent::Activate(_) => CollectionKind::Activate,
|
||||
CollectionEvent::EmptyActivated => CollectionKind::EmptyActivated,
|
||||
CollectionEvent::EmptyContextMenu { .. } => CollectionKind::EmptyContextMenu,
|
||||
CollectionEvent::Preview(_) => CollectionKind::Preview,
|
||||
CollectionEvent::ContextMenu(_) => CollectionKind::ContextMenu,
|
||||
CollectionEvent::CommandClick { .. } => CollectionKind::CommandClick,
|
||||
|
||||
@@ -21,8 +21,8 @@ pub use findings::{Finding, Findings, FindingsList, FindingsListStyle, FindingsS
|
||||
pub use predicate::{DropTest, RowTest, RowText};
|
||||
pub(crate) use row::RowThumb;
|
||||
pub use row::{
|
||||
ListRow, ListRowStyle, RowEvent, RowInk, RowOutput, RowStyleCx, ThumbAspect, ThumbPaint, ThumbSize, ThumbTarget, ThumbTargets, TrailingFace,
|
||||
TrailingPart, label_color_label,
|
||||
ListRow, ListRowStyle, RowDragSpot, RowEvent, RowInk, RowOutput, RowStyleCx, ThumbAspect, ThumbPaint, ThumbSize, ThumbTarget, ThumbTargets,
|
||||
TrailingFace, TrailingPart, label_color_label,
|
||||
};
|
||||
pub use toggle::{ToggleCell, ToggleFace, ToggleState};
|
||||
pub use tree::OpenSet;
|
||||
|
||||
@@ -12,7 +12,7 @@ use super::words::ListWords;
|
||||
use crate::contract::{Common, OpenChange, RowHeight, RowPressed, RowState, Show};
|
||||
use crate::primitives::{ContentPainterCx, HAlign, IconSpec};
|
||||
use crate::runtime::env::Label;
|
||||
use craft_behavior::ColumnKey;
|
||||
use craft_behavior::{ColumnKey, Cursor};
|
||||
use craft_theme::variant::Tone;
|
||||
use craft_theme::{LabelColor, TypeRole};
|
||||
use egui::Rect;
|
||||
@@ -45,6 +45,16 @@ use trailing::Hosted;
|
||||
pub(super) use trailing::{Trailing, TrailingItem};
|
||||
pub use trailing::{TrailingFace, TrailingPart};
|
||||
|
||||
/// Where on a row a drag of its own starts instead of the row's ([`ListRow::part_drag`]).
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum RowDragSpot {
|
||||
/// A thumbnail.
|
||||
Thumb(ThumbTarget),
|
||||
/// A trailing part.
|
||||
Trailing(TrailingPart),
|
||||
}
|
||||
|
||||
/// The name of a label colour, or of no label, in the language of `words`.
|
||||
pub fn label_color_label(color: Option<LabelColor>, words: &ListWords) -> Label {
|
||||
let word = match color {
|
||||
@@ -155,8 +165,10 @@ pub struct ListRow<'a> {
|
||||
pub(super) pressed: Option<RowPressed>,
|
||||
/// The collection asked for this row's menu and it is open, from its row state: a revealed part stays shown.
|
||||
pub(super) menu_open: bool,
|
||||
/// The thumbnails that drag instead of the row, each with what starts its drag session.
|
||||
pub(super) drags: Vec<(ThumbTarget, ThumbPayload)>,
|
||||
/// The parts that drag instead of the row, each with what starts its drag session.
|
||||
pub(super) drags: Vec<(RowDragSpot, ThumbPayload)>,
|
||||
/// The cursors over thumbnails.
|
||||
pub(super) cursors: Vec<(ThumbTarget, Cursor)>,
|
||||
/// The icon or thumbnails come before the disclosure column instead of after it.
|
||||
#[prop]
|
||||
pub(super) leading_first: bool,
|
||||
@@ -270,6 +282,7 @@ impl<'a> ListRow<'a> {
|
||||
pressed: None,
|
||||
menu_open: false,
|
||||
drags: Vec::new(),
|
||||
cursors: Vec::new(),
|
||||
leading_first: false,
|
||||
detail: None,
|
||||
lines: None,
|
||||
@@ -564,12 +577,30 @@ impl<'a> ListRow<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
/// A drag that starts on the thumbnail `target` drags `payload` through the drag session, with a ghost as large as
|
||||
/// the thumbnail, and reports [`RowEvent::ThumbDrag`]; the row does not drag.
|
||||
/// A drag that starts on `spot` drags `payload` through the drag session, with a ghost as large as the part, and
|
||||
/// reports [`RowEvent::PartDrag`]; the row does not drag.
|
||||
///
|
||||
/// A thumbnail keeps its click. A trailing part that drags is a handle on the row: a click on it is a click on the
|
||||
/// row and reports no [`RowEvent::Trailing`], and it is no focus stop (a layer's `fx`, whose drag carries the
|
||||
/// layer's effects).
|
||||
#[must_use]
|
||||
pub fn thumb_drag<P: Clone + Send + Sync + 'static>(mut self, target: ThumbTarget, payload: P) -> Self {
|
||||
self.drags.retain(|(held, _)| *held != target);
|
||||
self.drags.push((target, Arc::new(payload)));
|
||||
pub fn part_drag<P: Clone + Send + Sync + 'static>(mut self, spot: RowDragSpot, payload: P) -> Self {
|
||||
self.drags.retain(|(held, _)| *held != spot);
|
||||
self.drags.push((spot, Arc::new(payload)));
|
||||
self
|
||||
}
|
||||
|
||||
/// The cursor while the pointer is over the thumbnail `target` (the load-selection hand while Cmd is held over a
|
||||
/// layer's thumbnail).
|
||||
#[must_use]
|
||||
pub fn thumb_cursor(mut self, target: ThumbTarget, cursor: impl Into<Cursor>) -> Self {
|
||||
self.cursors.retain(|(held, _)| *held != target);
|
||||
self.cursors.push((target, cursor.into()));
|
||||
self
|
||||
}
|
||||
|
||||
/// The payload of the drag that starts on `spot`, if it drags.
|
||||
pub(super) fn drag_at(&self, spot: RowDragSpot) -> Option<&ThumbPayload> {
|
||||
self.drags.iter().find(|(held, _)| *held == spot).map(|(_, payload)| payload)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#[cfg(doc)]
|
||||
use super::ListRow;
|
||||
use super::RowDragSpot;
|
||||
use super::thumb::ThumbTarget;
|
||||
use super::trailing::TrailingPart;
|
||||
use crate::contract::{ItemOutput, NoValue, OpenChange, Outcome};
|
||||
@@ -31,9 +32,9 @@ pub enum RowEvent {
|
||||
/// click, reported after the single click's own report. An activation by key or AccessKit counts 1.
|
||||
clicks: u32,
|
||||
},
|
||||
/// A drag started on a thumbnail of a row with [`ListRow::thumb_drag`] for it: the thumbnail is dragged, not the
|
||||
/// row, and the drag session runs with the payload given.
|
||||
ThumbDrag(ThumbTarget),
|
||||
/// A drag started on a part of a row with [`ListRow::part_drag`] for it: the part is dragged, not the row, and
|
||||
/// the drag session runs with the payload given.
|
||||
PartDrag(RowDragSpot),
|
||||
/// A trailing part ([`ListRow::trailing_part`]) was activated; the selection is unchanged.
|
||||
#[non_exhaustive]
|
||||
Trailing {
|
||||
|
||||
@@ -53,6 +53,9 @@ impl ListRow<'_> {
|
||||
match face {
|
||||
TrailingFace::Icon(icon) => ui.face(key, IconButton::new(icon.clone()).focusable(false).enabled(*enabled)),
|
||||
TrailingFace::Disclosure { open } => ui.face(key, Disclosure::new(Bind::given(*open)).node(false).enabled(*enabled)),
|
||||
TrailingFace::Strong(text) => {
|
||||
ui.draw().text(*slot, &trailing_run(text, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use super::ListRow;
|
||||
use super::show::named;
|
||||
use super::style::ListRowStyle;
|
||||
use super::thumb::{Thumb, ThumbSize};
|
||||
use super::trailing::{TrailingItem, trailing_run};
|
||||
use super::trailing::{TrailingFace, TrailingItem, trailing_run};
|
||||
use crate::contract::{ColumnAlign, PartsCx, RowHeight, WordSetCx as _};
|
||||
use crate::layout::{ShrinkOrder, ShrinkUnit, shrink_widths};
|
||||
use crate::list::toggle::ToggleState;
|
||||
@@ -270,6 +270,7 @@ impl ListRow<'_> {
|
||||
pub(super) fn widths(&self, sizes: &Sizes, text_width: &dyn Fn(&TextRun<'_>) -> f32) -> Widths {
|
||||
let width = |item: &TrailingItem| match item {
|
||||
TrailingItem::Text { text, strong, .. } => text_width(&trailing_run(text, *strong)),
|
||||
TrailingItem::Part { face: TrailingFace::Strong(text), .. } => text_width(&trailing_run(text, true)),
|
||||
TrailingItem::Icon { .. } | TrailingItem::Part { .. } => sizes.icon,
|
||||
TrailingItem::Hosted(hosted) => hosted.size.map_or(0.0, |size| size.ideal.x),
|
||||
};
|
||||
|
||||
@@ -7,7 +7,7 @@ use super::placement::{Sizes, lead_run};
|
||||
use super::style::{FillKey, ListRowStyle, RowForm, fill_of, row_ink_of, selected_outline};
|
||||
use super::thumb::{RowThumb, target_at};
|
||||
use super::trailing::{HostedSize, TrailingFace, TrailingItem, TrailingPart, below_key, cell_key, field_key};
|
||||
use super::{ListRow, RowInk};
|
||||
use super::{ListRow, RowDragSpot, RowInk};
|
||||
use crate::contract::{
|
||||
Access, Bind, Component, Cx, DragPreview, Focus as _, MeasureCx, Name, OpenChange, PaintUi, PartsCx, Pointer as _, Props as _, Role, RowPressed,
|
||||
Styled as _, WordSetCx as _,
|
||||
@@ -257,13 +257,22 @@ impl Component for ListRow<'_> {
|
||||
TrailingItem::Icon { name, .. } => {
|
||||
cx.part(TRAILING_ICON.at(at as u64), shape).tooltip(name.clone());
|
||||
}
|
||||
TrailingItem::Part { part, name, enabled: true, .. } => {
|
||||
let name = self.part_name(*part, name, &cx.words::<ListWords>(), cx.resolved.label);
|
||||
cx.part(TRAILING.at(u64::from(part.0)), shape).sense(Sense::CLICK | Sense::FOCUS).focusable().tooltip(name);
|
||||
focusable = true;
|
||||
}
|
||||
TrailingItem::Part { part, name, enabled: false, .. } => {
|
||||
cx.part(TRAILING.at(u64::from(part.0)), shape).tooltip(name.clone());
|
||||
TrailingItem::Part { part, face, name, enabled, .. } => {
|
||||
// A text face takes its whole slot; the other faces the icon square in it.
|
||||
let shape = if matches!(face, TrailingFace::Strong(_)) { *slot } else { shape };
|
||||
let key = TRAILING.at(u64::from(part.0));
|
||||
if self.drag_at(RowDragSpot::Trailing(*part)).is_some() {
|
||||
cx.part(key, shape)
|
||||
.sense(Sense::CLICK | Sense::DRAG | Sense::PICKS_ITEM)
|
||||
.pointer_only("A drag handle is a pointer target; a click on it is a click on the row")
|
||||
.tooltip(name.clone());
|
||||
} else if *enabled {
|
||||
let name = self.part_name(*part, name, &cx.words::<ListWords>(), cx.resolved.label);
|
||||
cx.part(key, shape).sense(Sense::CLICK | Sense::FOCUS).focusable().tooltip(name);
|
||||
focusable = true;
|
||||
} else {
|
||||
cx.part(key, shape).tooltip(name.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -272,9 +281,13 @@ impl Component for ListRow<'_> {
|
||||
}
|
||||
let thumbs = placed.first.into_iter().chain(placed.extras.iter().map(|(thumb, _)| *thumb));
|
||||
for (at, thumb) in thumbs.enumerate() {
|
||||
let target = target_at(at);
|
||||
let sense =
|
||||
if self.drags.iter().any(|(held, _)| *held == target_at(at)) { Sense::CLICK | Sense::DRAG } else { Sense::CLICK } | Sense::PICKS_ITEM;
|
||||
cx.part(THUMB.at(at as u64), thumb).sense(sense).pointer_only("A thumbnail is a pointer target; the keys act on the row");
|
||||
if self.drag_at(RowDragSpot::Thumb(target)).is_some() { Sense::CLICK | Sense::DRAG } else { Sense::CLICK } | Sense::PICKS_ITEM;
|
||||
let part = cx.part(THUMB.at(at as u64), thumb).sense(sense).pointer_only("A thumbnail is a pointer target; the keys act on the row");
|
||||
if let Some((_, cursor)) = self.cursors.iter().find(|(held, _)| *held == target) {
|
||||
part.cursor(cursor.clone());
|
||||
}
|
||||
}
|
||||
if let (Some(slot), Some(_)) = (placed.icon, &self.lead_text) {
|
||||
let rect = Rect::from_x_y_ranges(slot.x_range(), rect.y_range());
|
||||
@@ -318,11 +331,10 @@ impl Component for ListRow<'_> {
|
||||
let Some(result) = cx.part_if_declared(THUMB.at(at as u64)) else { continue };
|
||||
let target = target_at(at);
|
||||
let phase = result.press.phase;
|
||||
let drag = self.drags.iter().find(|(held, _)| *held == target);
|
||||
if let (PressPhase::DragStart { .. }, Some((_, payload))) = (phase, drag) {
|
||||
if let (PressPhase::DragStart { .. }, Some(payload)) = (phase, self.drag_at(RowDragSpot::Thumb(target))) {
|
||||
let preview = DragPreview::frame(self.thumb_size(&cx.style.sizes), None);
|
||||
crate::runtime::drag::start(&cx.ctx, cx.id, payload.clone(), None, preview);
|
||||
self.event = Some(RowEvent::ThumbDrag(target));
|
||||
self.event = Some(RowEvent::PartDrag(RowDragSpot::Thumb(target)));
|
||||
} else if let Some(source) = cx.part_activated(THUMB.at(at as u64)) {
|
||||
let clicks = part_clicks(source, phase);
|
||||
self.event = Some(RowEvent::ThumbClicked { target, mods: part_mods(cx, THUMB.at(at as u64), source), clicks });
|
||||
@@ -337,6 +349,17 @@ impl Component for ListRow<'_> {
|
||||
for trailing in &self.trailing {
|
||||
let TrailingItem::Part { part, .. } = &trailing.item else { continue };
|
||||
let key = TRAILING.at(u64::from(part.0));
|
||||
if let Some(payload) = self.drag_at(RowDragSpot::Trailing(*part)) {
|
||||
// A handle's click is the row's: only its drag is its own.
|
||||
if let Some(result) = cx.part_if_declared(key)
|
||||
&& matches!(result.press.phase, PressPhase::DragStart { .. })
|
||||
{
|
||||
let preview = DragPreview::frame(result.rect.size(), None);
|
||||
crate::runtime::drag::start(&cx.ctx, cx.id, payload.clone(), None, preview);
|
||||
self.event = Some(RowEvent::PartDrag(RowDragSpot::Trailing(*part)));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if let Some(source) = cx.part_activated(key) {
|
||||
if *part == TrailingPart::MENU {
|
||||
self.menu = Some(cx.part(key).rect);
|
||||
@@ -370,8 +393,11 @@ impl Component for ListRow<'_> {
|
||||
(None, None) => Name::FromLabel,
|
||||
};
|
||||
access.name(name);
|
||||
// A drag handle is no button: its name is part of the row's description, as a mark's is.
|
||||
let handle = |part: &TrailingPart| self.drag_at(RowDragSpot::Trailing(*part)).is_some();
|
||||
let icons = self.trailing.iter().filter_map(|trailing| match &trailing.item {
|
||||
TrailingItem::Icon { name, .. } | TrailingItem::Text { name: Some(name), .. } => Some(name.as_str().to_owned()),
|
||||
TrailingItem::Part { part, name, .. } if handle(part) => Some(name.as_str().to_owned()),
|
||||
_ => None,
|
||||
});
|
||||
let percent = self.progress.map(|fraction| cx.format().percent(f64::from(Progress::clamped(fraction)), 0));
|
||||
@@ -437,6 +463,7 @@ impl Component for ListRow<'_> {
|
||||
for (at, trailing) in self.trailing.iter().enumerate() {
|
||||
match &trailing.item {
|
||||
TrailingItem::Text { .. } | TrailingItem::Hosted(_) => {}
|
||||
TrailingItem::Part { part, .. } if handle(part) => {}
|
||||
TrailingItem::Icon { name, .. } => {
|
||||
access.node(TRAILING_ICON.at(at as u64), Role::IMAGE).name = Name::Text(name.as_str().to_owned());
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ pub enum TrailingFace {
|
||||
/// Whether the section is open.
|
||||
open: bool,
|
||||
},
|
||||
/// A short text in the caption role's semibold face, as wide as it measures (a layer's `fx`).
|
||||
Strong(Label),
|
||||
}
|
||||
|
||||
impl TrailingFace {
|
||||
|
||||
Reference in New Issue
Block a user