From 6c8d4e2c67d6792e2451c8bbee0b486b2655df5c Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Tue, 10 Nov 2026 15:59:00 -0700 Subject: [PATCH] feat(ui): timeline marks layers with selected artwork, Properties shows mixed values (M1) Every layer row that holds selected items shows a square in the layer's colour after its name (and screen readers hear it). Properties lists the selection from every layer, titles it with how many layers it spans, shows the combined box's position for several elements and marks values that differ as mixed. --- src/panels.rs | 69 ++++++++++++++++++++++++++++++++++++++++--------- src/timeline.rs | 16 ++++++++++-- 2 files changed, 71 insertions(+), 14 deletions(-) diff --git a/src/panels.rs b/src/panels.rs index 10cc2aae..c3d0eeba 100644 --- a/src/panels.rs +++ b/src/panels.rs @@ -358,8 +358,8 @@ fn history(app: &mut App, ui: &mut egui::Ui) { } fn properties(app: &mut App, ui: &mut egui::Ui) { - let elements = app.s.visible_elements(); - let sel: Vec<_> = elements.iter().filter(|e| app.s.selection.contains(&e.id)).cloned().collect(); + // The selection on every layer (ADR 0044). + let sel: Vec<_> = app.s.selected_elements().into_iter().map(|(_, e)| e).collect(); // ---- tool options first while a drawing tool is in hand: they're what you reach for ---- if matches!(app.tool, Tool::Rect | Tool::Oval | Tool::Star | Tool::Line | Tool::Pen | Tool::Text | Tool::Pencil | Tool::Brush | Tool::Eraser | Tool::PaintBucket | Tool::InkBottle | Tool::Eyedropper) { @@ -393,8 +393,12 @@ fn properties(app: &mut App, ui: &mut egui::Ui) { } } if let Some(e) = sel.first() { - let title = if sel.len() > 1 { format!("{} elements", sel.len()) } else { element_label(&app.s.doc, e) }; - section(ui, "prop_selection", Section::Rule, &title, None, |ui| selection_props(app, ui, e, sel.len())); + let title = match (sel.len(), app.s.selected_layers().len()) { + (1, _) => element_label(&app.s.doc, e), + (n, 0 | 1) => format!("{n} elements"), + (n, l) => format!("{n} elements on {l} layers"), + }; + section(ui, "prop_selection", Section::Rule, &title, None, |ui| selection_props(app, ui, e, &sel)); } else { section(ui, "prop_document", Section::Rule, "Document", None, |ui| document_props(app, ui)); } @@ -407,7 +411,17 @@ fn properties(app: &mut App, ui: &mut egui::Ui) { } } -fn selection_props(app: &mut App, ui: &mut egui::Ui, e: &anicraft_engine::doc::Element, _count: usize) { +/// "mixed" after a value that differs across the selection (the field shows the first one's). +fn mixed(ui: &mut egui::Ui, differs: bool) { + if differs { + ui.label(text(Type::Caption, "mixed").color(T.text_faint)).on_hover_text("The selected elements differ here; it shows the first one's. A change applies to all of them"); + } +} + +/// The selection's properties: `e` is the first selected element, `all` the whole selection. +fn selection_props(app: &mut App, ui: &mut egui::Ui, e: &anicraft_engine::doc::Element, all: &[std::sync::Arc]) { + let many = all.len() > 1; + let differs = |f: &dyn Fn(&anicraft_engine::doc::Element) -> f32| all.iter().any(|x| (f(x) - f(e)).abs() > 1e-4); if let ElementKind::Symbol { symbol, events, .. } = &e.kind && app.s.doc.symbol(*symbol).is_some_and(|x| x.kind != SymbolKind::Graphic) { @@ -416,30 +430,51 @@ fn selection_props(app: &mut App, ui: &mut egui::Ui, e: &anicraft_engine::doc::E { let d = e.transform.decompose(); let (mut x, mut y, mut sx, mut sy, mut rot) = (d.tx, d.ty, d.sx * 100.0, d.sy * 100.0, d.rotation.to_degrees()); - row(ui, "Position", |ui| { - let a = ui.add(egui::DragValue::new(&mut x).prefix("X ").speed(1.0).max_decimals(1)).named("Position X"); - let b = ui.add(egui::DragValue::new(&mut y).prefix("Y ").speed(1.0).max_decimals(1)).named("Position Y"); - if a.changed() || b.changed() { - live(app, "Move", "element.set_transform", json!({"x": x, "y": y})); - } - }); + if many { + // Several elements: where their combined box is, as in Animate; a change moves them + // all together. + let b = app.s.selection_bounds(); + let (ox, oy) = (b.min.x, b.min.y); + let (mut bx, mut by) = (ox, oy); + row(ui, "Position", |ui| { + let a = ui.add(egui::DragValue::new(&mut bx).prefix("X ").speed(1.0).max_decimals(1)).named("Position X"); + let c = ui.add(egui::DragValue::new(&mut by).prefix("Y ").speed(1.0).max_decimals(1)).named("Position Y"); + if (a.changed() || c.changed()) && !b.is_empty() { + live(app, "Move", "element.translate", json!({"dx": bx - ox, "dy": by - oy})); + } + }); + } else { + row(ui, "Position", |ui| { + let a = ui.add(egui::DragValue::new(&mut x).prefix("X ").speed(1.0).max_decimals(1)).named("Position X"); + let b = ui.add(egui::DragValue::new(&mut y).prefix("Y ").speed(1.0).max_decimals(1)).named("Position Y"); + if a.changed() || b.changed() { + live(app, "Move", "element.set_transform", json!({"x": x, "y": y})); + } + }); + } + let scale_mixed = many && (differs(&|x| x.transform.decompose().sx) || differs(&|x| x.transform.decompose().sy)); row(ui, "Scale", |ui| { let a = ui.add(egui::DragValue::new(&mut sx).suffix(" %").speed(0.5).range(1.0..=10000.0).max_decimals(1)).named("Scale width"); let b = ui.add(egui::DragValue::new(&mut sy).suffix(" %").speed(0.5).range(1.0..=10000.0).max_decimals(1)).named("Scale height"); if a.changed() || b.changed() { live(app, "Scale", "element.set_transform", json!({"sx": sx / 100.0, "sy": sy / 100.0})); } + mixed(ui, scale_mixed); }); + let rot_mixed = many && differs(&|x| x.transform.decompose().rotation); row(ui, "Rotation", |ui| { if ui.add(egui::DragValue::new(&mut rot).suffix("°").speed(0.5).range(-360.0..=360.0).max_decimals(1)).named("Rotation").changed() { live(app, "Rotate", "element.set_transform", json!({"rotation": rot})); } + mixed(ui, rot_mixed); }); let mut alpha = e.color.alpha * 100.0; + let alpha_mixed = many && differs(&|x| x.color.alpha); row(ui, "Alpha", |ui| { if a11y::slider(ui, &mut alpha, 0.0..=100.0, "Alpha", a11y::SliderLook { suffix: " %", max_decimals: Some(0), ..Default::default() }).changed() { live(app, "Alpha", "element.set_alpha", json!({"alpha": alpha / 100.0})); } + mixed(ui, alpha_mixed); }); // Blending and filters, on movie clips and buttons as in Animate. if let ElementKind::Symbol { symbol, filters, .. } = &e.kind @@ -546,6 +581,14 @@ fn selection_props(app: &mut App, ui: &mut egui::Ui, e: &anicraft_engine::doc::E if let ElementKind::Shape(sh) = &e.kind { ui.add_space(4.0); let fill = sh.fill.as_ref().map(Paint::primary_color); + // Mixed: the selected shapes' fills, or lines, are not all alike. + let shapes: Vec<&anicraft_engine::doc::Shape> = all.iter().filter_map(|x| match &x.kind { + ElementKind::Shape(s) => Some(s), + _ => None, + }).collect(); + let fill_mixed = shapes.iter().any(|s| s.fill.as_ref().map(Paint::primary_color) != fill); + let line = |s: &anicraft_engine::doc::Shape| s.stroke.as_ref().map(|st| (st.color, st.width.to_bits())); + let stroke_mixed = shapes.iter().any(|s| line(s) != line(sh)); row(ui, "Fill", |ui| { let is_grad = matches!(sh.fill, Some(Paint::Linear { .. } | Paint::Radial { .. })); let mut c = rgb(fill.unwrap_or(Rgba::WHITE)); @@ -562,6 +605,7 @@ fn selection_props(app: &mut App, ui: &mut egui::Ui, e: &anicraft_engine::doc::E } else if is_grad { ui.label(text(Type::Caption, "gradient")); } + mixed(ui, fill_mixed); }); let mut sc = rgb(sh.stroke.as_ref().map_or(app.s.style.stroke, |s| s.color)); let mut sw = sh.stroke.as_ref().map_or(0.0, |s| s.width); @@ -572,6 +616,7 @@ fn selection_props(app: &mut App, ui: &mut egui::Ui, e: &anicraft_engine::doc::E if ui.add(egui::DragValue::new(&mut sw).suffix(" px").speed(0.1).range(0.0..=200.0).max_decimals(1)).named("Stroke width").changed() { live(app, "Stroke width", "element.set_stroke", json!({"width": sw})); } + mixed(ui, stroke_mixed); }); if let Some(st) = &sh.stroke { // The width profile, as Animate's Width menu: built-ins with a picture of each. diff --git a/src/timeline.rs b/src/timeline.rs index 0814bd06..cfd59295 100644 --- a/src/timeline.rs +++ b/src/timeline.rs @@ -38,6 +38,8 @@ const FOOTER_H: f32 = 38.0; const TOGGLE: f32 = 24.0; /// Indent per folder or mask level in the layer list. const INDENT: f32 = 14.0; +/// The selected-artwork square after a layer's name (points). +const SEL_MARK: f32 = 7.0; /// A rectangle of frames: the layers between the anchor's and the head's rows (in the /// current layer order) by the frames between them. View state: commands get explicit ranges. @@ -315,6 +317,9 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) { // rows let layers = app.s.doc.timeline(app.s.scene).layers.clone(); let active = app.s.layer; + // Layers with selected artwork show a square in their colour after the name, as in + // Animate: a selection can span layers (ADR 0044). + let holding = app.s.selection.layers(); let rows_top = ruler.bottom(); let rows_bottom = body.bottom() - FOOTER_H; let tl_now = app.s.doc.timeline(app.s.scene).clone(); @@ -370,7 +375,13 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) { } _ => x0 + 4.0, }; - painter.text(pos2(name_x, left.center().y), Align2::LEFT_CENTER, &layer.name, font(Type::Body), name_color); + let name_at = painter.text(pos2(name_x, left.center().y), Align2::LEFT_CENTER, &layer.name, font(Type::Body), name_color); + let has_selection = holding.contains(&layer.id); + if has_selection { + let sq = Rect::from_center_size(pos2(name_at.right() + 9.0, left.center().y), vec2(SEL_MARK, SEL_MARK)); + painter.rect_filled(sq, 0.0, to_color32(layer.color)); + painter.rect_stroke(sq, 0.0, Stroke::new(1.0, T.text), StrokeKind::Outside); + } // eye / lock / outline toggles: 24 × 24 targets with a hover fill let toggle = |k: f32| Rect::from_center_size(pos2(left.right() - 16.0 - k * (TOGGLE + 2.0), left.center().y), vec2(TOGGLE, TOGGLE)); @@ -416,7 +427,8 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) { LayerKind::Normal if masked => "masked layer", LayerKind::Normal => "layer", }; - a11y::control(ui, &nr, WidgetType::SelectableLabel, &format!("{} · {kind}", layer.name), Some(is_active)); + let held = if has_selection { " · has selected artwork" } else { "" }; + a11y::control(ui, &nr, WidgetType::SelectableLabel, &format!("{} · {kind}{held}", layer.name), Some(is_active)); // Ctrl+F6 lands on the active layer, or on the top row shown when it is scrolled away // (rows are drawn top down, so the active row, when drawn, has the last word). if is_active || r == first_row {