Separate selection and move-only tools
This commit is contained in:
parent
274934e079
commit
54832b3715
|
|
@ -25,6 +25,7 @@ use midra_layout::{
|
|||
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||
enum NavigationTool {
|
||||
#[default]
|
||||
Select,
|
||||
Move,
|
||||
Pan,
|
||||
Zoom,
|
||||
|
|
@ -264,7 +265,7 @@ impl Default for Editor {
|
|||
camera_one_to_one: false,
|
||||
pan: Vec2::ZERO,
|
||||
panning: false,
|
||||
navigation_tool: NavigationTool::Move,
|
||||
navigation_tool: NavigationTool::Select,
|
||||
camera_before: None,
|
||||
zoom_drag: None,
|
||||
marquee: None,
|
||||
|
|
@ -786,7 +787,8 @@ impl Editor {
|
|||
}
|
||||
if ctx.input(|i| i.modifiers == egui::Modifiers::NONE) {
|
||||
for (key, tool) in [
|
||||
(egui::Key::V, NavigationTool::Move),
|
||||
(egui::Key::V, NavigationTool::Select),
|
||||
(egui::Key::M, NavigationTool::Move),
|
||||
(egui::Key::H, NavigationTool::Pan),
|
||||
(egui::Key::Z, NavigationTool::Zoom),
|
||||
] {
|
||||
|
|
@ -2043,7 +2045,7 @@ impl Editor {
|
|||
390.0,
|
||||
)
|
||||
};
|
||||
let tools_wrapped = r.width() < options_x + 52.0 + 240.0 + 16.0;
|
||||
let tools_wrapped = r.width() < options_x + 52.0 + 284.0 + 16.0;
|
||||
let tools_x = if tools_wrapped {
|
||||
24.0
|
||||
} else {
|
||||
|
|
@ -2114,9 +2116,10 @@ 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),
|
||||
(3, NavigationTool::Select, "Select", ToolbarIcon::Select),
|
||||
(4, NavigationTool::Move, "Move", ToolbarIcon::Move),
|
||||
(5, NavigationTool::Pan, "Pan", ToolbarIcon::Pan),
|
||||
(6, NavigationTool::Zoom, "Zoom", ToolbarIcon::Zoom),
|
||||
] {
|
||||
let rect = Rect::from_min_size(
|
||||
ink.point(tools_x + 76.0 + (slot - 2) as f32 * 44.0, tools_y),
|
||||
|
|
@ -2400,7 +2403,11 @@ impl Editor {
|
|||
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;
|
||||
let edit_pointer = self.navigation_tool == NavigationTool::Select && !temporary_pan;
|
||||
let move_pointer = self.navigation_tool == NavigationTool::Move && !temporary_pan;
|
||||
if move_pointer && response.hovered() {
|
||||
ui.ctx().set_cursor_icon(egui::CursorIcon::Move);
|
||||
}
|
||||
|
||||
if response.hovered()
|
||||
&& !self.layout.dragging()
|
||||
|
|
@ -2495,6 +2502,20 @@ impl Editor {
|
|||
{
|
||||
self.zoom_drag = Some((p, (p - origin) / scale, self.zoom));
|
||||
}
|
||||
if !self.panning
|
||||
&& move_pointer
|
||||
&& let Some(p) = ui.input(|i| i.pointer.press_origin())
|
||||
{
|
||||
let p = (p - origin) / scale;
|
||||
let point = [p.x as f64, p.y as f64];
|
||||
if self.edit_content {
|
||||
if let Some(i) = self.layout.selected() {
|
||||
self.layout.start_content_drag(i, point);
|
||||
}
|
||||
} else {
|
||||
self.layout.start_selection_drag(point);
|
||||
}
|
||||
}
|
||||
if !self.panning
|
||||
&& edit_pointer
|
||||
&& let Some(p) = ui.input(|i| i.pointer.press_origin())
|
||||
|
|
@ -2577,7 +2598,9 @@ impl Editor {
|
|||
if self.panning {
|
||||
self.pan += response.drag_delta() / scale;
|
||||
origin += response.drag_delta();
|
||||
} else if edit_pointer && let Some(p) = pointer {
|
||||
} else if (edit_pointer || move_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.as_ref().map(|(i, _)| *i) {
|
||||
|
|
@ -2943,7 +2966,7 @@ impl Editor {
|
|||
ink.text(
|
||||
24.0,
|
||||
r.height() - 40.0,
|
||||
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() {
|
||||
if move_pointer { "Move tool · Drag anywhere to move the current selection · V: Select · H: Pan" } else if self.navigation_tool == NavigationTool::Pan { "Pan tool · Drag to move the view · V: Select · 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: Select · 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",
|
||||
|
|
@ -3367,6 +3390,7 @@ fn apply_button(ui: &mut egui::Ui, label: &str, pending: bool) -> egui::Response
|
|||
|
||||
#[derive(Clone, Copy)]
|
||||
enum ToolbarIcon {
|
||||
Select,
|
||||
Move,
|
||||
Pan,
|
||||
Zoom,
|
||||
|
|
@ -3563,7 +3587,7 @@ fn toolbar_icon(ui: &mut egui::Ui, rect: Rect, label: &str, icon: ToolbarIcon) -
|
|||
let palette = theme::palette(ui.ctx());
|
||||
let id = if matches!(
|
||||
icon,
|
||||
ToolbarIcon::Move | ToolbarIcon::Pan | ToolbarIcon::Zoom
|
||||
ToolbarIcon::Select | ToolbarIcon::Move | ToolbarIcon::Pan | ToolbarIcon::Zoom
|
||||
) {
|
||||
egui::Id::new(("navigation-tool", label))
|
||||
} else {
|
||||
|
|
@ -3588,6 +3612,20 @@ 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::Select => {
|
||||
painter.add(egui::Shape::closed_line(
|
||||
vec![
|
||||
point(-7.0, -11.0),
|
||||
point(-7.0, 10.0),
|
||||
point(-1.0, 4.0),
|
||||
point(4.0, 12.0),
|
||||
point(8.0, 9.0),
|
||||
point(3.0, 2.0),
|
||||
point(11.0, 1.0),
|
||||
],
|
||||
stroke,
|
||||
));
|
||||
}
|
||||
ToolbarIcon::Move => {
|
||||
for axis in [Vec2::X, Vec2::Y] {
|
||||
painter.line_segment([c - axis * 11.0, c + axis * 11.0], stroke);
|
||||
|
|
@ -3707,7 +3745,8 @@ 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::Select => "Select (V) — select, move and resize layers; drag empty space to select. Grid and Pivot toggles still apply.",
|
||||
ToolbarIcon::Move => "Move (M) — drag anywhere to move the current selection without selecting, deselecting or resizing. In crop mode, moves content only.",
|
||||
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",
|
||||
|
|
@ -4010,6 +4049,54 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn move_tool_preserves_selection_and_never_resizes() {
|
||||
for target in 0..3 {
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = Editor {
|
||||
navigation_tool: NavigationTool::Move,
|
||||
pivot_tool: true,
|
||||
..Default::default()
|
||||
};
|
||||
let before = app.layout.layers().clone();
|
||||
let selection = app.layout.selection_mask();
|
||||
let output = frame(&mut app, &ctx, vec![]);
|
||||
let rects = layer_rects(&output);
|
||||
let start = match target {
|
||||
0 => rects[0].center(), // unselected layer
|
||||
1 => rects[1].right_bottom(), // former resize handle
|
||||
_ => {
|
||||
ctx.read_response(egui::Id::new("canvas"))
|
||||
.unwrap()
|
||||
.rect
|
||||
.left_top()
|
||||
+ Vec2::splat(20.0)
|
||||
}
|
||||
};
|
||||
frame(
|
||||
&mut app,
|
||||
&ctx,
|
||||
vec![egui::Event::PointerMoved(start), mouse(start, true)],
|
||||
);
|
||||
frame(&mut app, &ctx, vec![mouse(start, false)]);
|
||||
assert_eq!(app.layout.selection_mask(), selection);
|
||||
let end = start + Vec2::new(25.0, 15.0);
|
||||
frame(&mut app, &ctx, vec![mouse(start, true)]);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(end)]);
|
||||
frame(&mut app, &ctx, vec![mouse(end, false)]);
|
||||
assert_eq!(app.layout.selection_mask(), selection);
|
||||
assert_eq!(app.layout.layers()[0], before[0]);
|
||||
let after = app.layout.layers()[1];
|
||||
assert_ne!(after.x, before[1].x);
|
||||
assert_eq!(
|
||||
[after.width, after.height],
|
||||
[before[1].width, before[1].height]
|
||||
);
|
||||
app.layout.undo();
|
||||
assert_eq!(app.layout.layers(), &before);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn navigation_icons_are_exclusive_and_keep_grid_pivot_choices() {
|
||||
let ctx = egui::Context::default();
|
||||
|
|
@ -4022,6 +4109,7 @@ mod tests {
|
|||
for (label, tool) in [
|
||||
("Pan", NavigationTool::Pan),
|
||||
("Zoom", NavigationTool::Zoom),
|
||||
("Select", NavigationTool::Select),
|
||||
("Move", NavigationTool::Move),
|
||||
] {
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
|
|
@ -4044,14 +4132,14 @@ mod tests {
|
|||
for (keycode, tool) in [
|
||||
(egui::Key::H, NavigationTool::Pan),
|
||||
(egui::Key::Z, NavigationTool::Zoom),
|
||||
(egui::Key::V, NavigationTool::Move),
|
||||
(egui::Key::V, NavigationTool::Select),
|
||||
] {
|
||||
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);
|
||||
assert_eq!(app.navigation_tool, NavigationTool::Select);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -4099,7 +4187,7 @@ mod tests {
|
|||
fn pan_tool_and_temporary_pan_only_change_the_view() {
|
||||
for tool in [
|
||||
NavigationTool::Pan,
|
||||
NavigationTool::Move,
|
||||
NavigationTool::Select,
|
||||
NavigationTool::Zoom,
|
||||
] {
|
||||
let ctx = egui::Context::default();
|
||||
|
|
@ -4227,6 +4315,7 @@ mod tests {
|
|||
let mut previous: Option<Rect> = None;
|
||||
for (kind, label) in [
|
||||
("edit-tool", "Pivot"),
|
||||
("navigation-tool", "Select"),
|
||||
("navigation-tool", "Move"),
|
||||
("navigation-tool", "Pan"),
|
||||
("navigation-tool", "Zoom"),
|
||||
|
|
|
|||
|
|
@ -1348,6 +1348,13 @@ impl Layout {
|
|||
self.select(None);
|
||||
}
|
||||
}
|
||||
/// Move the existing selection from any pointer position without changing selection.
|
||||
pub fn start_selection_drag(&mut self, point: [f64; 2]) {
|
||||
self.finish_drag();
|
||||
if point.iter().all(|v| v.is_finite()) && !self.selected_indices().is_empty() {
|
||||
self.drag = Some((self.selected.clone(), self.snapshot(), point));
|
||||
}
|
||||
}
|
||||
/// Resize one selected layer, keeping its opposite corner fixed.
|
||||
pub fn start_resize(
|
||||
&mut self,
|
||||
|
|
|
|||
|
|
@ -113,8 +113,8 @@ The session-only toolbar grid tools select 10 or 100 screen pixels (mutually exc
|
|||
|
||||
The session-only Pivot tool can combine with either grid. Ctrl without Shift temporarily inverts Pivot; Ctrl+Shift does not affect it. Tool selections are not persisted in application settings or projects; they survive project loads and selection changes within a session and start off on launch. Pivot positions belong to each layer and are saved in project v9, not application settings.
|
||||
|
||||
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
|
||||
Select/Move/Pan/Zoom navigation tool choice is also session-only and survives project loads.
|
||||
It starts at Select on launch; V/M/H/Z switch tools only outside text entry. Camera
|
||||
zoom/pan remain part of the project, not application settings.
|
||||
|
||||
Pivot placement also has nine built-in local anchors (corners, side midpoints,
|
||||
|
|
|
|||
|
|
@ -320,15 +320,17 @@ manual ratios and presets resize immediately when locked, as do width/height edi
|
|||
The Layer tab needs no Apply; pending Source edits still require their own Apply. 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
|
||||
### Select, 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
|
||||
The toolbar's **Select**, **Move**, **Pan** and **Zoom** icons are mutually exclusive and
|
||||
remain selected until another is chosen. **V**, **M**, **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
|
||||
- **Select (V):** select, move, resize and marquee-select layers using the existing
|
||||
controls; crop editing remains available.
|
||||
- **Move (M):** drag anywhere to move the current selection without changing it
|
||||
or resizing. In crop mode, moves the selected layer’s content.
|
||||
- **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
|
||||
|
|
@ -337,7 +339,7 @@ retained independently.
|
|||
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
|
||||
session; a new launch starts with Select. Pan/Zoom do not alter geometry, crop values
|
||||
or document history. Existing project saves still preserve zoom/pan values.
|
||||
|
||||
### Persistent editing tools
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Separate Select (V, previous behavior) from Move (M), which drags the existing selection without selecting, deselecting or resizing.
|
||||
|
||||
- Layer properties’ Layer tab applies size/locked-ratio changes immediately; remove its Apply button. Drag edits undo together; Source edits remain explicit.
|
||||
|
||||
- Layer properties’ Crop tab automatically enables visual crop editing and disables it on leaving/closing; remove its redundant toggle button.
|
||||
|
|
|
|||
Loading…
Reference in New Issue