mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
* Zoom tool: double-click zooms to 100% (#2508) Double-clicking the Zoom tool in the toolbar now selects it and runs view.actualPixels, as in Photoshop, next to the existing Hand tool double-click (fit on screen). With no document open it only picks the tool. Co-Authored-By: Claude Opus 5.5 <[email protected]> * contributors: add vangel76 (sync GitHub name) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
0c3c6cdd8d
commit
28edd59339
2 files changed
+51
-3
No files matched your search
@@ -74,3 +74,6 @@ sync_github_name = true
|
||||
real_name = "Ahmed Moussa"
|
||||
display_name = "Ahmed Moussa"
|
||||
sync_github_name = false
|
||||
|
||||
[people.vangel76]
|
||||
sync_github_name = true
|
||||
@@ -149,6 +149,12 @@ pub fn toolbar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
// With no document open there is nothing to fit.
|
||||
let _ = app.run("view.fitOnScreen", json!({}));
|
||||
}
|
||||
// Double-clicking the Zoom tool zooms to 100% (Photoshop).
|
||||
if resp.double_clicked() && tool == Tool::Zoom {
|
||||
app.ui.tool = tool;
|
||||
// With no document open there is nothing to zoom.
|
||||
let _ = app.run("view.actualPixels", json!({}));
|
||||
}
|
||||
// Right-click or long-press opens the flyout (Photoshop).
|
||||
let held_for =
|
||||
resp.is_pointer_button_down_on().then(|| ui.input(|i| i.pointer.press_start_time().map(|t0| i.time - t0))).flatten();
|
||||
@@ -3898,16 +3904,20 @@ mod toolbar_tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// The Hand tool's toolbar button: tool buttons have no label, so find it by slot order.
|
||||
fn hand_button(h: &egui_kittest::Harness<'_, PhotocraftApp>) -> egui::Pos2 {
|
||||
/// A tool's toolbar button: tool buttons have no label, so find it by slot order.
|
||||
fn tool_button(h: &egui_kittest::Harness<'_, PhotocraftApp>, tool: Tool) -> egui::Pos2 {
|
||||
let size = egui::Vec2::splat(if Tokens::get(&h.ctx).pro { 30.0 } else { 36.0 });
|
||||
let buttons: Vec<Rect> = h.ctx.viewport(|v| {
|
||||
v.prev_pass.widgets.layers().flat_map(|(_, w)| w.iter()).filter(|w| w.rect.size() == size && w.sense.senses_click()).map(|w| w.rect).collect()
|
||||
});
|
||||
let index = TOOL_SECTIONS.iter().flat_map(|section| section.iter()).position(|slot| slot.contains(&Tool::Hand)).unwrap();
|
||||
let index = TOOL_SECTIONS.iter().flat_map(|section| section.iter()).position(|slot| slot.contains(&tool)).unwrap();
|
||||
buttons[index].center()
|
||||
}
|
||||
|
||||
fn hand_button(h: &egui_kittest::Harness<'_, PhotocraftApp>) -> egui::Pos2 {
|
||||
tool_button(h, Tool::Hand)
|
||||
}
|
||||
|
||||
fn toolbar_harness(app: PhotocraftApp) -> egui_kittest::Harness<'static, PhotocraftApp> {
|
||||
// 60 fps steps, so two clicks a few frames apart are a double-click.
|
||||
let mut h = egui_kittest::Harness::builder().with_size(vec2(800.0, 1400.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|
||||
@@ -3956,6 +3966,41 @@ mod toolbar_tests {
|
||||
assert_eq!(h.state().ui.tool, Tool::Hand);
|
||||
assert!(h.state().session.active().is_none());
|
||||
}
|
||||
|
||||
/// Double-clicking the Zoom tool zooms to 100% (Photoshop); a single click only picks the tool.
|
||||
#[test]
|
||||
fn double_clicking_the_zoom_tool_zooms_to_actual_pixels() {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 64, "height": 64})).unwrap();
|
||||
app.ui.tool = Tool::Move;
|
||||
app.ui.views[0].fit_pending = true;
|
||||
app.ui.views[0].zoom = 0.25;
|
||||
let mut h = toolbar_harness(app);
|
||||
let p = tool_button(&h, Tool::Zoom);
|
||||
click(&mut h, p);
|
||||
assert_eq!(h.state().ui.tool, Tool::Zoom);
|
||||
assert_eq!(h.state().ui.views[0].zoom, 0.25, "a single click doesn't zoom");
|
||||
// Past the double-click window, so the next two clicks are a fresh double-click.
|
||||
h.run_steps(40);
|
||||
click(&mut h, p);
|
||||
click(&mut h, p);
|
||||
assert_eq!(h.state().ui.tool, Tool::Zoom);
|
||||
assert_eq!(h.state().ui.views[0].zoom, 1.0, "a double-click zooms to 100%");
|
||||
assert!(!h.state().ui.views[0].fit_pending, "100% replaces a pending fit");
|
||||
}
|
||||
|
||||
/// With no document open the double-click still picks the tool and doesn't panic.
|
||||
#[test]
|
||||
fn double_clicking_the_zoom_tool_without_a_document_is_harmless() {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.ui.tool = Tool::Move;
|
||||
let mut h = toolbar_harness(app);
|
||||
let p = tool_button(&h, Tool::Zoom);
|
||||
click(&mut h, p);
|
||||
click(&mut h, p);
|
||||
assert_eq!(h.state().ui.tool, Tool::Zoom);
|
||||
assert!(h.state().session.active().is_none());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in new issue
Block a user