From f6ed0b250002404a705e0cd40ce51a535df6eac7 Mon Sep 17 00:00:00 2001 From: nicolafalcier99 Date: Thu, 19 Nov 2026 09:12:26 +0900 Subject: [PATCH] #3391: a Views 1 | 2 | 4 switch in the Composition viewer's control row (#3848) * contributors: Nicola Falcier * #3391: a Views 1 | 2 | 4 switch in the Composition viewer's control row --------- Co-authored-by: Nicola Falcier <298941634+nicolafalcier99@users.noreply.github.com> --- contributors/people.toml | 5 ++ crates/ui-egui/src/a11y.rs | 11 ++++ crates/ui-egui/src/i18n/ui.rs | 11 ++++ crates/ui-egui/src/panels/viewer_tools.rs | 32 ++++++++++ crates/ui-egui/tests/it/main.rs | 1 + crates/ui-egui/tests/it/ui_view_layout.rs | 70 ++++++++++++++++++++++ crates/ui-egui/tests/it/viewer_geometry.rs | 41 ++++++++++--- 7 files changed, 163 insertions(+), 8 deletions(-) create mode 100644 crates/ui-egui/tests/it/ui_view_layout.rs diff --git a/contributors/people.toml b/contributors/people.toml index beb91a413..4f77ce8d1 100644 --- a/contributors/people.toml +++ b/contributors/people.toml @@ -138,3 +138,8 @@ sync_github_name = true [people.andreaaazo] sync_github_name = true + +[people.nicolafalcier99] +real_name = "Nicola Falcier" +display_name = "Nicola Falcier" +sync_github_name = false diff --git a/crates/ui-egui/src/a11y.rs b/crates/ui-egui/src/a11y.rs index b8f88ae23..b33c8ac05 100644 --- a/crates/ui-egui/src/a11y.rs +++ b/crates/ui-egui/src/a11y.rs @@ -103,6 +103,17 @@ pub(crate) fn check_box(r: &Response, label: &str, checked: bool, enabled: bool) }); } +/// A push button that is one of a set of choices (a view-layout button): `pressed` is whether it is +/// the current one, exposed as the toggled state. `description` says what the set is. +pub(crate) fn choice_button(r: &Response, label: &str, description: &str, pressed: bool) { + node(r, |n| { + n.set_role(Role::Button); + n.set_label(label); + n.set_description(description); + n.set_toggled(if pressed { Toggled::True } else { Toggled::False }); + }); +} + /// A drop-down: `label` says what it sets and `value` is what it is set to. pub(crate) fn combo_box(r: &Response, label: &str, value: &str, enabled: bool) { node(r, |n| { diff --git a/crates/ui-egui/src/i18n/ui.rs b/crates/ui-egui/src/i18n/ui.rs index b2e0b3631..69a8d56a1 100644 --- a/crates/ui-egui/src/i18n/ui.rs +++ b/crates/ui-egui/src/i18n/ui.rs @@ -181,6 +181,7 @@ pub(crate) fn tr_args(text: &str, args: &[&dyn Display]) -> String { /// Japanese: the same rows, in the same order, as the Chinese catalogs below. const JAPANESE: &[(&str, &str)] = &[ + ("Views:", "画面:"), ("Click to sample color", "クリックして色をサンプル"), ("Appearance Settings…", "外観設定…"), ("Add to favorites", "お気に入りに追加"), @@ -1325,6 +1326,7 @@ const JAPANESE: &[(&str, &str)] = &[ ]; const SIMPLIFIED_CHINESE: &[(&str, &str)] = &[ + ("Views:", "视图:"), ("Click to sample color", "单击以取样颜色"), ("Appearance Settings…", "外观设置…"), ("Add to favorites", "添加到收藏"), @@ -2445,6 +2447,7 @@ const SIMPLIFIED_CHINESE: &[(&str, &str)] = &[ /// Swedish (`sv`), written from the English source. const SWEDISH: &[(&str, &str)] = &[ + ("Views:", "Vyer:"), ("Appearance Settings…", "Utseendeinställningar…"), ("Add to favorites", "Lägg till i favoriter"), ("Remove from favorites", "Ta bort från favoriter"), @@ -3721,6 +3724,7 @@ const SWEDISH: &[(&str, &str)] = &[ ]; const TRADITIONAL_CHINESE: &[(&str, &str)] = &[ + ("Views:", "檢視:"), ("Click to sample color", "按一下以取樣顏色"), ("Appearance Settings…", "外觀設定…"), ("Add to favorites", "加入最愛"), @@ -4790,6 +4794,7 @@ const TRADITIONAL_CHINESE: &[(&str, &str)] = &[ /// Ukrainian (uk): original translations of the same interface rows as the Chinese catalogs. /// Technical names, key names and substituted project content keep their original spelling. const UKRAINIAN: &[(&str, &str)] = &[ + ("Views:", "Вигляди:"), ("Click to sample color", "Клацніть, щоб узяти зразок кольору"), ("Appearance Settings…", "Налаштування вигляду…"), ("Add to favorites", "Додати до вибраного"), @@ -5380,6 +5385,7 @@ const UKRAINIAN: &[(&str, &str)] = &[ // Brazilian Portuguese. const PORTUGUESE: &[(&str, &str)] = &[ + ("Views:", "Visualizações:"), ("Click to sample color", "Clique para obter uma amostra de cor"), ("Export Scene to Blender...", "Exportar cena para o Blender..."), (" OK ", " OK "), @@ -6148,6 +6154,7 @@ const PORTUGUESE: &[(&str, &str)] = &[ /// Polish (pl): original translations covering every row in the Chinese panel catalogs. const POLISH: &[(&str, &str)] = &[ + ("Views:", "Widoki:"), ("Click to sample color", "Kliknij, aby pobrać próbkę koloru"), ("Appearance Settings…", "Ustawienia wyglądu…"), ("Add to favorites", "Dodaj do ulubionych"), @@ -6909,6 +6916,7 @@ const POLISH: &[(&str, &str)] = &[ /// Czech (cs): original translations covering every row in the Chinese panel catalogs. const CZECH: &[(&str, &str)] = &[ + ("Views:", "Zobrazení:"), ("Click to sample color", "Kliknutím naberete barvu"), (" OK ", " OK "), (" Delete ", " Odstranit "), @@ -7479,6 +7487,7 @@ const CZECH: &[(&str, &str)] = &[ /// order. Terms follow the Spanish menu catalog (composición, material de archivo, cola de procesamiento, /// ajuste preestablecido, método abreviado). Written from the English source. const SPANISH: &[(&str, &str)] = &[ + ("Views:", "Vistas:"), ("Click to sample color", "Haz clic para tomar una muestra de color"), ("Copy Source Path", "Copiar ruta de origen"), ("Appearance Settings…", "Ajustes de apariencia…"), @@ -8051,6 +8060,7 @@ const SPANISH: &[(&str, &str)] = &[ /// Georgian (ka): every row of the Chinese catalogs, in the same order (the tests keep them in step). const GEORGIAN: &[(&str, &str)] = &[ + ("Views:", "ხედები:"), ("Click to sample color", "დააწკაპუნეთ ფერის ნიმუშის ასაღებად"), ("Appearance Settings…", "იერსახის პარამეტრები…"), ("Add to favorites", "რჩეულებში დამატება"), @@ -9023,6 +9033,7 @@ const GEORGIAN_PANELS: &[(&str, &str)] = &[ /// clé, métrage, file d'attente de rendu, chronologie, repère, estampe). A no-break space precedes /// `:`, `;`, `?` and `!`, and the apostrophe is the typographic one. Written from the English source. const FRENCH: &[(&str, &str)] = &[ + ("Views:", "Vues\u{a0}:"), ("Appearance Settings…", "Paramètres d’apparence…"), ("Add to favorites", "Ajouter aux favoris"), ("Remove from favorites", "Retirer des favoris"), diff --git a/crates/ui-egui/src/panels/viewer_tools.rs b/crates/ui-egui/src/panels/viewer_tools.rs index ded5fbdb3..52e19e999 100644 --- a/crates/ui-egui/src/panels/viewer_tools.rs +++ b/crates/ui-egui/src/panels/viewer_tools.rs @@ -969,12 +969,16 @@ fn bottom_bar_contents(app: &mut EffectcraftApp, ui: &mut egui::Ui, bar: Rect, z let _ = app.session.execute("view.set3DView", json!({"view": View3D::ALL[i].id()})); } x = r.max.x + 4.0; + x = layout_switch(app, ui, x, cy, &t); // Extended Viewer (Settings ▸ 3D): custom views and Draft 3D show past the comp frame. let on = app.session.prefs.three_d.extended_viewer; if tog(ui, &mut app.auto, &mut x, Icon::ExtendedViewer, on, "extendedViewer", "Extended Viewer").0 { let _ = app.session.execute("view.extendedViewer", json!({})); } x += 2.0; + } else { + // A 2D comp has no 3D View menu, but it can still be in a 2/4-view layout: keep the way back. + x = layout_switch(app, ui, x, cy, &t); } // Current time. let tc = crate::panels::timecode(&app.session, comp, time); @@ -1005,6 +1009,34 @@ fn go_to_time_on_click(app: &mut EffectcraftApp, resp: &egui::Response) { } } +/// The "Views: 1 | 2 | 4" switch (#3391): a label and three text buttons, the current layout +/// highlighted; a click runs `view.layout`. Returns the x after it. +fn layout_switch(app: &mut EffectcraftApp, ui: &mut egui::Ui, mut x: f32, cy: f32, t: &Tokens) -> f32 { + let label = crate::i18n::tr("Views:"); + let g = ui.painter().layout_no_wrap(label.to_string(), Tokens::ui(11.0), t.text_dim); + ui.painter().galley(pos2(x, cy - g.size().y / 2.0), g.clone(), t.text_dim); + x += g.size().x + 4.0; + let current = app.session.state.view_layout; + for (n, text, tip) in [(1u8, "1", "1 View"), (2, "2", "2 Views"), (4, "4", "4 Views")] { + let r = Rect::from_min_size(pos2(x, cy - 10.0), vec2(26.0, 20.0)); + let resp = widgets::text_button(ui, r, text, current == n, t, egui::Id::unique(("vw-layout", n))); + // The drawn text is just "1" / "2" / "4": the accessible name is the full "N View(s)", the group + // label ("Views") is its description, and the current layout is exposed as pressed. + let name = crate::i18n::command_label("view.layout", tip); + crate::a11y::choice_button(&resp, name, label.trim_end_matches([':', ':', ' ', '\u{a0}']), current == n); + let resp = resp.on_hover_text(name); + app.auto.add_response(&format!("viewer.layout.{n}"), &resp, tip); + if resp.clicked() + && current != n + && let Err(e) = app.session.execute("view.layout", json!({"views": n})) + { + app.ui.status = e.to_string(); + } + x = r.max.x + 2.0; + } + x + 4.0 +} + #[cfg(test)] mod tests { use super::*; diff --git a/crates/ui-egui/tests/it/main.rs b/crates/ui-egui/tests/it/main.rs index 8b156cb51..f80611a9b 100644 --- a/crates/ui-egui/tests/it/main.rs +++ b/crates/ui-egui/tests/it/main.rs @@ -112,6 +112,7 @@ mod ui_toolbar_gradient; mod ui_tracker; mod ui_unreadable_footage; mod ui_video_preview_off; +mod ui_view_layout; mod ui_viewer; mod ui_viewer_trackpad; mod ui_viewers; diff --git a/crates/ui-egui/tests/it/ui_view_layout.rs b/crates/ui-egui/tests/it/ui_view_layout.rs new file mode 100644 index 000000000..a6af5c688 --- /dev/null +++ b/crates/ui-egui/tests/it/ui_view_layout.rs @@ -0,0 +1,70 @@ +//! #3391: the Composition viewer's control row has a "Views: 1 | 2 | 4" switch (egui_kittest). + +use effectcraft_engine::Session; +use effectcraft_ui_egui::EffectcraftApp; +use egui_kittest::Harness; +use serde_json::json; + +fn harness(comp: Option<&str>) -> Harness<'static, EffectcraftApp> { + let mut s = Session::default(); + s.execute("file.openDemoProject", json!({})).unwrap(); + if let Some(comp) = comp { + s.execute("comp.open", json!({"comp": comp})).unwrap(); + } + Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s)) +} + +/// Click the centre of the automation element `id`. +fn click_id(h: &mut Harness<'_, EffectcraftApp>, id: &str) { + h.run_steps(3); + let [x, y, w, hh] = h.state().auto.find(id).unwrap_or_else(|| panic!("{id} is registered")).rect; + let p = egui::pos2(x + w / 2.0, y + hh / 2.0); + h.input_mut().events.push(egui::Event::PointerMoved(p)); + h.input_mut().events.push(egui::Event::PointerButton { pos: p, button: egui::PointerButton::Primary, pressed: true, modifiers: egui::Modifiers::NONE }); + h.step(); + h.input_mut().events.push(egui::Event::PointerButton { pos: p, button: egui::PointerButton::Primary, pressed: false, modifiers: egui::Modifiers::NONE }); + h.run_steps(3); +} + +#[test] +fn the_layout_buttons_switch_between_one_two_and_four_views_in_a_3d_comp() { + let mut h = harness(Some("3D Showcase")); + h.run_steps(3); + assert!(h.state().auto.find("viewer.view3d").is_some(), "this is a 3D comp"); + for (id, want) in [("viewer.layout.4", 4), ("viewer.layout.2", 2), ("viewer.layout.1", 1)] { + click_id(&mut h, id); + assert_eq!(h.state().session.state.view_layout, want, "{id}"); + } +} + +#[test] +fn the_layout_buttons_are_there_in_a_2d_comp_too() { + let mut h = harness(None); + h.run_steps(3); + assert!(h.state().auto.find("viewer.view3d").is_none(), "this is a 2D comp"); + for id in ["viewer.layout.1", "viewer.layout.2", "viewer.layout.4"] { + assert!(h.state().auto.find(id).is_some(), "{id} is registered"); + } + click_id(&mut h, "viewer.layout.4"); + assert_eq!(h.state().session.state.view_layout, 4); +} + +#[test] +fn the_layout_buttons_are_named_in_full_and_expose_the_current_layout() { + use egui::accesskit::{Role, Toggled}; + use egui_kittest::kittest::{NodeT, Queryable}; + let mut h = harness(None); + h.run_steps(3); + let state = |h: &Harness<'_, EffectcraftApp>, name: &str| { + let node = h.query_by_label(name).unwrap_or_else(|| panic!("a button named {name:?}")); + let node = node.accesskit_node(); + assert_eq!(node.role(), Role::Button, "{name}"); + node.toggled() + }; + assert_eq!(state(&h, "1 View"), Some(Toggled::True)); + assert_eq!(state(&h, "2 Views"), Some(Toggled::False)); + assert_eq!(state(&h, "4 Views"), Some(Toggled::False)); + click_id(&mut h, "viewer.layout.2"); + assert_eq!(state(&h, "1 View"), Some(Toggled::False)); + assert_eq!(state(&h, "2 Views"), Some(Toggled::True)); +} diff --git a/crates/ui-egui/tests/it/viewer_geometry.rs b/crates/ui-egui/tests/it/viewer_geometry.rs index 8a212cc35..72ee46013 100644 --- a/crates/ui-egui/tests/it/viewer_geometry.rs +++ b/crates/ui-egui/tests/it/viewer_geometry.rs @@ -19,14 +19,22 @@ fn harness(width: f32, kind: ThemeKind) -> Harness<'static, EffectcraftApp> { fn harness_at_scale(width: f32, kind: ThemeKind, scale: f32) -> Harness<'static, EffectcraftApp> { let mut session = Session::default(); session.execute("comp.new", json!({"name":"Geometry validation", "width":640, "height":360, "duration":4})).unwrap(); - let mut h = Harness::builder().with_size(vec2(width, 360.0)).with_pixels_per_point(scale).build_ui_state( - |ui, app: &mut EffectcraftApp| { - app.auto.begin_frame(); - *app.frames.last_ms.lock().unwrap() = 0.0; - viewer::show(app, ui, ui.max_rect()); - }, - EffectcraftApp::new(session), - ); + let app = EffectcraftApp::new(session); + // Install the fonts the real app installs at startup *before* the harness's first pass: the control + // row draws `widgets::text_button` text in the "medium" family, which has no fonts until then. + let tokens = app.tokens; + let mut h = Harness::builder() + .with_size(vec2(width, 360.0)) + .with_pixels_per_point(scale) + .with_context_setup(move |ctx| theme::install(ctx, &tokens, "en")) + .build_ui_state( + |ui, app: &mut EffectcraftApp| { + app.auto.begin_frame(); + *app.frames.last_ms.lock().unwrap() = 0.0; + viewer::show(app, ui, ui.max_rect()); + }, + app, + ); let ctx = h.ctx.clone(); h.state_mut().set_theme(&ctx, kind); theme::install(&ctx, &h.state().tokens, "en"); @@ -107,7 +115,24 @@ fn compact_control_row_scrolls_and_preserves_interactions() { let timecode = rect(&h, "viewer.timecode"); let row = rect(&h, "viewer.controls"); assert!(timecode.left() >= row.left() && timecode.right() <= row.right(), "last viewer control must scroll into view: {timecode:?}"); + // The Views switch (#3391) widened the row, so the exposure reset is no longer in view at the far + // end: scroll back until it is, then check the scrolled controls as before. + for _ in 0..40 { + let e = rect(&h, "viewer.resetExposure"); + if e.left() >= row.left() && e.right() <= row.right() { + break; + } + h.event(Event::MouseWheel { + unit: egui::MouseWheelUnit::Point, + delta: vec2(40.0, 0.0), + modifiers: Default::default(), + phase: egui::TouchPhase::Move, + source: egui::MouseWheelSource::Wheel, + }); + h.run_steps(4); + } let exposure = rect(&h, "viewer.resetExposure"); + // The convergence check for the scroll-back loop above: it must have brought the control into view. assert!(exposure.left() >= row.left() && exposure.right() <= row.right()); h.state_mut().session.execute("view.exposure", json!({"stops":2.0})).unwrap(); h.run_steps(2);