mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Show Move rollover with Auto-Select off and transform controls on
This commit is contained in:
1 parent
59153889bd
commit
f5f399c0d6
2 files changed
+73
-9
No files matched your search
@@ -0,0 +1,59 @@
|
||||
use egui::{Event, Modifiers, PointerButton};
|
||||
use photocraft_doc::LayerId;
|
||||
use photocraft_geom::Rect;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::guide_cursor_tests::{harness, hover, screen};
|
||||
use crate::state::Tool;
|
||||
|
||||
fn paint(app: &mut PhotocraftApp, bounds: Rect) -> LayerId {
|
||||
let layer = LayerId(app.run("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap());
|
||||
app.session
|
||||
.edit("Paint fixture", |doc, _| {
|
||||
doc.layer_mut(layer).unwrap().surface_mut().unwrap().fill_rect(bounds, &[1.0, 0.0, 0.0, 1.0]);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
layer
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hover_with_transform_controls_and_auto_select_off_does_not_select_on_click() {
|
||||
let mut h = harness(Tool::Move);
|
||||
let app = h.state_mut();
|
||||
let bounds = Rect::new(90, 110, 130, 145);
|
||||
let painted = paint(app, bounds);
|
||||
paint(app, Rect::new(290, 90, 335, 140));
|
||||
app.ui.tool_options.move_auto_select = false;
|
||||
app.ui.tool_options.move_show_transform = true;
|
||||
h.run_steps(2);
|
||||
|
||||
hover(&mut h, 110.0, 125.0, Modifiers::NONE);
|
||||
assert_eq!(h.state().canvas_hover_layer, Some(painted));
|
||||
assert_eq!(super::target(h.state_mut(), Some([110.0, 125.0]), false, false), Some(bounds));
|
||||
let st = h.state().session.active().unwrap();
|
||||
let (before, active, history) = (st.doc.clone(), st.active_layer, st.history.past_len());
|
||||
assert_ne!(active, Some(painted));
|
||||
let pos = screen(&h, 110.0, 125.0);
|
||||
for pressed in [true, false] {
|
||||
h.event(Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE });
|
||||
h.run_steps(2);
|
||||
}
|
||||
let st = h.state().session.active().unwrap();
|
||||
assert_eq!(st.doc, before);
|
||||
assert_eq!(st.active_layer, active);
|
||||
assert_eq!(st.history.past_len(), history);
|
||||
|
||||
h.state_mut().ui.tool_options.move_show_transform = false;
|
||||
hover(&mut h, 110.0, 125.0, Modifiers::NONE);
|
||||
assert_eq!(h.state().canvas_hover_layer, None);
|
||||
hover(&mut h, 110.0, 125.0, Modifiers::COMMAND);
|
||||
assert_eq!(h.state().canvas_hover_layer, Some(painted));
|
||||
|
||||
h.state_mut().ui.tool_options.move_auto_select = true;
|
||||
hover(&mut h, 110.0, 125.0, Modifiers::NONE);
|
||||
assert_eq!(h.state().canvas_hover_layer, Some(painted));
|
||||
hover(&mut h, 110.0, 125.0, Modifiers::COMMAND);
|
||||
assert_eq!(h.state().canvas_hover_layer, None);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Move tool › Show Highlight on Rollover (Preferences › Tools, on by default): with Auto-Select
|
||||
//! on, or ⌘ held while it is off, hovering the canvas outlines the layer (or group, per the
|
||||
//! Auto-Select target) that a click there would pick. The hit test is the click's own
|
||||
//! Move tool › Show Highlight on Rollover (Preferences › Tools, on by default): hovering the canvas
|
||||
//! outlines the layer or group the Auto-Select hit test finds. Show Transform Controls also allows
|
||||
//! the outline while Auto-Select is off and no modifier is held. The hit test is the click's own
|
||||
//! (`pick_cmds::move_auto_select_target`), so a type layer is outlined anywhere inside its text, as it
|
||||
//! is picked there (#2591). The answer is cached per document revision and pointer pixel: a
|
||||
//! pointer resting on the canvas costs nothing per frame.
|
||||
@@ -14,7 +14,7 @@ use photocraft_geom::Rect;
|
||||
use crate::PhotocraftApp;
|
||||
use crate::state::Tool;
|
||||
|
||||
/// The last answer: what a click at `at` on that revision of the document would outline.
|
||||
/// The cached rollover target at `at` on this document revision.
|
||||
pub(crate) struct Hover {
|
||||
doc: DocId,
|
||||
revision: u64,
|
||||
@@ -25,16 +25,17 @@ pub(crate) struct Hover {
|
||||
}
|
||||
|
||||
/// The document-space bounds to outline with the pointer at `at` (document px), or `None` when
|
||||
/// nothing is highlighted: the preference is off, another tool is current, a click wouldn't
|
||||
/// Auto-Select (it's off without ⌘, or the selected pixels move instead), a button is down (which
|
||||
/// covers every drag), or a transform is under way.
|
||||
/// nothing is highlighted: the preference is off, another tool is current, the hover mode is
|
||||
/// inactive, the selected pixels move instead, a button is down, or a transform is under way.
|
||||
pub(crate) fn target(app: &mut PhotocraftApp, at: Option<[f64; 2]>, command: bool, pressed: bool) -> Option<Rect> {
|
||||
let options = &app.ui.tool_options;
|
||||
let hover_enabled = if options.move_auto_select { !command } else { command || options.move_show_transform };
|
||||
if !app.session.prefs().tools.show_highlight_on_rollover
|
||||
|| app.ui.tool != Tool::Move
|
||||
|| !app.ui.tool_options.move_show_hover_bounds
|
||||
|| !options.move_show_hover_bounds
|
||||
|| pressed
|
||||
|| app.ui.transform.is_some()
|
||||
|| app.ui.tool_options.move_auto_select == command
|
||||
|| !hover_enabled
|
||||
|| crate::move_ui::moves_selected_pixels_with(app, Tool::Move)
|
||||
{
|
||||
app.canvas_hover_layer = None;
|
||||
@@ -122,6 +123,10 @@ pub(crate) fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui, canvas: egui::Rec
|
||||
HoverOutline::new(tl!("Layer rollover"), shape).show_at(ui, canvas);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../move_hover_auto_select_off_tests.rs"]
|
||||
mod move_hover_auto_select_off_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json::json;
|
||||
|
||||
Reference in new issue
Block a user