From cac9c70afc5afcdeb4d494188f6074ca893c05ad Mon Sep 17 00:00:00 2001 From: DuBearte <130190089+DuBearte@users.noreply.github.com> Date: Sun, 8 Nov 2026 00:11:58 -0500 Subject: [PATCH] Zoom tool bar: 100%, Fit Screen and Fill Screen with the reference tooltips (#12068) Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/panels/options_bar.rs | 41 ++++++----- .../panels/options_bar/zoom_buttons_tests.rs | 69 +++++++++++++++++++ 2 files changed, 93 insertions(+), 17 deletions(-) create mode 100644 crates/ui-egui/src/panels/options_bar/zoom_buttons_tests.rs diff --git a/crates/ui-egui/src/panels/options_bar.rs b/crates/ui-egui/src/panels/options_bar.rs index df45e61d01..b4bd565c76 100644 --- a/crates/ui-egui/src/panels/options_bar.rs +++ b/crates/ui-egui/src/panels/options_bar.rs @@ -649,25 +649,13 @@ fn tool_specific_options(app: &mut PhotocraftApp, ui: &mut egui::Ui, t: Tokens, // Resize Windows to Fit is Preferences › Zoom Resizes Windows itself, as in // Photoshop: one setting, shown in both places (zoom_window_fit.rs). let mut fit = app.session.prefs().general.zoom_resizes_windows; - if widgets::checkbox(ui, &mut fit, tl!("Resize Windows to Fit")).changed() { + if widgets::checkbox(ui, &mut fit, tl!("Resize Windows to Fit")).on_hover_text(tl!("Resize windows when zooming using the Zoom Tool")).changed() { app.session.prefs.edit(|p| p.general.zoom_resizes_windows = fit); } - widgets::checkbox(ui, &mut app.ui.tool_options.zoom_scrubby, tl!("Scrubby Zoom")); - hint( - ui, - &crate::i18n::fmt( - tl!("Click to zoom in · {key}-click to zoom out · drag right/left to zoom in/out"), - &[("key", &crate::shortcuts::pretty("Alt"))], - ), - ); - if widgets::secondary_button(ui, tl!("Fit Screen"), 0.0).clicked() - && let Some(i) = app.session.active_index() - { - app.ui.views[i].fit_pending = true; - app.ui.views[i].request_zoom_animation(app.session.prefs().general.animated_zoom); - app.ui.views[i].zoom_anchor = None; - } - if widgets::secondary_button(ui, "100%", 0.0).clicked() + widgets::checkbox(ui, &mut app.ui.tool_options.zoom_scrubby, tl!("Scrubby Zoom")) + .on_hover_text(tl!("Click and move left or right to scale using the Zoom Tool (OpenGL only)")); + // The same three buttons as the Hand bar, with the reference tooltips (#12068). + if widgets::secondary_button(ui, "100%", 0.0).on_hover_text(tl!("Zoom current window to 1:1")).clicked() && let Some(i) = app.session.active_index() { app.ui.views[i].zoom = 1.0; @@ -676,6 +664,22 @@ fn tool_specific_options(app: &mut PhotocraftApp, ui: &mut egui::Ui, t: Tokens, app.ui.views[i].fit_pending = false; app.ui.views[i].fill_pending = false; } + if widgets::secondary_button(ui, tl!("Fit Screen"), 0.0).on_hover_text(tl!("Zoom current window to screen size")).clicked() + && let Some(i) = app.session.active_index() + { + app.ui.views[i].fit_pending = true; + app.ui.views[i].request_zoom_animation(app.session.prefs().general.animated_zoom); + app.ui.views[i].zoom_anchor = None; + app.ui.views[i].fill_pending = false; + } + if widgets::secondary_button(ui, tl!("Fill Screen"), 0.0).on_hover_text(tl!("Zoom current window to fill the screen")).clicked() + && let Some(i) = app.session.active_index() + { + app.ui.views[i].fill_pending = true; + app.ui.views[i].request_zoom_animation(app.session.prefs().general.animated_zoom); + app.ui.views[i].zoom_anchor = None; + app.ui.views[i].fit_pending = false; + } } Tool::RotateView => { hint(ui, tl!("Drag around the center to rotate the view · Shift constrains to 15°")); @@ -727,6 +731,9 @@ fn tool_specific_options(app: &mut PhotocraftApp, ui: &mut egui::Ui, t: Tokens, } } +#[cfg(test)] +mod zoom_buttons_tests; + /// Width of the Layers panel's Opacity and Fill fields, with room for their pop-up slider's ▾. pub(super) const LAYER_PCT_W: f32 = 66.0 + widgets::POPUP_ARROW_W; diff --git a/crates/ui-egui/src/panels/options_bar/zoom_buttons_tests.rs b/crates/ui-egui/src/panels/options_bar/zoom_buttons_tests.rs new file mode 100644 index 0000000000..ce00ce0bc7 --- /dev/null +++ b/crates/ui-egui/src/panels/options_bar/zoom_buttons_tests.rs @@ -0,0 +1,69 @@ +//! #12068: the Zoom tool's bar shows 100%, Fit Screen and Fill Screen in that order, with the +//! reference tooltips, and no hint text. + +use egui::vec2; +use egui_kittest::Harness; +use egui_kittest::kittest::Queryable; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::state::Tool; + +fn zoom_bar() -> Harness<'static, PhotocraftApp> { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 3000, "height": 2000})).unwrap(); + // The bar's fonts are installed after the first frame, so it starts on a tool without "100%". + app.ui.tool = Tool::Move; + let mut h = Harness::builder().with_size(vec2(1600.0, 300.0)).with_step_dt(1.0 / 60.0).build_ui_state(|ui, app| crate::panels::options_bar(app, ui), app); + PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ProMedium); + h.state_mut().ui.tool = Tool::Zoom; + h.run_steps(4); + h +} + +#[test] +fn the_buttons_are_100_fit_and_fill_in_that_order() { + let h = zoom_bar(); + let x = |label: &str| h.get_by_label(label).rect().center().x; + assert!(x("Scrubby Zoom") < x("100%"), "after the checkboxes"); + assert!(x("100%") < x("Fit Screen") && x("Fit Screen") < x("Fill Screen")); +} + +#[test] +fn each_control_has_the_reference_tooltip() { + for (label, tip) in [ + ("100%", "Zoom current window to 1:1"), + ("Fit Screen", "Zoom current window to screen size"), + ("Fill Screen", "Zoom current window to fill the screen"), + ("Resize Windows to Fit", "Resize windows when zooming using the Zoom Tool"), + ("Scrubby Zoom", "Click and move left or right to scale using the Zoom Tool (OpenGL only)"), + ] { + let mut h = zoom_bar(); + h.get_by_label(label).hover(); + h.run_steps(60); + assert!(h.query_by_label(tip).is_some(), "{label}: no tooltip {tip:?}"); + } +} + +#[test] +fn the_bar_shows_no_hint_text() { + let h = zoom_bar(); + assert!(h.query_by_label_contains("to zoom out").is_none()); + assert!(h.query_by_label_contains("Click to zoom in").is_none()); +} + +#[test] +fn fill_screen_fills_as_on_the_hand_bar() { + let mut h = zoom_bar(); + h.get_by_label("Fit Screen").click(); + h.run_steps(2); + assert!(h.state().ui.views[0].fit_pending); + h.get_by_label("Fill Screen").click(); + h.run_steps(2); + let v = &h.state().ui.views[0]; + assert!(v.fill_pending && !v.fit_pending); + h.get_by_label("100%").click(); + h.run_steps(2); + let v = &h.state().ui.views[0]; + assert!(!v.fill_pending && !v.fit_pending && v.zoom == 1.0); +}