FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
Scroll the timeline clip menu when it is taller than the screen (#2852) (#2862)
HEOJUNFO700bdd9190c0
diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rsindex a73611886..33c243762 100644--- a/crates/ui-egui/src/panels/timeline.rs+++ b/crates/ui-egui/src/panels/timeline.rs@@ -2861,76 +2861,80 @@ fn interact(app: &mut FilmcraftApp, ui: &mut egui::Ui, seq: &Sequence, layout: &}}resp.context_menu(|ui| {- ui.set_min_width(220.0);- if let Some(marker) = ctx.data(|d| d.get_temp::<Option<MarkerId>>(marker_menu_id)).flatten() {- marker_menu(app, &ctx, ui, marker);- return;- }- if let Some(target) = ctx.data(|d| d.get_temp::<Option<EditPointTarget>>(edit_point_menu_id)).flatten() {- edit_point_menu(app, &ctx, ui, seq, target);- return;- }- if ctx.data(|d| d.get_temp::<bool>(gap_menu_id)).unwrap_or(false) {- gap_menu(app, &ctx, ui);- return;- }- let sel = app.session.state.selection.clone();- let picked: Vec<&filmcraft_project::TrackItem> = sel.iter().filter_map(|c| seq.find_item(*c).map(|(_, it)| it)).collect();- let all_enabled = !picked.is_empty() && picked.iter().all(|it| it.enabled);- let linked = picked.iter().any(|it| it.link.is_some());- let mut first = true;- for group in CLIP_MENU {- if !std::mem::take(&mut first) {- ui.separator();- }- for &(label, cmd) in *group {- if cmd == "edit.label" {- ui.add_enabled_ui(!picked.is_empty(), |ui| {- let menu = ui.menu_button(crate::i18n::t(label), |ui| {- // the user's label names and colours, as in Edit ▸ Label (#786)- let labels = app.session.prefs.labels.clone();- for l in filmcraft_project::Label::ALL {- if crate::menus::label_choice(ui, &mut app.auto, &labels, l, "timeline.clipMenu.label").clicked() {- if let Err(error) = app.session.execute("edit.label", json!({"label":l.name()})) {- app.ui.status = error.to_string();+ // a long menu scrolls instead of running off the bottom of the screen (#2852)+ let max_height = (ui.ctx().content_rect().height() - 16.0).max(0.0);+ egui::ScrollArea::vertical().id_salt("clip-menu-scroll").max_height(max_height).min_scrolled_height(max_height).show(ui, |ui| {+ ui.set_min_width(220.0);+ if let Some(marker) = ctx.data(|d| d.get_temp::<Option<MarkerId>>(marker_menu_id)).flatten() {+ marker_menu(app, &ctx, ui, marker);+ return;+ }+ if let Some(target) = ctx.data(|d| d.get_temp::<Option<EditPointTarget>>(edit_point_menu_id)).flatten() {+ edit_point_menu(app, &ctx, ui, seq, target);+ return;+ }+ if ctx.data(|d| d.get_temp::<bool>(gap_menu_id)).unwrap_or(false) {+ gap_menu(app, &ctx, ui);+ return;+ }+ let sel = app.session.state.selection.clone();+ let picked: Vec<&filmcraft_project::TrackItem> = sel.iter().filter_map(|c| seq.find_item(*c).map(|(_, it)| it)).collect();+ let all_enabled = !picked.is_empty() && picked.iter().all(|it| it.enabled);+ let linked = picked.iter().any(|it| it.link.is_some());+ let mut first = true;+ for group in CLIP_MENU {+ if !std::mem::take(&mut first) {+ ui.separator();+ }+ for &(label, cmd) in *group {+ if cmd == "edit.label" {+ ui.add_enabled_ui(!picked.is_empty(), |ui| {+ let menu = ui.menu_button(crate::i18n::t(label), |ui| {+ // the user's label names and colours, as in Edit ▸ Label (#786)+ let labels = app.session.prefs.labels.clone();+ for l in filmcraft_project::Label::ALL {+ if crate::menus::label_choice(ui, &mut app.auto, &labels, l, "timeline.clipMenu.label").clicked() {+ if let Err(error) = app.session.execute("edit.label", json!({"label":l.name()})) {+ app.ui.status = error.to_string();+ }+ ui.close();}- ui.close();}- }+ });+ app.auto.add_response("timeline.clipMenu.edit.label", &menu.response, crate::i18n::t(label));});- app.auto.add_response("timeline.clipMenu.edit.label", &menu.response, crate::i18n::t(label));- });- continue;- }- if cmd == "clip.multicam" {- multicam_menu(app, ui, &picked);- continue;- }- let label = match cmd {- "clip.enable" if all_enabled => tl!("✓ Enable"),- "clip.link" if linked => tl!("Unlink"),- _ => crate::i18n::t(label),- };- let r = ui.add_enabled(!sel.is_empty() && app.session.is_enabled(cmd), egui::Button::new(label));- app.auto.add(&format!("timeline.clipMenu.{cmd}"), r.rect, label);- if r.clicked() {- match crate::menus::invoke(app, &ctx, cmd, json!({})) {- // Unlink (#220): the clips were selected together because they were linked;- // keep only the one right-clicked, so it can be dragged away from the others- Ok(v) if cmd == "clip.link" && v["linked"] == json!(false) => {- if let Some(clip) = ctx.data(|d| d.get_temp::<ClipId>(menu_clip_id))- && app.session.state.selection.contains(&clip)- {- let _ = app.session.execute("timeline.select", json!({"clips": [clip.0]}));+ continue;+ }+ if cmd == "clip.multicam" {+ multicam_menu(app, ui, &picked);+ continue;+ }+ let label = match cmd {+ "clip.enable" if all_enabled => tl!("✓ Enable"),+ "clip.link" if linked => tl!("Unlink"),+ _ => crate::i18n::t(label),+ };+ let r = ui.add_enabled(!sel.is_empty() && app.session.is_enabled(cmd), egui::Button::new(label));+ app.auto.add(&format!("timeline.clipMenu.{cmd}"), r.rect, label);+ if r.clicked() {+ match crate::menus::invoke(app, &ctx, cmd, json!({})) {+ // Unlink (#220): the clips were selected together because they were linked;+ // keep only the one right-clicked, so it can be dragged away from the others+ Ok(v) if cmd == "clip.link" && v["linked"] == json!(false) => {+ if let Some(clip) = ctx.data(|d| d.get_temp::<ClipId>(menu_clip_id))+ && app.session.state.selection.contains(&clip)+ {+ let _ = app.session.execute("timeline.select", json!({"clips": [clip.0]}));+ }}+ Ok(_) => {}+ Err(e) => app.ui.status = e,}- Ok(_) => {}- Err(e) => app.ui.status = e,+ ui.close();}- ui.close();}}- }+ });});// ---- drops: project items and effectsdiff --git a/crates/ui-egui/tests/edit_point_menu_ui.rs b/crates/ui-egui/tests/edit_point_menu_ui.rsindex d4e259b50..afe545975 100644--- a/crates/ui-egui/tests/edit_point_menu_ui.rs+++ b/crates/ui-egui/tests/edit_point_menu_ui.rs@@ -18,11 +18,15 @@ struct Driver {impl Driver {fn new() -> Self {+ Self::with_height(980.0)+ }++ fn with_height(height: f32) -> Self {let mut s = Session::default();s.execute("file.openDemoProject", json!({})).unwrap();let (tx, rx) = channel();let app = FilmcraftApp::new(s).with_control(rx);- let harness = Harness::builder().with_size(egui::vec2(1600.0, 980.0)).with_max_steps(10_000).build_eframe(move |_cc| app);+ let harness = Harness::builder().with_size(egui::vec2(1600.0, height)).with_max_steps(10_000).build_eframe(move |_cc| app);let mut d = Driver { harness, tx };d.frames(4);d@@ -66,6 +70,14 @@ impl Driver {v.as_array().unwrap().iter().any(|e| e["id"] == json!(id))}+ /// [x, y, width, height]+ fn rect(&mut self, id: &str) -> [f64; 4] {+ let v = self.ok("ui.elements", json!({"prefix": id}));+ let e = v.as_array().unwrap().iter().find(|e| e["id"] == json!(id)).unwrap_or_else(|| panic!("no element {id}"));+ let r: Vec<f64> = e["rect"].as_array().unwrap().iter().map(|x| x.as_f64().unwrap()).collect();+ [r[0], r[1], r[2], r[3]]+ }+fn seq(&mut self) -> Sequence {self.harness.state_mut().session.active_sequence().unwrap().clone()}@@ -158,3 +170,18 @@ fn join_through_edits_joins_only_the_right_clicked_cut() {d.click("timeline.editPointMenu.joinThroughEdits");assert_eq!(d.seq().video_tracks[0].items.len(), before, "disabled: nothing joined");}++/// #2852: on a short screen the clip menu scrolls, so the items past its bottom can be reached.+#[test]+fn the_clip_menu_scrolls_on_a_short_screen() {+ let height = 600.0;+ let mut d = Driver::with_height(height as f32);+ let (_, b) = d.cut_on_v1();+ d.right_click(b, 0.5);+ let last = "timeline.clipMenu.sequence.joinThroughEdits";+ assert!(d.rect(last)[1] > height, "the menu is taller than the screen");+ d.ok("ui.scroll", json!({"id": "timeline.clipMenu.edit.cut", "dy": -2000.0}));+ d.frames(10);+ let r = d.rect(last);+ assert!(r[1] >= 0.0 && r[1] + r[3] <= height, "Join Through Edits scrolled into view: {r:?}");+}