Files
gridcraft/crates/ui-egui/tests/it/support.rs
T
aiongg 2c4652d3d8 Host GridCraft's egui UI on craft-libs next's runtime
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.
2026-11-24 15:52:54 +00:00

52 lines
2.1 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! Constructors for the suite's usual harness shapes.
//!
//! The strict font and lifecycle setup stays in `crate::common`; these wrap it at the sizes and
//! step timings the `it` tests share. Keeping them here (rather than in `common`) leaves the
//! `keytips` test binary's copy of `common` free of helpers only this binary uses.
use crate::common::{Harness, app, builder, harness_with, prepare};
use gridcraft_engine::Session;
use gridcraft_ui_egui::{Services, SheetApp};
/// A blank workbook session, as most integration tests start.
pub fn blank_session() -> Session {
let mut session = Session::new();
session.new_workbook();
session
}
/// The suite's usual 1200×800 harness around `session`, warmed for `steps` frames.
pub fn harness(session: Session, steps: usize) -> Harness {
harness_with(builder().with_size(egui::vec2(1200.0, 800.0)), app(session), steps)
}
/// A blank workbook in the suite's usual 1200×800 harness.
pub fn blank_harness(steps: usize) -> Harness {
harness(blank_session(), steps)
}
/// A 1200×800 harness advancing in 1/60 s frames, for drags and hover sequences.
pub fn stepped_harness(session: Session) -> Harness {
harness_with(builder().with_step_dt(1.0 / 60.0).with_size(egui::vec2(1200.0, 800.0)), app(session), 4)
}
/// A harness around an app built with the caller's `Services` (e.g. a test inbox).
pub fn services_harness(services: Services, steps: usize) -> Harness {
harness_with(builder().with_size(egui::vec2(1200.0, 800.0)), prepare(SheetApp::new(blank_session(), services)), steps)
}
/// A harness around an already-prepared `app`, at the suite's usual 1200×800 size.
pub fn app_harness(app: SheetApp, steps: usize) -> Harness {
harness_with(builder().with_size(egui::vec2(1200.0, 800.0)), app, steps)
}
/// Runs `n` frames as the desktop and web shells do: the app hands the runtime its frame input
/// (theme mode, interface scale) before each one.
pub fn frames(h: &mut Harness, n: usize) {
for _ in 0..n {
let ctx = h.ctx.clone();
h.state_mut().before_input(&ctx);
h.step();
}
}