mirror of
https://github.com/storytold/photocraft.git
synced 2026-10-24 09:57:08 -06:00
This commit is contained in:
@@ -3853,6 +3853,26 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn view_snap_off_survives_a_restart() {
|
||||
let (mut app, store) = app_with_store();
|
||||
let ctx = egui::Context::default();
|
||||
tick(&mut app, &ctx);
|
||||
assert!(app.ui.extras.snap, "on by default");
|
||||
crate::menus::invoke(&mut app, &ctx, "view.snap", json!({})).unwrap();
|
||||
assert!(!app.ui.extras.snap);
|
||||
crate::view_cmds::persist(&mut app, &ctx);
|
||||
tick(&mut app, &ctx);
|
||||
assert_eq!(stored(&store)["viewExtras"], json!({"snap": false}));
|
||||
let saved = store.lock().unwrap().clone().unwrap();
|
||||
let (mut app2, _) = app_with_saved(Some(saved));
|
||||
tick(&mut app2, &ctx);
|
||||
assert!(!app2.ui.extras.snap, "still off after a restart");
|
||||
crate::menus::invoke(&mut app2, &ctx, "view.snap", json!({})).unwrap();
|
||||
crate::view_cmds::persist(&mut app2, &ctx);
|
||||
assert!(app2.session.prefs().view_extras.is_null());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn show_tooltips_preferences_turn_tooltips_off() {
|
||||
let (mut app, _) = app_with_store();
|
||||
|
||||
@@ -288,7 +288,7 @@ fn pixel_round(app: &PhotocraftApp, p: [f64; 2]) -> [f64; 2] {
|
||||
fn apply(app: &mut PhotocraftApp, p: [f64; 2], mods: egui::Modifiers) -> [f64; 2] {
|
||||
let tol = tolerance(app);
|
||||
let Some(snap) = app.prefs_rt.snap.as_ref() else { return p };
|
||||
if snap.disabled {
|
||||
if !snap_on(app) || snap.disabled {
|
||||
app.prefs_rt.snap_lines.clear();
|
||||
return p;
|
||||
}
|
||||
@@ -705,6 +705,20 @@ mod tests {
|
||||
assert!(!override_held(cmd) && override_held(ctrl));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn snap_off_disables_all_snapping_even_with_smart_guides() {
|
||||
let mut app = app_with_box();
|
||||
app.ui.tool = Tool::Move;
|
||||
assert!(app.ui.view.show.smart_guides);
|
||||
app.ui.extras.snap = false;
|
||||
app.ui.tool_options.move_auto_select = false;
|
||||
let m = egui::Modifiers::NONE;
|
||||
crate::canvas::tool_event(&mut app, ToolEvent::Down { x: 60.0, y: 60.0, pressure: 1.0 }, m);
|
||||
crate::canvas::tool_event(&mut app, ToolEvent::Up { x: 323.0, y: 100.0 }, m);
|
||||
assert_eq!(mover_bounds(&app).x0, 303);
|
||||
assert!(app.prefs_rt.snap_lines.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn marquee_corner_snaps_to_guides_and_document_edges() {
|
||||
let mut app = app_with_box();
|
||||
|
||||
@@ -302,6 +302,9 @@ fn remembered(app: &PhotocraftApp) -> Value {
|
||||
if e.guides != def.guides {
|
||||
m.insert("guides".into(), Value::Bool(e.guides));
|
||||
}
|
||||
if e.snap != def.snap {
|
||||
m.insert("snap".into(), Value::Bool(e.snap));
|
||||
}
|
||||
if let Some(show) = changed_flags(v.show, Show::default(), &SHOW_KEYS, show_slot) {
|
||||
m.insert("show".into(), show);
|
||||
}
|
||||
@@ -342,6 +345,9 @@ pub fn restore(app: &mut PhotocraftApp) {
|
||||
if let Some(on) = flag("guides") {
|
||||
app.ui.extras.guides = on;
|
||||
}
|
||||
if let Some(on) = flag("snap") {
|
||||
app.ui.extras.snap = on;
|
||||
}
|
||||
for (k, v) in saved.get("show").and_then(Value::as_object).into_iter().flatten() {
|
||||
if let (Some(slot), Some(on)) = (show_slot(&mut app.ui.view.show, k), v.as_bool()) {
|
||||
*slot = on;
|
||||
|
||||
Reference in New Issue
Block a user