From 4d318a5347bd2608870ea2dcd2e91183b319e100 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Tue, 17 Nov 2026 16:11:18 +0530 Subject: [PATCH] #3585: scroll the effect Up / Down picks into view Effect Controls scrolls its list so the header Down / Up selected is in view, as a long effect stack would otherwise move the selection off screen. The key handler leaves the effect to reveal for the panel's next pass, which knows where the header is laid out. --- crates/ui-egui/src/menus/shortcuts.rs | 2 +- .../src/panels/effect_controls/panel.rs | 25 +++++++++++++- crates/ui-egui/tests/it/ui_effect_controls.rs | 34 +++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/menus/shortcuts.rs b/crates/ui-egui/src/menus/shortcuts.rs index ff48f4d45..eaca5568a 100644 --- a/crates/ui-egui/src/menus/shortcuts.rs +++ b/crates/ui-egui/src/menus/shortcuts.rs @@ -403,7 +403,7 @@ fn handle_shortcuts_impl(app: &mut EffectcraftApp, ctx: &egui::Context, tab_only if app.dialog.is_some() { continue; } - if !mods.any() && crate::panels::effect_controls::handle_arrow_key(app, key) { + if !mods.any() && crate::panels::effect_controls::handle_arrow_key(app, ctx, key) { ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, key)); continue; } diff --git a/crates/ui-egui/src/panels/effect_controls/panel.rs b/crates/ui-egui/src/panels/effect_controls/panel.rs index 5c06dec61..f89a6eac0 100644 --- a/crates/ui-egui/src/panels/effect_controls/panel.rs +++ b/crates/ui-egui/src/panels/effect_controls/panel.rs @@ -11,7 +11,7 @@ use crate::dock::{PanelKind, WorkspaceExt as _}; /// last frame (a maximized frame hides every other frame and every floating window), not behind /// Home. Only the effect headers selected on the layer the panel shows (the locked one when it is /// locked) count: with none the arrows still nudge. -pub(crate) fn handle_arrow_key(app: &mut EffectcraftApp, key: egui::Key) -> bool { +pub(crate) fn handle_arrow_key(app: &mut EffectcraftApp, ctx: &egui::Context, key: egui::Key) -> bool { use egui::Key::{ArrowDown, ArrowLeft, ArrowRight, ArrowUp}; let panel = PanelKind::EffectControls; if app.ui.focused != panel @@ -36,6 +36,7 @@ pub(crate) fn handle_arrow_key(app: &mut EffectcraftApp, key: egui::Key) -> bool if let Some(&uid) = headers.get(to) { // A selection, as a click on the header makes it: no undo step. app.session.state.selected_props = vec![(layer_id, uid)]; + reveal_effect(ctx, uid); } } _ => { @@ -51,6 +52,17 @@ pub(crate) fn handle_arrow_key(app: &mut EffectcraftApp, key: egui::Key) -> bool true } +/// The effect header the next Effect Controls pass scrolls into view. +fn reveal_id() -> egui::Id { + egui::Id::unique("ec-reveal") +} + +/// Scroll Effect Controls so effect `uid`'s header is in view, once it has been laid out. +fn reveal_effect(ctx: &egui::Context, uid: u64) { + ctx.data_mut(|d| d.insert_temp(reveal_id(), uid)); + ctx.request_repaint(); +} + // --------------------------------------------------------------------------------------------- /// Open the rename field on effect `uid` (Enter with the effect selected). It takes the keyboard, @@ -449,7 +461,18 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { actions.extend(crate::menus::menu_contents(app, ui, "Effect")); }); let content_h = y + scroll.offset - body.min.y; + let offset = scroll.offset; scroll.end(ui, &mut app.auto, "effectControls.scroll", content_h, &t); + // Up / Down picked an effect: bring its header into view from the next pass (after `end`, + // which stores this pass's offset). + if let Some(uid) = ctx.data_mut(|d| d.remove_temp::(reveal_id())) + && let Some(&(_, top)) = tops.iter().find(|(u, _)| *u == uid) + { + // (With the 4-point gap above the first header.) + let top = top - body.min.y + offset; + widgets::PanelScroll::reveal(&ctx, egui::Id::unique("ec-scroll"), top - 4.0, top + ROW + 2.0, body.height()); + ctx.request_repaint(); + } drop_payload(ui, rect, &p, &t, layer.id.0, &mut actions); if ui.input(|i| i.pointer.primary_down()) && actions.iter().any(|(id, _)| id == "prop.set") { app.ui.viewer.property_interacting = true; diff --git a/crates/ui-egui/tests/it/ui_effect_controls.rs b/crates/ui-egui/tests/it/ui_effect_controls.rs index 88f705f89..49de1f24c 100644 --- a/crates/ui-egui/tests/it/ui_effect_controls.rs +++ b/crates/ui-egui/tests/it/ui_effect_controls.rs @@ -426,6 +426,40 @@ fn effect_header_arrows_act_on_the_locked_layer() { assert!(h.state().ui.fx_closed.is_empty()); } +/// #3585: a long effect list scrolls so the effect Down / Up picks stays in view. +#[test] +fn effect_header_down_and_up_scroll_the_picked_effect_into_view() { + let mut s = Session::default(); + s.execute("comp.new", json!({"name": "Long", "width": 32, "height": 18, "frameRate": 30, "duration": 2})).unwrap(); + let lid = s.execute("layer.newSolid", json!({"name": "Controls", "color": "#40b080"})).unwrap()["layer"].as_u64().unwrap(); + let fx: Vec = + (0..16).map(|_| s.execute("effect.apply", json!({"layers": [lid], "effect": "Point Control"})).unwrap()["effects"][0].as_u64().unwrap()).collect(); + s.state.selected_props = vec![(LayerId(lid), fx[0])]; + let mut app = EffectcraftApp::new(s); + app.show_panel(PanelKind::EffectControls); + app.toggle_maximize(PanelKind::EffectControls); + app.ui.focused = PanelKind::EffectControls; + let mut h = Harness::builder().with_size(egui::vec2(800.0, 300.0)).with_step_dt(1.0 / 60.0).build_eframe(|_| app); + h.run_steps(4); + let panel = rect_of(&h, "panel.EffectControls"); + let last = fx[fx.len() - 1]; + assert!(!panel.contains_rect(rect_of(&h, &format!("effectControls.effect.{last}"))), "the last effect starts out of view"); + for _ in 1..fx.len() { + header_arrow_key(&mut h, egui::Key::ArrowDown, egui::Modifiers::NONE); + h.run_steps(2); + let (_, uid) = h.state().session.state.selected_props[0]; + assert!(panel.contains_rect(rect_of(&h, &format!("effectControls.effect.{uid}"))), "Down keeps effect {uid} in view"); + } + assert_eq!(h.state().session.state.selected_props, vec![(LayerId(lid), last)]); + for _ in 1..fx.len() { + header_arrow_key(&mut h, egui::Key::ArrowUp, egui::Modifiers::NONE); + h.run_steps(2); + let (_, uid) = h.state().session.state.selected_props[0]; + assert!(panel.contains_rect(rect_of(&h, &format!("effectControls.effect.{uid}"))), "Up keeps effect {uid} in view"); + } + assert_eq!(h.state().session.state.selected_props, vec![(LayerId(lid), fx[0])]); +} + #[test] fn effect_controls_widgets_register_automation_ids() { let (app, x) = app();