fix(ui): fit stage on Hand tool double-click (M8)

This commit is contained in:
Call4han committed 2026-11-18 16:40:22 -05:00
1 parent 4a75c49e3b
commit 9b277ef84e
3 files changed
+66

No files matched your search

+3
View File
@@ -2,6 +2,9 @@
## Unreleased
* **Double-click the Hand tool to fit the stage in the window** (#457, M8). A single click
still selects the Hand tool without changing the view.
* **Themes of your own** (#340, ADR 0117, M8): a theme is a small JSON file that names colours
for the interface's roles, kept in `themes` in the settings folder (`data/themes` in a
portable copy).
+1
View File
@@ -208,6 +208,7 @@ lets you change them (see [Preferences, shortcuts and accessibility](preferences
| Zoom in | **View › Zoom In** (**Ctrl+=**), or click with the **Zoom** tool (**Z**) |
| Zoom out | **View › Zoom Out** (**Ctrl+-**), or **Alt**-click with the Zoom tool |
| Fit the whole stage in the window | **View › Fit in Window** (**Ctrl+0**, or **Ctrl+2**) |
| Fit the stage with the mouse | Double-click the **Hand** tool |
| See the stage at actual size | **View › 100%** (**Ctrl+1**) |
| Jump to a set zoom | the arrow beside the zoom field at the right of the edit bar: Fit in window, 25 % to 800 % |
| Type a zoom | click the zoom field, type a percentage (5 to 6400) and press **Enter** |
+62
View File
@@ -102,6 +102,10 @@ pub fn tools(app: &mut App, ui: &mut egui::Ui, flow: ToolFlow) {
fn tool_items(app: &mut App, ui: &mut egui::Ui, area: Rect, flow: ToolFlow) {
for tool in Tool::ALL {
let (rect, resp) = ui.allocate_exact_size(vec2(TOOL_BUTTON, TOOL_BUTTON), Sense::click());
#[cfg(test)]
if tool == Tool::Hand {
ui.ctx().data_mut(|data| data.insert_temp(egui::Id::new("test_hand_tool_rect"), rect));
}
let active = app.tool == tool;
// The active tool sits on a lighter gray block with a white icon; the rest are a
// step dimmer, so the one in hand stands out without colour.
@@ -130,6 +134,10 @@ fn tool_items(app: &mut App, ui: &mut egui::Ui, area: Rect, flow: ToolFlow) {
if resp.clicked() {
app.tool = tool;
}
// #457: the Hand tool's double-click uses the same fit as View > Fit in Window.
if tool == Tool::Hand && resp.double_clicked() {
app.view.fit = true;
}
// Animate: double-clicking the Eraser erases everything on the stage (it asks first).
if tool == Tool::Eraser && resp.double_clicked() {
crate::erasertool::erase_everything(app);
@@ -3466,6 +3474,60 @@ pub(crate) fn library(app: &mut App, ui: &mut egui::Ui) {
mod tests {
use super::*;
#[test]
fn double_clicking_the_hand_tool_fits_the_stage_but_a_single_click_only_selects_it() {
for flow in [ToolFlow::Column, ToolFlow::Row, ToolFlow::Grid] {
for zoom in [0.1, 8.0] {
let ctx = egui::Context::default();
let mut app = App::with_context(&ctx, anicraft_engine::Session::default(), Some(std::path::PathBuf::from("unused.png")));
app.view.fit = false;
app.view.fitted = None;
app.view.zoom = zoom;
app.view.pan = vec2(120.0, -80.0);
let state = app.s.state;
let mut time = 0.0;
let mut draw = |app: &mut App, events| {
time += 0.05;
let input = egui::RawInput {
screen_rect: Some(Rect::from_min_size(egui::Pos2::ZERO, vec2(1600.0, 1400.0))),
time: Some(time),
events,
..Default::default()
};
ctx.run_ui(input, |ui| tools(app, ui, flow)).textures_delta.clear();
};
draw(&mut app, Vec::new());
let rect = ctx.data(|data| data.get_temp::<Rect>(egui::Id::new("test_hand_tool_rect"))).expect("Hand tool drawn");
let at = rect.center();
let event = |pressed| vec![
egui::Event::PointerMoved(at),
egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE },
];
draw(&mut app, event(true));
draw(&mut app, event(false));
assert_eq!(app.tool, Tool::Hand);
assert!(!app.view.fit, "a single click must not fit the view");
assert_eq!(app.view.zoom, zoom);
assert_eq!(app.view.pan, vec2(120.0, -80.0));
draw(&mut app, event(true));
draw(&mut app, event(false));
assert!(app.view.fit, "double-click must request Fit in Window ({flow:?})");
for _ in 0..3 {
let input = egui::RawInput {
screen_rect: Some(Rect::from_min_size(egui::Pos2::ZERO, vec2(1600.0, 1400.0))),
..Default::default()
};
ctx.run_ui(input, |ui| app.frame(ui)).textures_delta.clear();
}
assert_eq!(app.view.pan, egui::Vec2::ZERO);
let canvas = app.stage_cache.canvas;
let size = vec2(app.s.doc.stage.width as f32, app.s.doc.stage.height as f32);
assert!(size.x * app.view.zoom <= canvas.width() && size.y * app.view.zoom <= canvas.height());
assert_eq!(app.s.state, state, "fitting is view state, not a document edit");
}
}
}
/// #252: the Pencil and the Line tool never fill, whatever the fill swatch says, so their
/// Properties show no Fill row; the Pen and the shape tools still fill.
#[test]