mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-25 02:07:09 -06:00
Presentation Mode hides the menus and panels, had no Escape and was saved with the preferences, so it came back on every restart with no way out. Escape now leaves it (as in Illustrator), F from it goes back to Normal Screen Mode, and the screen mode is no longer saved: the app always starts in Normal Screen Mode, and preferences saved in Presentation Mode by older versions open normally. ui.inspect reports `screenMode` on its own. Desktop file drags carry no pointer position or modifiers (winit 0.30 on Windows, macOS and X11), so every drop on a window with a document open was taken for the middle of the canvas and placed. Where the platform doesn't say, a dropped document (native, SVG, PDF, .ai, EPS, DXF, EMF/WMF) now opens as a tab of its own and a picture or text is placed in the middle of the view; pictures dropped together with documents are placed first, so the last document opened is shown. The web, whose drag events give the position, keeps Illustrator's choice: placed on the canvas, opened off it (the tab bar). Illustrator's PDF-compatible part leaves out art outside the artboards (it lives in the private data alone, which isn't read), so it can't open; importing a file with that private data now says so in a note. Off-page art a PDF does draw already opens on the pasteboard; a test keeps it so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
61 lines
2.6 KiB
Rust
61 lines
2.6 KiB
Rust
//! Screen modes and Presentation Mode (#472): Escape leaves Presentation Mode, F cycles the three
|
|
//! screen modes, and no screen mode is saved with the preferences.
|
|
|
|
use serde_json::json;
|
|
use vectorcraft_engine::Session;
|
|
|
|
use crate::VectorcraftApp;
|
|
|
|
/// One headless frame of the whole window with `events`.
|
|
fn frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec<egui::Event>) {
|
|
let raw =
|
|
egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, 600.0))), events, ..Default::default() };
|
|
let mut out = ctx.run_ui(raw, |ui| {
|
|
app.logic(ui.ctx());
|
|
app.ui(ui);
|
|
});
|
|
out.textures_delta.clear();
|
|
}
|
|
|
|
fn escape() -> Vec<egui::Event> {
|
|
[true, false]
|
|
.map(|pressed| egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed, repeat: false, modifiers: Default::default() })
|
|
.to_vec()
|
|
}
|
|
|
|
#[test]
|
|
fn escape_leaves_presentation_mode() {
|
|
let mut app = VectorcraftApp::new(Session::new(), crate::Services::default());
|
|
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
|
let ctx = egui::Context::default();
|
|
frame(&mut app, &ctx, vec![]);
|
|
assert_eq!(app.run("view.presentation", json!({})).unwrap(), json!(3));
|
|
frame(&mut app, &ctx, vec![]);
|
|
assert_eq!(crate::control::inspect(&app, &ctx)["screenMode"], json!(3), "agents see the screen mode");
|
|
frame(&mut app, &ctx, escape());
|
|
assert_eq!(app.ui.screen_mode, 0, "Escape is back in Normal Screen Mode");
|
|
// Escape in Normal Screen Mode leaves it so.
|
|
frame(&mut app, &ctx, escape());
|
|
assert_eq!(app.ui.screen_mode, 0);
|
|
}
|
|
|
|
#[test]
|
|
fn f_cycles_the_screen_modes_and_leaves_presentation_mode() {
|
|
let mut app = VectorcraftApp::new(Session::new(), crate::Services::default());
|
|
let modes: Vec<u64> = (0..4).map(|_| app.run("view.screenMode", json!({})).unwrap().as_u64().unwrap()).collect();
|
|
assert_eq!(modes, [1, 2, 0, 1]);
|
|
app.run("view.presentation", json!({})).unwrap();
|
|
assert_eq!(app.run("view.screenMode", json!({})).unwrap(), json!(0), "from Presentation Mode, F goes back to Normal");
|
|
}
|
|
|
|
#[test]
|
|
fn the_screen_mode_is_not_saved() {
|
|
let mut app = VectorcraftApp::new(Session::new(), crate::Services::default());
|
|
app.run("view.presentation", json!({})).unwrap();
|
|
let saved = serde_json::to_value(&app.ui).unwrap();
|
|
assert!(saved.get("screen_mode").is_none(), "{saved}");
|
|
// Preferences an older version saved in Presentation Mode start in Normal Screen Mode.
|
|
let old: crate::state::UiState = serde_json::from_value(json!({ "screen_mode": 3 })).unwrap();
|
|
assert_eq!(old.screen_mode, 0);
|
|
}
|