mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Move tool: no hover outline on the active layer (#18433)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
df65a96dff
commit
736d5894ef
2 files changed
+73
-9
No files matched your search
@@ -0,0 +1,50 @@
|
||||
use egui::Modifiers;
|
||||
use photocraft_doc::LayerId;
|
||||
use photocraft_geom::Rect;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::guide_cursor_tests::{harness, hover};
|
||||
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
|
||||
}
|
||||
|
||||
/// Red, Blue and Green (top) overlap; at (130, 130) Green is the topmost layer.
|
||||
#[test]
|
||||
fn rollover_skips_the_active_layer_and_outlines_others() {
|
||||
let mut h = harness(Tool::Move);
|
||||
let app = h.state_mut();
|
||||
let red = paint(app, Rect::new(60, 60, 140, 140));
|
||||
let blue = paint(app, Rect::new(90, 90, 170, 170));
|
||||
let green_bounds = Rect::new(120, 120, 200, 200);
|
||||
let green = paint(app, green_bounds);
|
||||
app.ui.tool_options.move_auto_select = true;
|
||||
h.run_steps(2);
|
||||
|
||||
// Green active, Green on top under the pointer: no outline.
|
||||
h.state_mut().run("layer.select", json!({"layer": green.0})).unwrap();
|
||||
hover(&mut h, 130.0, 130.0, Modifiers::NONE);
|
||||
assert_eq!(h.state().canvas_hover_layer, None);
|
||||
assert_eq!(super::target(h.state_mut(), Some([130.0, 130.0]), false, false), None);
|
||||
|
||||
// Blue active, Green on top: Green is outlined as usual, also from the cached hit.
|
||||
h.state_mut().run("layer.select", json!({"layer": blue.0})).unwrap();
|
||||
hover(&mut h, 130.0, 130.0, Modifiers::NONE);
|
||||
assert_eq!(h.state().canvas_hover_layer, Some(green));
|
||||
assert_eq!(super::target(h.state_mut(), Some([130.0, 130.0]), false, false), Some(green_bounds));
|
||||
|
||||
// Blue active and topmost where Green doesn't reach: no outline; Red elsewhere still is.
|
||||
hover(&mut h, 100.0, 100.0, Modifiers::NONE);
|
||||
assert_eq!(h.state().canvas_hover_layer, None);
|
||||
hover(&mut h, 70.0, 70.0, Modifiers::NONE);
|
||||
assert_eq!(h.state().canvas_hover_layer, Some(red));
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
//! 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.
|
||||
//! pointer resting on the canvas costs nothing per frame. The active layer itself is never outlined.
|
||||
|
||||
use craft::behavior::kurbo;
|
||||
use craft::ui::canvas_controls::{HoverOutline, HoverShape};
|
||||
@@ -48,15 +48,23 @@ pub(crate) fn target(app: &mut PhotocraftApp, at: Option<[f64; 2]>, command: boo
|
||||
let at = [at[0].floor() as i32, at[1].floor() as i32];
|
||||
let group = app.ui.tool_options.move_target == "group";
|
||||
let st = app.session.active()?;
|
||||
let (doc, revision) = (st.doc.id, st.revision);
|
||||
if let Some(h) = app.move_hover.as_ref().filter(|h| h.doc == doc && h.revision == revision && h.at == at && h.group == group) {
|
||||
app.canvas_hover_layer = h.target_layer;
|
||||
return h.bounds;
|
||||
let (doc, revision, active) = (st.doc.id, st.revision, st.active_layer);
|
||||
let (target_layer, bounds) = match app.move_hover.as_ref().filter(|h| h.doc == doc && h.revision == revision && h.at == at && h.group == group) {
|
||||
Some(h) => (h.target_layer, h.bounds),
|
||||
None => {
|
||||
let target_layer = photocraft_engine::pick_cmds::move_auto_select_target(&st.doc, at[0], at[1], group);
|
||||
let bounds = target_layer.and_then(|id| outline(&st.doc, id));
|
||||
let target_layer = if bounds.is_some() { target_layer } else { None };
|
||||
app.move_hover = Some(Hover { doc, revision, at, group, target_layer, bounds });
|
||||
(target_layer, bounds)
|
||||
}
|
||||
};
|
||||
// The active layer is never outlined (#18433). Checked after the cache: picking another layer
|
||||
// doesn't change the document revision.
|
||||
if target_layer.is_some() && target_layer == active {
|
||||
app.canvas_hover_layer = None;
|
||||
return None;
|
||||
}
|
||||
let target_layer = photocraft_engine::pick_cmds::move_auto_select_target(&st.doc, at[0], at[1], group);
|
||||
let bounds = target_layer.and_then(|id| outline(&st.doc, id));
|
||||
let target_layer = if bounds.is_some() { target_layer } else { None };
|
||||
app.move_hover = Some(Hover { doc, revision, at, group, target_layer, bounds });
|
||||
app.canvas_hover_layer = target_layer;
|
||||
bounds
|
||||
}
|
||||
@@ -127,6 +135,10 @@ pub(crate) fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui, canvas: egui::Rec
|
||||
#[path = "../move_hover_auto_select_off_tests.rs"]
|
||||
mod move_hover_auto_select_off_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../move_hover_active_layer_tests.rs"]
|
||||
mod move_hover_active_layer_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json::json;
|
||||
@@ -210,6 +222,8 @@ mod tests {
|
||||
})
|
||||
.unwrap();
|
||||
let target_layer = app.session.active().unwrap().active_layer.unwrap();
|
||||
// An empty layer on top takes the active layer: the active layer isn't outlined.
|
||||
app.session.execute("layer.new.layer", json!({})).unwrap();
|
||||
app.ui.tool = Tool::Move;
|
||||
|
||||
// Hovering over painted layer sets canvas_hover_layer:
|
||||
|
||||
Reference in new issue
Block a user