Add persistent Move Pan and Zoom viewport tools
This commit is contained in:
parent
e38e40530d
commit
35f6ac6165
|
|
@ -21,6 +21,14 @@ use midra_layout::{
|
|||
AlignTarget, Alignment, Corner, Geometry, Layout, PositionPoint, ResizeHandle, ResizeMode,
|
||||
};
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||
enum NavigationTool {
|
||||
#[default]
|
||||
Move,
|
||||
Pan,
|
||||
Zoom,
|
||||
}
|
||||
|
||||
pub struct Editor {
|
||||
device: device_ui::DeviceUi,
|
||||
layer_ui: layers_ui::LayerUi,
|
||||
|
|
@ -43,6 +51,9 @@ pub struct Editor {
|
|||
camera_one_to_one: bool,
|
||||
pan: Vec2,
|
||||
panning: bool,
|
||||
navigation_tool: NavigationTool,
|
||||
camera_before: Option<(f32, Vec2)>,
|
||||
zoom_drag: Option<(Pos2, Vec2, f32)>,
|
||||
marquee: Option<Marquee>,
|
||||
align_target: AlignTarget,
|
||||
layer_order: Vec<usize>,
|
||||
|
|
@ -250,6 +261,9 @@ impl Default for Editor {
|
|||
camera_one_to_one: false,
|
||||
pan: Vec2::ZERO,
|
||||
panning: false,
|
||||
navigation_tool: NavigationTool::Move,
|
||||
camera_before: None,
|
||||
zoom_drag: None,
|
||||
marquee: None,
|
||||
align_target: AlignTarget::Selection,
|
||||
layer_order: Vec::new(),
|
||||
|
|
@ -700,6 +714,12 @@ impl Editor {
|
|||
if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
|
||||
self.edit_content = false;
|
||||
self.layout.cancel_drag();
|
||||
if let Some((zoom, pan)) = self.camera_before.take() {
|
||||
self.zoom = zoom;
|
||||
self.pan = pan;
|
||||
}
|
||||
self.zoom_drag = None;
|
||||
self.panning = false;
|
||||
if let Some((_, before)) = self.pivot_drag.take() {
|
||||
self.pivot_relative = before;
|
||||
}
|
||||
|
|
@ -733,7 +753,11 @@ impl Editor {
|
|||
self.open_paste(text);
|
||||
return;
|
||||
}
|
||||
if self.layout.dragging() || self.marquee.is_some() || self.panning {
|
||||
if self.layout.dragging()
|
||||
|| self.marquee.is_some()
|
||||
|| self.panning
|
||||
|| self.zoom_drag.is_some()
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ctx.input(|i| i.events.iter().any(|e| matches!(e, egui::Event::Copy))) {
|
||||
|
|
@ -755,6 +779,18 @@ impl Editor {
|
|||
}
|
||||
return;
|
||||
}
|
||||
if ctx.input(|i| i.modifiers == egui::Modifiers::NONE) {
|
||||
for (key, tool) in [
|
||||
(egui::Key::V, NavigationTool::Move),
|
||||
(egui::Key::H, NavigationTool::Pan),
|
||||
(egui::Key::Z, NavigationTool::Zoom),
|
||||
] {
|
||||
if ctx.input(|i| i.key_pressed(key)) {
|
||||
self.navigation_tool = tool;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
let step = if ctx.input(|i| i.modifiers.shift) {
|
||||
10.0
|
||||
} else {
|
||||
|
|
@ -1843,6 +1879,23 @@ impl Editor {
|
|||
self.resize_mode
|
||||
}
|
||||
}
|
||||
fn set_view_zoom(
|
||||
&mut self,
|
||||
zoom: f32,
|
||||
world: Vec2,
|
||||
pointer: Pos2,
|
||||
area: Rect,
|
||||
base: f32,
|
||||
) -> (Pos2, f32) {
|
||||
self.zoom = zoom.clamp(0.0001, 256.0);
|
||||
let scale = base * self.zoom;
|
||||
let center = Vec2::new(
|
||||
self.layout.formats().output[0] as f32,
|
||||
self.layout.formats().output[1] as f32,
|
||||
) / 2.0;
|
||||
self.pan = (pointer - area.center()) / scale + center - world;
|
||||
(area.center() - center * scale + self.pan * scale, scale)
|
||||
}
|
||||
fn workspace(&mut self, ui: &mut egui::Ui) {
|
||||
let palette = theme::palette(ui.ctx());
|
||||
let r = ui.max_rect();
|
||||
|
|
@ -1887,7 +1940,7 @@ impl Editor {
|
|||
390.0,
|
||||
)
|
||||
};
|
||||
let tools_wrapped = r.width() < options_x + 52.0 + 132.0 + 16.0;
|
||||
let tools_wrapped = r.width() < options_x + 52.0 + 264.0 + 16.0;
|
||||
let tools_x = if tools_wrapped {
|
||||
24.0
|
||||
} else {
|
||||
|
|
@ -1950,6 +2003,37 @@ impl Editor {
|
|||
);
|
||||
}
|
||||
}
|
||||
for (slot, tool, name, icon) in [
|
||||
(3, NavigationTool::Move, "Move", ToolbarIcon::Move),
|
||||
(4, NavigationTool::Pan, "Pan", ToolbarIcon::Pan),
|
||||
(5, NavigationTool::Zoom, "Zoom", ToolbarIcon::Zoom),
|
||||
] {
|
||||
let rect = Rect::from_min_size(
|
||||
ink.point(tools_x + slot as f32 * 44.0, tools_y),
|
||||
Vec2::splat(32.0),
|
||||
);
|
||||
if self.navigation_tool == tool {
|
||||
ui.painter().rect(
|
||||
rect,
|
||||
4.0,
|
||||
palette.purple,
|
||||
Stroke::new(1.0_f32, palette.cyan),
|
||||
StrokeKind::Inside,
|
||||
);
|
||||
}
|
||||
if toolbar_icon(ui, rect, name, icon).clicked() {
|
||||
self.navigation_tool = tool;
|
||||
}
|
||||
if names {
|
||||
ui.painter().text(
|
||||
rect.center_bottom() + Vec2::new(0.0, 7.0),
|
||||
Align2::CENTER_TOP,
|
||||
name,
|
||||
FontId::proportional(11.0),
|
||||
palette.muted,
|
||||
);
|
||||
}
|
||||
}
|
||||
ink.card(
|
||||
strip_x,
|
||||
20.0,
|
||||
|
|
@ -2190,25 +2274,35 @@ impl Editor {
|
|||
let mut origin = area.center() - Vec2::new(sw / 2.0, sh / 2.0) * scale + self.pan * scale;
|
||||
let response = ui.interact(area, egui::Id::new("canvas"), egui::Sense::click_and_drag());
|
||||
let pointer = ui.input(|i| i.pointer.interact_pos());
|
||||
if response.hovered() && !self.layout.dragging() && !self.panning && self.marquee.is_none()
|
||||
let temporary_pan = ui.input(|i| {
|
||||
i.key_down(egui::Key::Space) || i.pointer.button_down(egui::PointerButton::Middle)
|
||||
});
|
||||
let edit_pointer = self.navigation_tool == NavigationTool::Move && !temporary_pan;
|
||||
|
||||
if response.hovered()
|
||||
&& !self.layout.dragging()
|
||||
&& !self.panning
|
||||
&& self.marquee.is_none()
|
||||
&& self.zoom_drag.is_none()
|
||||
&& self.pivot_drag.is_none()
|
||||
{
|
||||
let scroll = ui.input(|i| i.smooth_scroll_delta.y);
|
||||
if scroll != 0.0
|
||||
&& let Some(p) = pointer
|
||||
{
|
||||
let world = (p - origin) / scale;
|
||||
self.zoom = (self.zoom * (scroll * 0.002).exp()).clamp(0.0001, 256.0);
|
||||
scale = base * self.zoom;
|
||||
self.pan = (p - area.center()) / scale + Vec2::new(sw / 2.0, sh / 2.0) - world;
|
||||
origin = area.center() - Vec2::new(sw / 2.0, sh / 2.0) * scale + self.pan * scale;
|
||||
(origin, scale) =
|
||||
self.set_view_zoom(self.zoom * (scroll * 0.002).exp(), world, p, area, base);
|
||||
}
|
||||
}
|
||||
if response.hovered()
|
||||
if edit_pointer
|
||||
&& response.hovered()
|
||||
&& pointer.is_some_and(|p| self.content_hit(p, origin, scale).is_some())
|
||||
{
|
||||
ui.ctx().set_cursor_icon(egui::CursorIcon::Grab);
|
||||
}
|
||||
if self.edit_content
|
||||
if edit_pointer
|
||||
&& self.edit_content
|
||||
&& response.hovered()
|
||||
&& let Some(corner) = pointer.and_then(|p| self.crop_handle(p, origin, scale))
|
||||
{
|
||||
|
|
@ -2221,7 +2315,8 @@ impl Editor {
|
|||
ResizeHandle::Top | ResizeHandle::Bottom => egui::CursorIcon::ResizeVertical,
|
||||
});
|
||||
}
|
||||
if !self.edit_content
|
||||
if edit_pointer
|
||||
&& !self.edit_content
|
||||
&& response.hovered()
|
||||
&& let Some(p) = pointer
|
||||
&& let Some((_, corner)) = self.resize_handle(p, origin, scale)
|
||||
|
|
@ -2235,7 +2330,8 @@ impl Editor {
|
|||
ResizeHandle::Top | ResizeHandle::Bottom => egui::CursorIcon::ResizeVertical,
|
||||
});
|
||||
}
|
||||
let pivot_visible = self.effective_pivot(ui.input(|i| i.modifiers)) && !self.edit_content;
|
||||
let pivot_visible =
|
||||
edit_pointer && self.effective_pivot(ui.input(|i| i.modifiers)) && !self.edit_content;
|
||||
let pivot_hover = if pivot_visible {
|
||||
pointer.and_then(|p| self.pivot_hit(p, origin, scale))
|
||||
} else {
|
||||
|
|
@ -2244,6 +2340,21 @@ impl Editor {
|
|||
if response.hovered() && pivot_hover.is_some() {
|
||||
ui.ctx().set_cursor_icon(egui::CursorIcon::Move);
|
||||
}
|
||||
if response.hovered() && !edit_pointer {
|
||||
ui.ctx().set_cursor_icon(
|
||||
if temporary_pan || self.navigation_tool == NavigationTool::Pan {
|
||||
if self.panning {
|
||||
egui::CursorIcon::Grabbing
|
||||
} else {
|
||||
egui::CursorIcon::Grab
|
||||
}
|
||||
} else if ui.input(|i| i.modifiers.alt) {
|
||||
egui::CursorIcon::ZoomOut
|
||||
} else {
|
||||
egui::CursorIcon::ZoomIn
|
||||
},
|
||||
);
|
||||
}
|
||||
if response.drag_started_by(egui::PointerButton::Primary)
|
||||
|| response.drag_started_by(egui::PointerButton::Middle)
|
||||
{
|
||||
|
|
@ -2252,10 +2363,18 @@ impl Editor {
|
|||
m.surrender_focus(id);
|
||||
}
|
||||
});
|
||||
self.panning = ui.input(|i| {
|
||||
i.key_down(egui::Key::Space) || i.pointer.button_down(egui::PointerButton::Middle)
|
||||
});
|
||||
self.panning = temporary_pan || self.navigation_tool == NavigationTool::Pan;
|
||||
if self.panning || self.navigation_tool == NavigationTool::Zoom {
|
||||
self.camera_before = Some((self.zoom, self.pan));
|
||||
}
|
||||
if !self.panning
|
||||
&& self.navigation_tool == NavigationTool::Zoom
|
||||
&& let Some(p) = ui.input(|i| i.pointer.press_origin())
|
||||
{
|
||||
self.zoom_drag = Some((p, (p - origin) / scale, self.zoom));
|
||||
}
|
||||
if !self.panning
|
||||
&& edit_pointer
|
||||
&& let Some(p) = ui.input(|i| i.pointer.press_origin())
|
||||
{
|
||||
let pivot = if pivot_visible {
|
||||
|
|
@ -2312,11 +2431,32 @@ impl Editor {
|
|||
}
|
||||
self.snap_guides = [None; 2];
|
||||
let modifiers = ui.input(|i| i.modifiers);
|
||||
if (response.dragged() || response.drag_stopped())
|
||||
&& let Some((start, world, zoom)) = self.zoom_drag
|
||||
&& let Some(p) = pointer
|
||||
{
|
||||
(origin, scale) = self.set_view_zoom(
|
||||
zoom * ((p.x - start.x) * 0.01).exp(),
|
||||
world,
|
||||
start,
|
||||
area,
|
||||
base,
|
||||
);
|
||||
}
|
||||
if response.clicked()
|
||||
&& self.navigation_tool == NavigationTool::Zoom
|
||||
&& !temporary_pan
|
||||
&& let Some(p) = pointer
|
||||
{
|
||||
let world = (p - origin) / scale;
|
||||
let factor = if modifiers.alt { 1.0 / 1.25 } else { 1.25 };
|
||||
(origin, scale) = self.set_view_zoom(self.zoom * factor, world, p, area, base);
|
||||
}
|
||||
if response.dragged() {
|
||||
if self.panning {
|
||||
self.pan += response.drag_delta() / scale;
|
||||
origin += response.drag_delta();
|
||||
} else if let Some(p) = pointer {
|
||||
} else if edit_pointer && let Some(p) = pointer {
|
||||
let p = (p - origin) / scale;
|
||||
let point = [p.x as f64, p.y as f64];
|
||||
if let Some((i, _)) = self.pivot_drag {
|
||||
|
|
@ -2350,8 +2490,11 @@ impl Editor {
|
|||
self.pivot_drag = None;
|
||||
self.marquee = None;
|
||||
self.panning = false;
|
||||
self.zoom_drag = None;
|
||||
self.camera_before = None;
|
||||
}
|
||||
if response.clicked()
|
||||
&& edit_pointer
|
||||
&& self.edit_content
|
||||
&& pointer.is_some_and(|p| {
|
||||
self.content_hit(p, origin, scale).is_none()
|
||||
|
|
@ -2364,6 +2507,7 @@ impl Editor {
|
|||
self.pivot_relative = [0.5; 2];
|
||||
}
|
||||
if response.clicked()
|
||||
&& edit_pointer
|
||||
&& pivot_hover.is_none()
|
||||
&& !self.edit_content
|
||||
&& let Some(p) = pointer
|
||||
|
|
@ -2396,6 +2540,7 @@ impl Editor {
|
|||
});
|
||||
}
|
||||
if response.secondary_clicked()
|
||||
&& edit_pointer
|
||||
&& let Some(p) = pointer
|
||||
{
|
||||
let point = (p - origin) / scale;
|
||||
|
|
@ -2690,7 +2835,7 @@ impl Editor {
|
|||
ink.text(
|
||||
24.0,
|
||||
r.height() - 40.0,
|
||||
if pivot_visible { "Pivot resize · Drag pivot to position · Double-click to center · Ctrl temporarily toggles pivot" } else if self.edit_content { "Crop mode · Drag crop handles to zoom content · Drag image to reposition · Click outside to finish" } else { match self.active_resize_mode() {
|
||||
if self.navigation_tool == NavigationTool::Pan { "Pan tool · Drag to move the view · V: Move · Z: Zoom · Space/middle-drag pans from any tool" } else if self.navigation_tool == NavigationTool::Zoom { "Zoom tool · Click to zoom in · Alt-click to zoom out · Drag right/left to zoom · V: Move · H: Pan" } else if pivot_visible { "Pivot resize · Drag pivot to position · Double-click to center · Ctrl temporarily toggles pivot" } else if self.edit_content { "Crop mode · Drag crop handles to zoom content · Drag image to reposition · Click outside to finish" } else { match self.active_resize_mode() {
|
||||
ResizeMode::Individual => "Corners resize · Side handles keep opposite edge fixed · Shift-click selects",
|
||||
ResizeMode::Same => "Same handles · Matching handles scale selected layers proportionally · Escape cancels drag",
|
||||
ResizeMode::Mirror => "Mirror horizontally · Left/right mirrored handles · Escape cancels drag",
|
||||
|
|
@ -3098,6 +3243,9 @@ fn apply_button(ui: &mut egui::Ui, label: &str, pending: bool) -> egui::Response
|
|||
|
||||
#[derive(Clone, Copy)]
|
||||
enum ToolbarIcon {
|
||||
Move,
|
||||
Pan,
|
||||
Zoom,
|
||||
Output,
|
||||
Screen,
|
||||
Selection,
|
||||
|
|
@ -3289,7 +3437,15 @@ fn edit_tool_icon(
|
|||
|
||||
fn toolbar_icon(ui: &mut egui::Ui, rect: Rect, label: &str, icon: ToolbarIcon) -> egui::Response {
|
||||
let palette = theme::palette(ui.ctx());
|
||||
let response = ui.interact(rect, ui.id().with(("toolbar", label)), egui::Sense::click());
|
||||
let id = if matches!(
|
||||
icon,
|
||||
ToolbarIcon::Move | ToolbarIcon::Pan | ToolbarIcon::Zoom
|
||||
) {
|
||||
egui::Id::new(("navigation-tool", label))
|
||||
} else {
|
||||
ui.id().with(("toolbar", label))
|
||||
};
|
||||
let response = ui.interact(rect, id, egui::Sense::click());
|
||||
response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, label));
|
||||
let painter = ui.painter();
|
||||
let focused = response.hovered() || response.has_focus();
|
||||
|
|
@ -3308,6 +3464,50 @@ fn toolbar_icon(ui: &mut egui::Ui, rect: Rect, label: &str, icon: ToolbarIcon) -
|
|||
let c = rect.center();
|
||||
let point = |x, y| c + Vec2::new(x, y);
|
||||
match icon {
|
||||
ToolbarIcon::Move => {
|
||||
for axis in [Vec2::X, Vec2::Y] {
|
||||
painter.line_segment([c - axis * 11.0, c + axis * 11.0], stroke);
|
||||
let side = Vec2::new(-axis.y, axis.x);
|
||||
for sign in [-1.0, 1.0] {
|
||||
let tip = c + axis * 11.0 * sign;
|
||||
for direction in [-1.0, 1.0] {
|
||||
painter.line_segment(
|
||||
[tip, tip - axis * 4.0 * sign + side * 4.0 * direction],
|
||||
stroke,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ToolbarIcon::Pan => {
|
||||
painter.add(egui::Shape::line(
|
||||
vec![
|
||||
point(-8.0, 0.0),
|
||||
point(-11.0, -3.0),
|
||||
point(-13.0, -1.0),
|
||||
point(-7.0, 9.0),
|
||||
point(5.0, 9.0),
|
||||
point(9.0, 2.0),
|
||||
point(9.0, -7.0),
|
||||
point(5.0, -7.0),
|
||||
point(5.0, -11.0),
|
||||
point(1.0, -11.0),
|
||||
point(1.0, -12.0),
|
||||
point(-3.0, -12.0),
|
||||
point(-3.0, -9.0),
|
||||
point(-7.0, -9.0),
|
||||
point(-8.0, 0.0),
|
||||
],
|
||||
stroke,
|
||||
));
|
||||
}
|
||||
ToolbarIcon::Zoom => {
|
||||
painter.circle_stroke(c - Vec2::splat(3.0), 7.0, stroke);
|
||||
painter.line_segment([point(2.0, 2.0), point(11.0, 11.0)], stroke);
|
||||
painter.line_segment([point(-7.0, -3.0), point(1.0, -3.0)], stroke);
|
||||
painter.line_segment([point(-3.0, -7.0), point(-3.0, 1.0)], stroke);
|
||||
}
|
||||
|
||||
ToolbarIcon::Output => {
|
||||
painter.rect_stroke(
|
||||
Rect::from_center_size(c, Vec2::new(22.0, 18.0)),
|
||||
|
|
@ -3383,6 +3583,9 @@ fn toolbar_icon(ui: &mut egui::Ui, rect: Rect, label: &str, icon: ToolbarIcon) -
|
|||
}
|
||||
}
|
||||
response.on_hover_text(match icon {
|
||||
ToolbarIcon::Move => "Move (V) — select, move and resize layers; drag empty space to select. Grid and Pivot toggles still apply.",
|
||||
ToolbarIcon::Pan => "Pan (H) — drag to move the view. Hold Space or middle-drag to pan temporarily from any tool.",
|
||||
ToolbarIcon::Zoom => "Zoom (Z) — click to zoom in, Alt-click to zoom out; drag right/left to zoom around the starting point. Scroll zoom works from any tool.",
|
||||
ToolbarIcon::Output => "Output format — screen ratio and resolution",
|
||||
ToolbarIcon::Screen => "Fit screen — show the entire output",
|
||||
ToolbarIcon::Selection => "Zoom to selection — frame the selected layers",
|
||||
|
|
@ -3435,6 +3638,126 @@ mod tests {
|
|||
);
|
||||
frame(app, ctx, vec![mouse(pos, false)]);
|
||||
}
|
||||
#[test]
|
||||
fn navigation_icons_are_exclusive_and_keep_grid_pivot_choices() {
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = Editor {
|
||||
grid_tool: Some(10),
|
||||
pivot_tool: true,
|
||||
..Default::default()
|
||||
};
|
||||
let before = app.layout.layers().clone();
|
||||
for (label, tool) in [
|
||||
("Pan", NavigationTool::Pan),
|
||||
("Zoom", NavigationTool::Zoom),
|
||||
("Move", NavigationTool::Move),
|
||||
] {
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let pos = ctx
|
||||
.read_response(egui::Id::new(("navigation-tool", label)))
|
||||
.unwrap()
|
||||
.rect
|
||||
.center();
|
||||
frame(
|
||||
&mut app,
|
||||
&ctx,
|
||||
vec![egui::Event::PointerMoved(pos), mouse(pos, true)],
|
||||
);
|
||||
frame(&mut app, &ctx, vec![mouse(pos, false)]);
|
||||
assert_eq!(app.navigation_tool, tool);
|
||||
assert_eq!(app.grid_tool, Some(10));
|
||||
assert!(app.pivot_tool);
|
||||
}
|
||||
assert_eq!(app.layout.layers(), &before);
|
||||
for (keycode, tool) in [
|
||||
(egui::Key::H, NavigationTool::Pan),
|
||||
(egui::Key::Z, NavigationTool::Zoom),
|
||||
(egui::Key::V, NavigationTool::Move),
|
||||
] {
|
||||
frame(&mut app, &ctx, vec![key(keycode)]);
|
||||
assert_eq!(app.navigation_tool, tool);
|
||||
}
|
||||
ctx.memory_mut(|m| m.request_focus(egui::Id::new(("geometry", 0_usize))));
|
||||
frame(&mut app, &ctx, vec![key(egui::Key::H)]);
|
||||
assert_eq!(app.navigation_tool, NavigationTool::Move);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zoom_tool_anchors_click_and_drag_without_editing_layers_and_escape_restores_camera() {
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = Editor {
|
||||
navigation_tool: NavigationTool::Zoom,
|
||||
edit_content: true,
|
||||
..Default::default()
|
||||
};
|
||||
let before = app.layout.layers().clone();
|
||||
let formats = app.layout.formats().clone();
|
||||
let selection = app.layout.selection_mask();
|
||||
let output = frame(&mut app, &ctx, vec![]);
|
||||
let start = layer_rects(&output)[1].center();
|
||||
frame(
|
||||
&mut app,
|
||||
&ctx,
|
||||
vec![egui::Event::PointerMoved(start), mouse(start, true)],
|
||||
);
|
||||
let output = frame(&mut app, &ctx, vec![mouse(start, false)]);
|
||||
assert!((app.zoom - 1.25).abs() < 1e-6);
|
||||
assert!(layer_rects(&output)[1].center().distance(start) < 0.001);
|
||||
let alt = egui::Modifiers {
|
||||
alt: true,
|
||||
..Default::default()
|
||||
};
|
||||
frame_modifiers(&mut app, &ctx, alt, vec![mouse(start, true)]);
|
||||
frame_modifiers(&mut app, &ctx, alt, vec![mouse(start, false)]);
|
||||
assert!((app.zoom - 1.0).abs() < 1e-6);
|
||||
let camera = (app.zoom, app.pan);
|
||||
let end = start + Vec2::new(35.0, 0.0);
|
||||
frame(&mut app, &ctx, vec![mouse(start, true)]);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(end)]);
|
||||
assert!(app.zoom > camera.0);
|
||||
frame(&mut app, &ctx, vec![key(egui::Key::Escape)]);
|
||||
frame(&mut app, &ctx, vec![mouse(end, false)]);
|
||||
assert_eq!((app.zoom, app.pan), camera);
|
||||
assert_eq!(app.layout.layers(), &before);
|
||||
assert_eq!(app.layout.formats(), &formats);
|
||||
assert_eq!(app.layout.selection_mask(), selection);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pan_tool_and_temporary_pan_only_change_the_view() {
|
||||
for tool in [
|
||||
NavigationTool::Pan,
|
||||
NavigationTool::Move,
|
||||
NavigationTool::Zoom,
|
||||
] {
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = Editor {
|
||||
navigation_tool: tool,
|
||||
..Default::default()
|
||||
};
|
||||
let before = app.layout.layers().clone();
|
||||
let selection = app.layout.selection_mask();
|
||||
let output = frame(&mut app, &ctx, vec![]);
|
||||
let start = layer_rects(&output)[1].center();
|
||||
let end = start + Vec2::new(30.0, 20.0);
|
||||
if tool != NavigationTool::Pan {
|
||||
frame(&mut app, &ctx, vec![key(egui::Key::Space)]);
|
||||
}
|
||||
frame(
|
||||
&mut app,
|
||||
&ctx,
|
||||
vec![egui::Event::PointerMoved(start), mouse(start, true)],
|
||||
);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(end)]);
|
||||
frame(&mut app, &ctx, vec![mouse(end, false)]);
|
||||
assert!(app.pan.x > 0.0 && app.pan.y > 0.0);
|
||||
assert_eq!(app.zoom, 1.0);
|
||||
assert_eq!(app.navigation_tool, tool);
|
||||
assert_eq!(app.layout.layers(), &before);
|
||||
assert_eq!(app.layout.selection_mask(), selection);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn manual_ratio_keeps_width_and_position_reference_and_is_undoable() {
|
||||
for point in [
|
||||
|
|
@ -3530,9 +3853,16 @@ mod tests {
|
|||
}
|
||||
let canvas = ctx.read_response(egui::Id::new("canvas")).unwrap().rect;
|
||||
let mut previous: Option<Rect> = None;
|
||||
for label in ["10 px", "100 px", "Pivot"] {
|
||||
for (kind, label) in [
|
||||
("edit-tool", "10 px"),
|
||||
("edit-tool", "100 px"),
|
||||
("edit-tool", "Pivot"),
|
||||
("navigation-tool", "Move"),
|
||||
("navigation-tool", "Pan"),
|
||||
("navigation-tool", "Zoom"),
|
||||
] {
|
||||
let rect = ctx
|
||||
.read_response(egui::Id::new(("edit-tool", label)))
|
||||
.read_response(egui::Id::new((kind, label)))
|
||||
.unwrap()
|
||||
.rect;
|
||||
assert!(rect.right() <= canvas.right());
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ impl Editor {
|
|||
ui.label("Double-click pivot: reset to center · Shift/Ctrl+Shift: invert matching grid tool");
|
||||
ui.label("Arrow keys: move 1 pixel · Shift-arrow: move 10 pixels");
|
||||
ui.label("Shift-click: add/remove a layer from selection");
|
||||
ui.label("Tools: V Move · H Pan · Z Zoom (outside text fields)");
|
||||
ui.label("Space-drag or middle button: pan · Scroll: zoom");
|
||||
ui.label("Double-click a layer: adjust crop · Escape: cancel gesture");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ impl Editor {
|
|||
resize_mode: self.resize_mode,
|
||||
grid_tool: self.grid_tool,
|
||||
pivot_tool: self.pivot_tool,
|
||||
navigation_tool: self.navigation_tool,
|
||||
layout,
|
||||
reference,
|
||||
corner: e.position_point,
|
||||
|
|
@ -300,6 +301,7 @@ mod tests {
|
|||
resize_mode: mode,
|
||||
grid_tool: Some(100),
|
||||
pivot_tool: true,
|
||||
navigation_tool: NavigationTool::Pan,
|
||||
..Default::default()
|
||||
};
|
||||
app.install_project(&ctx, Project::from_layout(&Layout::default()))
|
||||
|
|
@ -307,6 +309,7 @@ mod tests {
|
|||
assert_eq!(app.resize_mode, mode);
|
||||
assert_eq!(app.grid_tool, Some(100));
|
||||
assert!(app.pivot_tool);
|
||||
assert_eq!(app.navigation_tool, NavigationTool::Pan);
|
||||
assert_eq!(app.active_resize_mode(), ResizeMode::Individual);
|
||||
app.layout.set_selection([true; 2]);
|
||||
app.sync();
|
||||
|
|
|
|||
|
|
@ -112,3 +112,7 @@ The session-only toolbar grid tools select 10 or 100 screen pixels (mutually exc
|
|||
**Try autoconnecting at startup** is in Settings → Midra integration. It saves immediately but applies on the next launch; toggling it does not initiate a connection. One background attempt uses the regular connection timeout and error handling, with no automatic retry loop. Failures leave the app offline and are reported in Midra connection. Project loading does not trigger an attempt.
|
||||
|
||||
The session-only Pivot tool can combine with either grid. Ctrl without Shift temporarily inverts Pivot; Ctrl+Shift does not affect it. Pivot positions and tool selections are not persisted in application settings or projects. Tool selections survive project loads and selection changes within a session, and start off on launch; pivot positions reset on selection changes/project loads.
|
||||
|
||||
Move/Pan/Zoom navigation tool choice is also session-only and survives project loads.
|
||||
It starts at Move on launch; V/H/Z switch tools only outside text entry. Camera
|
||||
zoom/pan remain part of the project, not application settings.
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ missing fields and non-finite values are rejected before replacing the document.
|
|||
Projects larger than 96 MiB are rejected.
|
||||
|
||||
Save includes **applied values only**. Pending text/format/import drafts, prepared aspect-ratio targets, open
|
||||
dialogs, undo/redo history, crop-edit mode, resize mode, temporary resize pivots, grid/pivot tool selections, and provisional device
|
||||
dialogs, undo/redo history, crop-edit mode, resize mode, temporary resize pivots, grid/pivot/navigation tool selections, and provisional device
|
||||
export calculations are not persisted. The current resize mode stays selected
|
||||
when opening another project in the same session; a fresh launch starts with
|
||||
Individual mode. Names and folder labels are stored. Removing layers does not renumber surviving
|
||||
|
|
|
|||
|
|
@ -300,6 +300,26 @@ manual ratios and presets update the size draft only when locked; **Apply** comm
|
|||
the draft. Unapplied ratio text/targets are temporary UI state, not saved settings
|
||||
or a separate project constraint. Source content remains proportionally scaled.
|
||||
|
||||
### Move, Pan and Zoom tools
|
||||
|
||||
The toolbar's **Move**, **Pan** and **Zoom** icons are mutually exclusive and
|
||||
remain selected until another is chosen. **V**, **H** and **Z** select them when
|
||||
not typing in a field; hover the icons for help. Grid/Pivot toggle choices are
|
||||
retained independently.
|
||||
|
||||
- **Move (V):** select, move, resize and marquee-select layers using the existing
|
||||
controls; crop editing remains available.
|
||||
- **Pan (H):** drag anywhere in the viewport to move the camera without editing
|
||||
layers or changing selection.
|
||||
- **Zoom (Z):** click to zoom in around the pointer, Alt-click to zoom out. Drag
|
||||
right to zoom in or left to zoom out, anchored at the gesture's starting point.
|
||||
- **Space-drag / middle-drag:** temporarily pan from any tool. Scroll zoom works
|
||||
from every tool. Escape restores the camera if a pan/zoom drag is in progress.
|
||||
|
||||
Navigation tool choice survives selection changes and project loads in the current
|
||||
session; a new launch starts with Move. Pan/Zoom do not alter geometry, crop values
|
||||
or document history. Existing project saves still preserve zoom/pan values.
|
||||
|
||||
### Persistent editing tools
|
||||
|
||||
The toolbar has **10 px grid**, **100 px grid**, and **Pivot** icon toggles.
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Add persistent Move/Pan/Zoom icons (V/H/Z). Zoom supports click, Alt-click out and horizontal drag; Space/middle-drag pans from any tool. Escape cancels camera drags; grid/pivot choices stay independent.
|
||||
|
||||
- Layer lists now show the topmost layer first; drag/drop and arrows match. Selection no longer raises layers temporarily. Saved project/SVG stacking stays compatible.
|
||||
|
||||
- Show current aspect ratios beside dimensions and the ratio lock. Accept manual W:H, W/H or decimal ratios; locked edits keep width/reference and adjust height, unlocked edits wait for the lock. Layer properties remain Apply-based.
|
||||
|
|
|
|||
Loading…
Reference in New Issue