EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust
Merge pull request #979 from nanox333/codex/fix-958-vector-context-menu
Brandon Thomasfe439f6e9c2b
diff --cc crates/ui-egui/src/panels/timeline.rsindex aa597d904,57b2830c2..8962204f4--- a/crates/ui-egui/src/panels/timeline.rs+++ b/crates/ui-egui/src/panels/timeline.rs@@@ -1900,12 -1870,16 +1900,12 @@@ pub fn show(app: &mut EffectcraftApp, u}}if row_resp.double_clicked() {- match &layer.source {- LayerSource::Comp { item } => actions.push(("comp.open".into(), json!({"comp": item.0}))),- // Footage and solids open in the Layer panel (paint happens there).- LayerSource::Footage { .. } | LayerSource::Solid { .. } => {- actions.push(("layer.openLayer".into(), json!({"layer": layer.id.0})));- }- _ => start_rename(&ctx, layer.id.0, &layer.name),+ match double_click_action(layer) {+ Some(a) => actions.push(a),+ None => start_rename(&ctx, layer.id.0, &layer.name),}}- layer_context_menu(&row_resp, &comp, layer, &selected, &mut actions);- layer_context_menu(&row_resp, layer, vector_footage_layer(&app.session.project, layer), &mut actions);++ layer_context_menu(&row_resp, &comp, layer, &selected, vector_footage_layer(&app.session.project, layer), &mut actions);// Switches.let sws: [(Icon, bool, &str, bool); 8] = [(Icon::Shy, sw.shy, "shy", true),@@@ -2124,7 -2097,7 +2124,7 @@@set_anchor(&ctx, cid, layer.id);}}- layer_context_menu(&body, &comp, layer, &selected, &mut actions);- layer_context_menu(&body, layer, vector_footage_layer(&app.session.project, layer), &mut actions);++ layer_context_menu(&body, &comp, layer, &selected, vector_footage_layer(&app.session.project, layer), &mut actions);let drag_key = format!("bar-{}", layer.id.0);for (resp, kind) in [(&body, "move"), (&lin, "in"), (&lout, "out")] {if resp.dragged() {@@@ -3494,16 -3442,16 +3494,24 @@@ fn prop_menuitem(ui, "essentialGraphics", "Add Property to Essential Graphics", false, "essential.addProperty", json!({"comp": comp.0, "layer": l, "prop": uid}));}+/// A layer row's or bar's context menu. As in After Effects, right-clicking a layer that is part+/// of the selection keeps the selection and the menu acts on all of it; right-clicking an+/// unselected layer selects only that layer.- fn layer_context_menu(resp: &egui::Response, comp: &Comp, layer: &Layer, selected: &[LayerId], actions: &mut Vec<(String, serde_json::Value)>) {+ pub(crate) fn vector_footage_layer(project: &effectcraft_engine::project::Project, layer: &Layer) -> bool {+ layer+ .source+ .item()+ .and_then(|item| project.item(item))+ .is_some_and(|item| matches!(&item.kind, effectcraft_engine::project::ItemKind::Footage(footage) if effectcraft_engine::vector::is_vector(footage)))+ }+-fn layer_context_menu(resp: &egui::Response, layer: &Layer, vector: bool, actions: &mut Vec<(String, serde_json::Value)>) {- resp.context_menu(|ui| layer_menu(ui, &[layer.id.0], vector, actions));++fn layer_context_menu(resp: &egui::Response, comp: &Comp, layer: &Layer, selected: &[LayerId], vector: bool, actions: &mut Vec<(String, serde_json::Value)>) {+ let in_selection = selected.contains(&layer.id);+ if resp.secondary_clicked() && !in_selection && !layer.switches.locked {+ actions.push(("layer.select".into(), json!({"layers": [layer.id.0]})));+ }+ let targets: Vec<u64> = if in_selection { comp.layers.iter().filter(|l| selected.contains(&l.id)).map(|l| l.id.0).collect() } else { vec![layer.id.0] };- crate::widgets::context_menu(&resp, |ui| layer_menu(ui, &targets, actions));++ crate::widgets::context_menu(&resp, |ui| layer_menu(ui, &targets, vector, actions));}/// Shared layer actions for Timeline rows and Composition context menus.diff --cc crates/ui-egui/src/panels/viewer.rsindex 42a5b8063,7b43be165..a41d7883f--- a/crates/ui-egui/src/panels/viewer.rs+++ b/crates/ui-egui/src/panels/viewer.rs@@@ -1219,13 -1131,12 +1219,17 @@@ pub fn show(app: &mut EffectcraftApp, uif context_layers.is_empty() {ui.label(crate::i18n::tr("No unlocked layer selected"));} else {- super::timeline::layer_menu(ui, &context_layers, &mut context_actions);+ let vector = context_layers+ .iter()+ .filter_map(|id| comp.layer(effectcraft_engine::project::LayerId(*id)))+ .any(|layer| super::timeline::vector_footage_layer(&app.session.project, layer));+ super::timeline::layer_menu(ui, &context_layers, vector, &mut context_actions);}+ ui.separator();+ if ui.button(copy_frame).clicked() {+ context_actions.push(("comp.copyFrame".to_owned(), serde_json::json!({"comp": cid.0})));+ ui.close();+ }});for (id, params) in context_actions {if let Err(e) = crate::menus::invoke(app, &ctx, &id, params) {