mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-30 10:13:56 +01:00
The runtime's four hooks in the desktop and web shells, the close path decided by SheetApp::close_decision, Escape read through the window's cancel where no GridCraft widget has the keyboard, the grid as the window's host canvas, the interface scale as the runtime's RootEnv scale, fonts through craft_ui::fonts::load with the chrome's families, the update dialogs on a DialogHost, and app-local copies of the removed capture slot, combo menu and window viewports; the print controls on craft-print's ui feature. Test harnesses that run the app install the runtime.
44 lines
2.0 KiB
Rust
44 lines
2.0 KiB
Rust
//! Interface size preference (#230): a persistent zoom for the whole window, clamped.
|
|
|
|
use gridcraft_engine::Session;
|
|
use gridcraft_ui_egui::{SheetApp, UiState};
|
|
use serde_json::json;
|
|
|
|
#[test]
|
|
/// Interface size applies and persists, clamps to 75-200, accepts `auto`, and rejects missing or non-numeric values.
|
|
fn interface_size_applies_persists_and_clamps() {
|
|
let mut session = Session::new();
|
|
session.new_workbook();
|
|
let mut h = crate::common::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|
|
|ui, app: &mut SheetApp| {
|
|
app.logic(ui.ctx());
|
|
app.ui(ui);
|
|
},
|
|
crate::common::app(session),
|
|
);
|
|
crate::support::frames(&mut h, 2);
|
|
assert_eq!(h.ctx.zoom_factor(), 1.0);
|
|
|
|
h.state_mut().run("view.interfaceScale", json!({"percent": 125})).unwrap();
|
|
crate::support::frames(&mut h, 2);
|
|
assert_eq!(h.ctx.zoom_factor(), 1.25);
|
|
let saved: UiState = serde_json::from_str(&serde_json::to_string(&h.state().ui).unwrap()).unwrap();
|
|
assert_eq!(saved.interface_scale, 125);
|
|
|
|
// Hostile and missing values: clamped or refused, never applied raw.
|
|
assert_eq!(h.state_mut().run("view.interfaceScale", json!({"percent": 1e12})).unwrap()["percent"], 200);
|
|
assert_eq!(h.state_mut().run("view.interfaceScale", json!({"percent": -5})).unwrap()["percent"], 75);
|
|
assert!(h.state_mut().run("view.interfaceScale", json!({})).is_err(), "no value is an error, not a dialog");
|
|
assert!(h.state_mut().run("view.interfaceScale", json!({"percent": "huge"})).is_err());
|
|
h.state_mut().run("view.interfaceScale", json!({"percent": "auto"})).unwrap();
|
|
crate::support::frames(&mut h, 2);
|
|
assert_eq!(h.ctx.zoom_factor(), 1.0);
|
|
|
|
// A malformed or out-of-range ui.json keeps the other preferences.
|
|
let ui: UiState = serde_json::from_str(r#"{"dark": true, "interfaceScale": "big"}"#).unwrap();
|
|
assert!(ui.dark);
|
|
assert_eq!(ui.interface_scale, 100);
|
|
let ui: UiState = serde_json::from_str(r#"{"interfaceScale": 900}"#).unwrap();
|
|
assert_eq!(ui.interface_scale, 200);
|
|
}
|