Tests: the runtime in the test windows that draw FigCraft's UI

Each such window installs the runtime headless and hands it FigCraft's
frame input before each frame, as the shells do; the main window's
close tests run its close path.
This commit is contained in:
aiongg
2026-11-24 18:40:53 +00:00
parent 51473c7e17
commit 3ddb9d46ec
28 changed files with 103 additions and 64 deletions
+2 -1
View File
@@ -43,6 +43,7 @@ fn start(dir: &std::path::Path) -> FigApp {
/// Draw two frames (the first only sets the fonts up).
fn frames(fig: &mut FigApp, ctx: &egui::Context) {
for _ in 0..2 {
fig.before_input(ctx);
ctx.run_ui(egui::RawInput::default(), |ui| fig.ui(ui)).textures_delta.clear();
}
}
@@ -51,7 +52,7 @@ fn frames(fig: &mut FigApp, ctx: &egui::Context) {
fn plugins_are_kept_when_the_app_is_killed() {
let dir = root("killed");
let folder = plugin(&dir);
let ctx = egui::Context::default();
let ctx = figcraft_ui_egui::framework::headless_context();
let mut fig = start(&dir);
assert!(fig.run("plugin.import", json!({"path": folder.to_string_lossy()})).is_some());
frames(&mut fig, &ctx);
@@ -25,7 +25,7 @@ impl Harness {
s.execute("file.new", &json!({"name": n})).unwrap();
s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 200, "height": 120})).unwrap();
}
Self { ctx: egui::Context::default(), app: FigApp::new(s, Box::new(NoServices)), time: 0.0 }
Self { ctx: crate::framework::headless_context(), app: FigApp::new(s, Box::new(NoServices)), time: 0.0 }
}
/// One frame with no input, 1/60 s after the last.
@@ -34,6 +34,7 @@ impl Harness {
self.app.clock.set_test_now(Some(self.time));
let input = RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1440.0, 900.0))), time: Some(self.time), ..Default::default() };
let app = &mut self.app;
app.before_input(&self.ctx);
let mut out = self.ctx.run_ui(input, |ui| app.ui(ui));
out.textures_delta.clear();
}
@@ -29,7 +29,7 @@ impl Canvas {
}
fn with_invert(scroll_wheel_zoom: bool, invert_zoom: bool) -> Self {
let mut c = Self { ctx: egui::Context::default(), app: FigApp::new(Session::new(), Box::new(NoServices)), time: 0.0 };
let mut c = Self { ctx: crate::framework::headless_context(), app: FigApp::new(Session::new(), Box::new(NoServices)), time: 0.0 };
c.app.run("pref.scrollWheelZoom", json!({"on": scroll_wheel_zoom}));
c.app.run("pref.invertZoom", json!({"on": invert_zoom}));
for _ in 0..3 {
@@ -50,6 +50,7 @@ impl Canvas {
let input =
RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1440.0, 900.0))), time: Some(self.time), events, ..Default::default() };
let app = &mut self.app;
app.before_input(&self.ctx);
let mut out = self.ctx.run_ui(input, |ui| app.ui(ui));
out.textures_delta.clear();
}
+2 -1
View File
@@ -62,7 +62,7 @@ impl Win {
fn with_session(s: Session) -> Self {
let recorded = Arc::new(Mutex::new(Recorded::default()));
let app = FigApp::new(s, Box::new(Clipboard(recorded.clone())));
let mut win = Self { ctx: egui::Context::default(), app, time: 0.0, recorded };
let mut win = Self { ctx: crate::framework::headless_context(), app, time: 0.0, recorded };
for _ in 0..3 {
win.frame(vec![]);
}
@@ -76,6 +76,7 @@ impl Win {
let input =
RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1440.0, 900.0))), time: Some(self.time), events, ..Default::default() };
let app = &mut self.app;
app.before_input(&self.ctx);
let mut out = self.ctx.run_ui(input, |ui| app.ui(ui));
out.textures_delta.clear();
}
@@ -34,6 +34,7 @@ fn settle_to_issue(u: &mut Ui, n: usize) {
fn resized_frame(u: &mut Ui, size: egui::Vec2) -> egui::FullOutput {
let input = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, size)), ..Default::default() };
let app = &mut u.app;
app.before_input(&u.ctx);
let mut out = u.ctx.run_ui(input, |ui| app.ui(ui));
out.textures_delta.clear();
out
@@ -592,6 +593,7 @@ fn a_discarded_pass_does_not_acknowledge_or_lose_an_injected_batch() {
let app = &mut u.app;
let ctx = u.ctx.clone();
let mut passes = 0;
app.before_input(&ctx);
let mut out = ctx.run_ui(input, |ui| {
passes += 1;
app.ui(ui);
@@ -638,6 +640,7 @@ fn injected_text_lands_once_across_a_discarded_sizing_pass() {
let app = &mut u.app;
let ctx = u.ctx.clone();
let mut passes = 0;
app.before_input(&ctx);
let mut out = ctx.run_ui(input, |ui| {
passes += 1;
app.ui(ui);
@@ -42,7 +42,7 @@ struct Ui {
impl Ui {
fn new() -> Self {
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
crate::theme::install_fonts(&ctx, false, 0);
crate::theme::apply(&ctx, Tokens::light());
let mut u = Self { ctx, time: 0.0 };
@@ -250,7 +250,7 @@ fn the_models_table_is_as_tall_as_its_rows() {
#[test]
fn the_about_window_draws_every_tab() {
// The whole app, with the compiled-in credits (whatever contributors.json held, or none).
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
let mut app = crate::FigApp::new(figcraft_engine::Session::new(), Box::new(crate::NoServices));
app.ui.about = true;
for (i, tab) in crate::dialogs::AboutTab::ALL.into_iter().enumerate() {
@@ -261,6 +261,7 @@ fn the_about_window_draws_every_tab() {
time: Some((i * 3 + f) as f64 / 60.0),
..Default::default()
};
app.before_input(&ctx);
ctx.run_ui(input, |ui| app.ui(ui)).textures_delta.clear();
}
assert!(app.ui.about, "{tab:?}: the About window closed");
@@ -312,7 +313,7 @@ fn settled_frame(ctx: &egui::Context) -> Vec<Rect> {
/// A new context with the table open and settled, and the rects of its header cells.
fn opened_table() -> (egui::Context, Vec<Rect>) {
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
settled_frame(&ctx);
let cells = settled_frame(&ctx);
(ctx, cells)
+4 -2
View File
@@ -30,7 +30,7 @@ impl Harness {
// again: scanned here, before the first frame, rather than by whichever test happens to
// run first while this one waits for idle (#333).
figcraft_text::scan_system_fonts();
Self { ctx: egui::Context::default(), app: FigApp::new(s, Box::new(NoServices)), time: 0.0 }
Self { ctx: crate::framework::headless_context(), app: FigApp::new(s, Box::new(NoServices)), time: 0.0 }
}
/// One frame with `events`, 1/60 s after the last; returns the repaint delay it asked for.
@@ -40,6 +40,7 @@ impl Harness {
let input =
RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1440.0, 900.0))), time: Some(self.time), events, ..Default::default() };
let app = &mut self.app;
app.before_input(&self.ctx);
let mut out = self.ctx.run_ui(input, |ui| app.ui(ui));
out.textures_delta.clear();
out.viewport_output.get(&ViewportId::ROOT).map_or(Duration::MAX, |v| v.repaint_delay)
@@ -216,7 +217,7 @@ fn a_toast_raised_by_a_slow_frame_still_shows_for_3_s() {
#[test]
fn a_finished_background_render_wakes_the_ui() {
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
let wakes = Arc::new(AtomicUsize::new(0));
let w = wakes.clone();
ctx.set_request_repaint_callback(move |_| {
@@ -549,6 +550,7 @@ fn a_discarded_sizing_pass_sets_up_and_counts_one_frame_only() {
RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1440.0, 900.0))), time: Some(h.time + 1.0 / 60.0), ..Default::default() };
let mut passes = 0;
let app = &mut h.app;
app.before_input(&h.ctx);
let mut out = h.ctx.run_ui(input, |ui| {
passes += 1;
app.ui(ui);
+5 -1
View File
@@ -19,7 +19,8 @@ pub(crate) struct Ui {
impl Ui {
pub(crate) fn new(s: Session) -> Self {
let mut u = Self { ctx: egui::Context::default(), app: FigApp::new(s, Box::new(NoServices)), time: 0.0, screen: vec2(1440.0, 900.0) };
let mut u =
Self { ctx: crate::framework::headless_context(), app: FigApp::new(s, Box::new(NoServices)), time: 0.0, screen: vec2(1440.0, 900.0) };
for _ in 0..3 {
u.frame(vec![]);
}
@@ -48,6 +49,8 @@ impl Ui {
self.app.clock.set_test_now(Some(self.time));
let input = RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, self.screen)), time: Some(self.time), ..raw };
let app = &mut self.app;
// As the shells do: the runtime gets FigCraft's frame input before the frame.
app.before_input(&self.ctx);
let mut out = self.ctx.run_ui(input, |ui| app.ui(ui));
out.textures_delta.clear();
out
@@ -62,6 +65,7 @@ impl Ui {
self.app.clock.set_test_now(Some(self.time));
let input = RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1440.0, 900.0))), time: Some(self.time), ..raw };
let Ui { ctx, app, .. } = self;
app.before_input(ctx);
let mut out = ctx.run_ui(input, |ui| {
app.ui(ui);
if ui.ctx().current_pass_index() == 0 {
+2 -1
View File
@@ -69,7 +69,7 @@ impl Harness {
s.execute("select.set", &json!({"ids": []})).unwrap();
let events = Arc::new(Mutex::new(Vec::new()));
s.live.install(Box::new(Mock(events.clone(), 0)));
let h = Harness { ctx: egui::Context::default(), app: FigApp::new(s, Box::new(NoServices)), time: 0.0, events };
let h = Harness { ctx: crate::framework::headless_context(), app: FigApp::new(s, Box::new(NoServices)), time: 0.0, events };
(h, rect)
}
@@ -79,6 +79,7 @@ impl Harness {
let input =
RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1440.0, 900.0))), time: Some(self.time), events, ..Default::default() };
let app = &mut self.app;
app.before_input(&self.ctx);
let mut out = self.ctx.run_ui(input, |ui| app.ui(ui));
out.textures_delta.clear();
let delay = out.viewport_output.get(&ViewportId::ROOT).map_or(Duration::MAX, |v| v.repaint_delay);
+2 -1
View File
@@ -23,7 +23,7 @@ struct Ui {
impl Ui {
fn new() -> Self {
let app = FigApp::new(Session::new(), Box::new(NoServices));
let mut u = Self { ctx: egui::Context::default(), app, time: 0.0 };
let mut u = Self { ctx: crate::framework::headless_context(), app, time: 0.0 };
for _ in 0..3 {
u.frame(vec![]);
}
@@ -34,6 +34,7 @@ impl Ui {
self.time += 1.0 / 60.0;
let input = RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, SIZE)), time: Some(self.time), events, ..Default::default() };
let app = &mut self.app;
app.before_input(&self.ctx);
let mut out = self.ctx.run_ui(input, |ui| app.ui(ui));
out.textures_delta.clear();
}
+6 -3
View File
@@ -289,12 +289,13 @@ fn the_smallest_window_keeps_its_canvas_whatever_the_widths() {
for asked in [(240.0, 240.0), (450.0, 500.0), (450.0, 240.0), (240.0, 500.0)] {
let mut s = Session::new();
s.prefs.panel_widths = asked;
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
let mut app = FigApp::new(s, Box::new(NoServices));
// The desktop window's minimum inner size.
let screen = Rect::from_min_size(Pos2::ZERO, vec2(800.0, 500.0));
for k in 0..5 {
let input = RawInput { screen_rect: Some(screen), time: Some(f64::from(k) / 60.0), ..Default::default() };
app.before_input(&ctx);
ctx.run_ui(input, |ui| app.ui(ui)).textures_delta.clear();
}
let canvas = app.canvas.rect;
@@ -311,13 +312,14 @@ fn the_smallest_window_keeps_its_canvas_whatever_the_widths() {
#[test]
fn a_narrow_window_keeps_its_panel_buttons_while_minimized() {
use crate::MobilePanel;
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
let mut app = FigApp::new(Session::new(), Box::new(NoServices));
let mut k = 0.0;
let mut canvas_width = |app: &mut FigApp, size: egui::Vec2| {
for _ in 0..4 {
k += 1.0 / 60.0;
let input = RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, size)), time: Some(k), ..Default::default() };
app.before_input(&ctx);
ctx.run_ui(input, |ui| app.ui(ui)).textures_delta.clear();
}
app.canvas.rect.width()
@@ -341,13 +343,14 @@ fn a_narrow_window_keeps_its_panel_buttons_while_minimized() {
#[test]
fn a_narrow_window_shows_one_side_panel_at_a_time() {
use crate::MobilePanel;
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
let mut app = FigApp::new(Session::new(), Box::new(NoServices));
let mut k = 0.0;
let mut canvas_width = |app: &mut FigApp, size: egui::Vec2| {
for _ in 0..4 {
k += 1.0 / 60.0;
let input = RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, size)), time: Some(k), ..Default::default() };
app.before_input(&ctx);
ctx.run_ui(input, |ui| app.ui(ui)).textures_delta.clear();
}
app.canvas.rect.width()
+2 -1
View File
@@ -64,7 +64,7 @@ impl Win {
let mut s = Session::new();
s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 100, "height": 50})).unwrap();
s.execute("select.none", &json!({})).unwrap();
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
let clip = Rc::new(RefCell::new(Clip::default()));
let app = FigApp::new(s, Box::new(Desktop(clip.clone())));
let mut w = Self { ctx, app, time: 0.0, clip, shapes: Vec::new() };
@@ -84,6 +84,7 @@ impl Win {
let input =
RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1440.0, 900.0))), time: Some(self.time), events, ..Default::default() };
let app = &mut self.app;
app.before_input(&self.ctx);
let mut out = self.ctx.run_ui(input, |ui| {
if take_v {
ui.ctx().input_mut(|i| i.consume_key(Modifiers::NONE, Key::V));
+5 -3
View File
@@ -30,7 +30,8 @@ impl Bench {
fn with_document(doc: Document) -> Self {
figcraft_text::scan_system_fonts();
let mut b = Self { ctx: egui::Context::default(), app: FigApp::new(Session::with_document(doc), Box::new(NoServices)), time: 0.0 };
let mut b =
Self { ctx: crate::framework::headless_context(), app: FigApp::new(Session::with_document(doc), Box::new(NoServices)), time: 0.0 };
// Fonts install on the first frame; the next ones lay out and settle.
for _ in 0..4 {
b.frame(vec![]);
@@ -49,6 +50,7 @@ impl Bench {
};
let t = Instant::now();
let app = &mut self.app;
app.before_input(&self.ctx);
let mut out = self.ctx.run_ui(input, |ui| app.ui(ui));
let ms = t.elapsed().as_secs_f64() * 1000.0;
// No GPU here to take the texture uploads.
@@ -300,7 +302,7 @@ fn ids(rows: &[crate::layers::Row]) -> Vec<NodeId> {
#[test]
fn layer_rows_follow_edits_undo_pages_expansion_and_filter() {
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
let mut s = Session::new();
let page = s.page().unwrap();
let frame = s.execute("node.create", &json!({"type": "frame", "x": 0, "y": 0, "width": 100, "height": 100})).unwrap()["id"].as_u64().unwrap();
@@ -343,7 +345,7 @@ fn layer_rows_follow_edits_undo_pages_expansion_and_filter() {
#[test]
fn prototype_sources_follow_edits_and_undo() {
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
let mut s = Session::new();
let page = s.page().unwrap();
let id = |v: serde_json::Value| NodeId(v["id"].as_u64().unwrap());
+3 -2
View File
@@ -31,7 +31,7 @@ fn frame_margins(ctx: &egui::Context) -> f32 {
#[test]
fn a_menu_is_as_wide_as_its_widest_row_and_does_not_wrap() {
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
let mut t = 0.0;
let items = [("Copy as code", "Cmd+Shift+C"), ("Paste", "Cmd+V"), ("A much longer menu item label", "")];
let mut frame = |events: Vec<Event>| {
@@ -69,9 +69,10 @@ fn a_menu_is_as_wide_as_its_widest_row_and_does_not_wrap() {
fn right_panel_dropdown_menus_fit_the_panel() {
let mut app = FigApp::new(Session::new(), Box::new(NoServices));
app.ui.right_tab = RightTab::Inspect;
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
let mut t = 0.0;
let mut frame = |app: &mut FigApp, events: Vec<Event>| {
app.before_input(&ctx);
let mut out = ctx.run_ui(input(&mut t, events), |ui| app.ui(ui));
out.textures_delta.clear();
};
+2 -1
View File
@@ -19,7 +19,7 @@ pub(crate) struct Ui {
impl Ui {
pub(crate) fn new(s: Session) -> Self {
let mut u = Self { ctx: egui::Context::default(), app: FigApp::new(s, Box::new(NoServices)), time: 0.0, hidpi: None };
let mut u = Self { ctx: crate::framework::headless_context(), app: FigApp::new(s, Box::new(NoServices)), time: 0.0, hidpi: None };
u.frames(3, Vec::new);
u
}
@@ -38,6 +38,7 @@ impl Ui {
input.viewports.entry(egui::ViewportId::ROOT).or_default().native_pixels_per_point = Some(ppp);
}
let app = &mut self.app;
app.before_input(&self.ctx);
let mut out = self.ctx.run_ui(input, |ui| app.ui(ui));
out.textures_delta.clear();
out
+2 -1
View File
@@ -489,9 +489,10 @@ fn a_property_copied_in_one_window_pastes_in_another_and_the_highlight_stays_in_
s.execute("file.new", &json!({"name": "B"})).unwrap();
let b = rect(&mut s, 0.0, "#00FF00");
let clip = Rc::new(RefCell::new(None));
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
ctx.set_embed_viewports(false);
let mut app = crate::FigApp::new(s, Box::new(Clip(clip.clone())));
app.before_input(&ctx);
ctx.run_ui(egui::RawInput::default(), |ui| app.ui(ui)).textures_delta.clear();
// File A goes to a window of its own; the main window shows B.
let w = crate::control::handle(&mut app, &ctx, "window.new", &json!({"index": 0})).unwrap()["window"].as_u64().unwrap();
+11 -10
View File
@@ -7,13 +7,14 @@ use serde_json::json;
use crate::{FigApp, NoServices, Services, theme::Tokens};
fn frame(ctx: &Context, app: &mut FigApp, system: Option<Theme>) {
app.before_input(ctx);
let mut output = ctx.run_ui(RawInput { system_theme: system, ..Default::default() }, |ui| app.ui(ui));
output.textures_delta.clear();
}
#[test]
fn fresh_app_uses_system_dark_theme_on_its_first_frame() {
let ctx = Context::default();
let ctx = crate::framework::headless_context();
let mut app = FigApp::new(Session::empty(), Box::new(NoServices));
frame(&ctx, &mut app, Some(Theme::Dark));
assert!(app.ui.dark, "a first run must use the OS dark theme before drawing");
@@ -24,7 +25,7 @@ fn fresh_app_uses_system_dark_theme_on_its_first_frame() {
#[test]
fn first_run_and_preferences_without_a_theme_follow_system_light() {
for prefs in [Prefs::default(), serde_json::from_value(json!({"nudge_small": 2})).unwrap()] {
let ctx = Context::default();
let ctx = crate::framework::headless_context();
let mut session = Session::empty();
session.prefs = prefs;
let mut app = FigApp::new(session, Box::new(NoServices));
@@ -37,7 +38,7 @@ fn first_run_and_preferences_without_a_theme_follow_system_light() {
#[test]
fn saved_manual_themes_survive_startup_and_os_changes() {
for (saved, expected) in [("light", Tokens::light()), ("dark", Tokens::dark())] {
let ctx = Context::default();
let ctx = crate::framework::headless_context();
let mut session = Session::empty();
session.prefs = serde_json::from_value(json!({"theme": saved})).unwrap();
let mut app = FigApp::new(session, Box::new(NoServices));
@@ -52,7 +53,7 @@ fn saved_manual_themes_survive_startup_and_os_changes() {
#[test]
fn returning_to_system_reads_the_os_not_the_previously_drawn_palette() {
for (manual, os) in [("view.themeLight", Theme::Dark), ("view.themeDark", Theme::Light)] {
let ctx = Context::default();
let ctx = crate::framework::headless_context();
let mut app = FigApp::new(Session::empty(), Box::new(NoServices));
app.session.execute(manual, &json!({})).unwrap();
frame(&ctx, &mut app, Some(os));
@@ -65,7 +66,7 @@ fn returning_to_system_reads_the_os_not_the_previously_drawn_palette() {
#[test]
fn system_theme_changes_apply_in_the_same_frame() {
let ctx = Context::default();
let ctx = crate::framework::headless_context();
let mut app = FigApp::new(Session::empty(), Box::new(NoServices));
app.session.execute("view.themeSystem", &json!({})).unwrap();
for os in [Theme::Dark, Theme::Light, Theme::Dark] {
@@ -77,7 +78,7 @@ fn system_theme_changes_apply_in_the_same_frame() {
#[test]
fn unavailable_system_theme_uses_the_existing_light_fallback() {
let ctx = Context::default();
let ctx = crate::framework::headless_context();
let mut app = FigApp::new(Session::empty(), Box::new(NoServices));
app.session.execute("view.themeSystem", &json!({})).unwrap();
frame(&ctx, &mut app, None);
@@ -96,7 +97,7 @@ impl Services for Scheme {
#[test]
fn without_a_system_theme_the_colour_scheme_services_decide() {
for (dark, expected) in [(Some(true), Tokens::dark()), (Some(false), Tokens::light())] {
let ctx = Context::default();
let ctx = crate::framework::headless_context();
let mut app = FigApp::new(Session::empty(), Box::new(Scheme(dark)));
app.session.execute("view.themeSystem", &json!({})).unwrap();
frame(&ctx, &mut app, None);
@@ -108,7 +109,7 @@ fn without_a_system_theme_the_colour_scheme_services_decide() {
#[test]
fn the_os_theme_wins_over_the_colour_scheme_services() {
for (os, scheme) in [(Theme::Light, Some(true)), (Theme::Dark, Some(false))] {
let ctx = Context::default();
let ctx = crate::framework::headless_context();
let mut app = FigApp::new(Session::empty(), Box::new(Scheme(scheme)));
app.session.execute("view.themeSystem", &json!({})).unwrap();
frame(&ctx, &mut app, Some(os));
@@ -118,7 +119,7 @@ fn the_os_theme_wins_over_the_colour_scheme_services() {
#[test]
fn manual_themes_ignore_the_colour_scheme_services() {
let ctx = Context::default();
let ctx = crate::framework::headless_context();
let mut app = FigApp::new(Session::empty(), Box::new(Scheme(Some(false))));
app.session.execute("view.themeDark", &json!({})).unwrap();
frame(&ctx, &mut app, None);
@@ -132,7 +133,7 @@ fn tests_have_the_explicit_default_and_monochrome_emoji_font_features() {
// 0.37 egui has no default features, and kittest's own dev-features do not propagate to this
// crate. The test graph must therefore enable `default_fonts` and `monochrome_emoji_fonts`
// explicitly (Cargo.toml), or strict glyph tests would silently draw tofu.
let ctx = Context::default();
let ctx = crate::framework::headless_context();
let mut app = FigApp::new(Session::empty(), Box::new(NoServices));
frame(&ctx, &mut app, Some(Theme::Light));
frame(&ctx, &mut app, Some(Theme::Light));
+2 -1
View File
@@ -24,7 +24,7 @@ impl Ui {
fn new(title_bar: TitleBar) -> Self {
let mut app = FigApp::new(Session::new(), Box::new(NoServices));
app.ui.title_bar = title_bar;
let mut u = Self { ctx: egui::Context::default(), app, time: 0.0, maximized: false, modifiers: egui::Modifiers::NONE };
let mut u = Self { ctx: crate::framework::headless_context(), app, time: 0.0, maximized: false, modifiers: egui::Modifiers::NONE };
for _ in 0..3 {
u.frame(vec![]);
}
@@ -38,6 +38,7 @@ impl Ui {
let mut input = RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, SIZE)), time: Some(self.time), events, ..Default::default() };
input.viewports.entry(ViewportId::ROOT).or_default().maximized = Some(self.maximized);
let app = &mut self.app;
app.before_input(&self.ctx);
let mut out = self.ctx.run_ui(input, |ui| app.ui(ui));
out.textures_delta.clear();
out.viewport_output.get(&ViewportId::ROOT).map(|v| v.commands.clone()).unwrap_or_default()
+2 -1
View File
@@ -108,7 +108,7 @@ fn every_window_size_system_scale_and_interface_size_lays_out_inside_the_window(
let case = format!("{w}x{h} pt at {native}x, {want}");
let mut app = FigApp::new(Session::new(), Box::new(NoServices));
assert!(app.run("pref.uiScale", json!({"scale": want})).is_some(), "{case}");
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
let mut time = 0.0;
let mut seen = Vec::new();
for _ in 0..8 {
@@ -116,6 +116,7 @@ fn every_window_size_system_scale_and_interface_size_lays_out_inside_the_window(
let ppp = ctx.pixels_per_point();
let mut raw = RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, px / ppp)), time: Some(time), ..Default::default() };
raw.viewports.insert(ViewportId::ROOT, ViewportInfo { native_pixels_per_point: Some(native), ..Default::default() });
app.before_input(&ctx);
let mut out = ctx.run_ui(raw, |ui| app.ui(ui));
out.textures_delta.clear();
seen.push((ctx.pixels_per_point(), ctx.content_rect().size()));
+4 -3
View File
@@ -38,7 +38,7 @@ impl Page {
let mut s = Session::new();
let r = s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 100, "height": 50})).unwrap();
s.execute("select.set", &json!({"ids": [r["id"]]})).unwrap();
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
let app = FigApp::new(s, Box::new(Browser(ctx.clone())));
let mut p = Self { ctx, app, time: 0.0, clipboard: "text copied in another app".into() };
for _ in 0..3 {
@@ -59,6 +59,7 @@ impl Page {
RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1440.0, 900.0))), time: Some(self.time), events, ..Default::default() };
let app = &mut self.app;
let mut then = Some(then);
app.before_input(&self.ctx);
let mut out = self.ctx.run_ui(input, |ui| {
app.ui(ui);
if let Some(f) = then.take() {
@@ -219,7 +220,7 @@ fn copy_as_png_puts_an_image_on_the_clipboard() {
#[test]
fn a_mismatched_image_buffer_is_dropped() {
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
for (w, h, rgba) in [(4, 4, &[0u8; 10][..]), (u32::MAX, u32::MAX, &[][..])] {
let mut out = ctx.run_ui(RawInput::default(), |ui| egui_copy_png(ui.ctx(), w, h, rgba));
out.textures_delta.clear();
@@ -252,7 +253,7 @@ fn a_paste_event_its_own_text_never_triggers_the_synchronous_text_read() {
let mut s = Session::new();
s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 100, "height": 50})).unwrap();
let mut p = Page {
ctx: egui::Context::default(),
ctx: crate::framework::headless_context(),
app: FigApp::new(s, Box::new(CountingReads { reads: reads.clone() })),
time: 0.0,
clipboard: String::new(),
@@ -39,6 +39,7 @@ fn frame(ctx: &egui::Context, app: &mut FigApp, t: &mut f64) {
fn frame_with(ctx: &egui::Context, app: &mut FigApp, t: &mut f64, events: Vec<egui::Event>) {
*t += 1.0 / 60.0;
let input = RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1440.0, 900.0))), time: Some(*t), events, ..Default::default() };
app.before_input(ctx);
let mut out = ctx.run_ui(input, |ui| app.ui(ui));
out.textures_delta.clear();
}
@@ -53,7 +54,7 @@ fn picker_draws_every_view_and_commits_a_typed_name_on_close() {
s.execute("select.set", &json!({"ids": [r]})).unwrap();
s.execute("style.apply", &json!({"ids": [r], "style": "Brand/Primary", "target": "fill"})).unwrap();
let mut app = FigApp::new(s, Box::new(NoServices));
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
let mut t = 0.0;
for slot in [StyleSlot::Fill, StyleSlot::Stroke, StyleSlot::Effect, StyleSlot::Grid, StyleSlot::Text] {
open_for_selection(&mut app, slot, None);
@@ -101,7 +102,7 @@ fn text_session() -> (Session, figcraft_doc::NodeId) {
fn text_styles_preview_on_hover_and_apply_on_click() {
let (s, t) = text_session();
let mut app = FigApp::new(s, Box::new(NoServices));
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
let mut time = 0.0;
open_for_selection(&mut app, StyleSlot::Text, None);
for _ in 0..3 {
@@ -157,7 +158,7 @@ fn chars_linked_to_several_styles_show_mixed() {
assert_eq!(text_link(&app, &doc, &[t]), Some(doc.style("Type/Heading").map(|s| s.id.clone())));
// The panel draws the chip ("Mixed" when the edit spans both).
figcraft_engine::textedit::set_caret(&mut app.session, 4, true).unwrap();
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
let mut time = 0.0;
for _ in 0..3 {
frame(&ctx, &mut app, &mut time);
@@ -285,7 +286,7 @@ fn local_styles_list_draws_by_type_and_folder() {
s.execute("style.create", &json!({"type": ty, "name": name, "value": value})).unwrap();
}
let mut app = FigApp::new(s, Box::new(NoServices));
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
let mut t = 0.0;
// Nothing selected: the Design panel shows the page, with Local styles; a folder rename in
// progress draws its field.
@@ -307,7 +308,7 @@ fn edit_local_for_test(app: &mut FigApp, ctx: &egui::Context) {
/// Commits `typed` in the text style editor's field `field` ("ts_lh" / "ts_ls") with Enter and
/// returns the redefined style, if any.
fn commit_text_field(def: &TextStyle, field: &str, typed: &str) -> Option<TextStyle> {
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
ctx.data_mut(|d| d.insert_temp(Id::unique((field, "S")).with("editing"), typed.to_string()));
let enter = egui::Event::Key { key: egui::Key::Enter, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() };
let input = RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(400.0, 400.0))), events: vec![enter], ..Default::default() };
+18 -15
View File
@@ -17,8 +17,9 @@ fn frame(ctx: &egui::Context, app: &mut FigApp, close: bool) -> Vec<egui::Viewpo
if close {
input.viewports.insert(ViewportId::ROOT, ViewportInfo { events: vec![ViewportEvent::Close], ..Default::default() });
}
app.before_input(ctx);
let mut out = ctx.run_ui(input, |ui| {
crate::windows::on_close_request(app, ui.ctx());
app.close_path(ui.ctx());
app.ui(ui);
});
out.textures_delta.clear();
@@ -52,7 +53,7 @@ fn names(app: &FigApp) -> Vec<String> {
fn closing_a_window_in_the_presenter_shows_the_unsaved_changes_dialog() {
let mut session = Session::new();
let frame_id = session.execute("node.create", &json!({"type": "frame", "width": 402, "height": 874})).unwrap()["id"].clone();
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
let mut app = FigApp::new(session, Box::new(NoServices));
frame(&ctx, &mut app, false);
app.session.execute("proto.present", &json!({"start": frame_id})).unwrap();
@@ -73,7 +74,7 @@ fn windows_hold_tabs_and_close_with_their_files() {
for n in ["A", "B", "C"] {
s.execute("file.new", &json!({"name": n})).unwrap();
}
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
// As eframe does where windows are native.
ctx.set_embed_viewports(false);
let mut app = FigApp::new(s, Box::new(NoServices));
@@ -115,7 +116,7 @@ fn another_hidden_window_answers_requests_that_need_no_frame_in_its_own_file() {
for n in ["A", "B"] {
s.execute("file.new", &json!({"name": n})).unwrap();
}
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
ctx.set_embed_viewports(false);
let mut app = FigApp::new(s, Box::new(NoServices));
frame(&ctx, &mut app, false);
@@ -165,7 +166,7 @@ fn a_request_for_a_window_on_screen_wakes_it_while_the_main_window_is_hidden() {
for n in ["A", "B"] {
s.execute("file.new", &json!({"name": n})).unwrap();
}
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
ctx.set_embed_viewports(false);
let mut app = FigApp::new(s, Box::new(NoServices));
frame(&ctx, &mut app, false);
@@ -191,7 +192,7 @@ fn a_request_for_a_window_on_screen_wakes_it_while_the_main_window_is_hidden() {
fn every_direct_ui_frame_runs_background_work() {
// Direct `App::ui` harnesses never call `App::logic`: the tick marker the UI pass consumes
// must not leak into the next frame, or autosave/live/control work would run every other frame.
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
let mut app = FigApp::new(Session::empty(), Box::new(NoServices));
for _ in 0..3 {
frame(&ctx, &mut app, false);
@@ -207,7 +208,7 @@ fn synthetic_input_for_a_child_window_reaches_the_pane_that_draws_it() {
for n in ["A", "B"] {
s.execute("file.new", &json!({"name": n})).unwrap();
}
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
ctx.set_embed_viewports(false);
let mut app = FigApp::new(s, Box::new(NoServices));
frame(&ctx, &mut app, false);
@@ -231,7 +232,7 @@ fn a_frame_without_a_batch_does_not_error_another_windows_acknowledgement() {
for n in ["A", "B"] {
s.execute("file.new", &json!({"name": n})).unwrap();
}
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
ctx.set_embed_viewports(false);
let mut app = FigApp::new(s, Box::new(NoServices));
frame(&ctx, &mut app, false);
@@ -259,7 +260,7 @@ fn a_child_window_runs_the_ui_setup_the_main_window_does() {
for n in ["A", "B"] {
s.execute("file.new", &json!({"name": n})).unwrap();
}
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
ctx.set_embed_viewports(false);
let mut app = FigApp::new(s, Box::new(NoServices));
frame(&ctx, &mut app, false);
@@ -289,7 +290,7 @@ fn an_emptied_window_forgets_its_ime_context() {
for n in ["A", "B"] {
s.execute("file.new", &json!({"name": n})).unwrap();
}
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
ctx.set_embed_viewports(false);
let mut app = FigApp::new(s, Box::new(NoServices));
frame(&ctx, &mut app, false);
@@ -344,7 +345,7 @@ fn asking(path: Option<&std::path::Path>, save_as: Vec<std::path::PathBuf>) -> (
}
s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap();
let asked = std::rc::Rc::new(std::cell::Cell::new(0));
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
let mut app = FigApp::new(s, Box::new(SaveAs { paths: save_as, asked: asked.clone() }));
frame(&ctx, &mut app, false);
frame(&ctx, &mut app, true);
@@ -371,6 +372,7 @@ fn the_unsaved_changes_question_offers_save_dont_save_and_cancel() {
let (ctx, mut app, _) = asking(None, vec![]);
ctx.enable_accesskit();
frame(&ctx, &mut app, false);
app.before_input(&ctx);
let mut out = ctx.run_ui(RawInput::default(), |ui| app.ui(ui));
// A canvas picture that lands in this frame uploads a texture nobody applies here.
out.textures_delta.clear();
@@ -491,8 +493,9 @@ fn enter_answers_save() {
frame(&ctx, &mut app, false);
let enter = |pressed| egui::Event::Key { key: egui::Key::Enter, physical_key: None, pressed, repeat: false, modifiers: egui::Modifiers::NONE };
let input = RawInput { events: vec![enter(true), enter(false)], ..Default::default() };
app.before_input(&ctx);
ctx.run_ui(input, |ui| {
crate::windows::on_close_request(&mut app, ui.ctx());
app.close_path(ui.ctx());
app.ui(ui);
})
.textures_delta
@@ -511,7 +514,7 @@ fn enter_answers_save() {
fn a_quit_with_unsaved_changes_waits_for_the_answer() {
let mut s = Session::new();
s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap();
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
let mut app = FigApp::new(s, Box::new(NoServices));
frame(&ctx, &mut app, false);
let sent = frame(&ctx, &mut app, true);
@@ -533,7 +536,7 @@ fn quitting_twice_before_the_window_draws_closes_it_once() {
for n in ["A", "B"] {
s.execute("file.new", &json!({"name": n})).unwrap();
}
let ctx = egui::Context::default();
let ctx = crate::framework::headless_context();
ctx.set_embed_viewports(false);
let mut app = FigApp::new(s, Box::new(NoServices));
frame(&ctx, &mut app, false);
@@ -548,7 +551,7 @@ fn quitting_twice_before_the_window_draws_closes_it_once() {
for _ in 0..2 {
let mut input = RawInput::default();
input.viewports.insert(ViewportId::ROOT, ViewportInfo { events: vec![ViewportEvent::Close], occluded: Some(true), ..Default::default() });
let _ = ctx.run_logic(&input, |ctx| crate::windows::on_close_request(&mut app, ctx));
let _ = ctx.run_logic(&input, |ctx| app.close_path(ctx));
}
frame(&ctx, &mut app, false);
frame(&ctx, &mut app, false);
@@ -17,7 +17,7 @@ impl Frames {
fn new() -> Self {
let mut session = Session::new();
session.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 300, "height": 200})).unwrap();
let mut f = Frames { ctx: egui::Context::default(), app: FigApp::new(session, Box::new(NoServices)), time: 0.0 };
let mut f = Frames { ctx: figcraft_ui_egui::framework::headless_context(), app: FigApp::new(session, Box::new(NoServices)), time: 0.0 };
for _ in 0..3 {
f.frame(vec![]);
}
@@ -28,6 +28,7 @@ impl Frames {
self.time += 1.0 / 60.0;
let input =
RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1440.0, 900.0))), time: Some(self.time), events, ..Default::default() };
self.app.before_input(&self.ctx);
let mut output = self.ctx.run_ui(input, |ui| self.app.ui(ui));
output.textures_delta.clear();
}
@@ -4,6 +4,7 @@ use figcraft_ui_egui::{FigApp, NoServices, control};
use serde_json::json;
fn frame(ctx: &egui::Context, app: &mut FigApp, time: f64) {
app.before_input(ctx);
let mut out = ctx
.run_ui(RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1440.0, 900.0))), time: Some(time), ..Default::default() }, |ui| {
app.ui(ui)
@@ -18,7 +19,7 @@ fn comment_open_other_page() {
let second = session.execute("page.add", &json!({})).unwrap()["id"].as_u64().unwrap();
session.execute("page.select", &json!({"id": second})).unwrap();
let comment = session.execute("comment.add", &json!({"x": 50, "y": 50, "text": "Review this"})).unwrap()["id"].as_u64().unwrap();
let ctx = egui::Context::default();
let ctx = figcraft_ui_egui::framework::headless_context();
let mut app = FigApp::new(session, Box::new(NoServices));
for i in 1..=3 {
frame(&ctx, &mut app, i as f64 / 60.0);
+2 -1
View File
@@ -18,10 +18,11 @@ impl Services for SaveTo {
/// The menu item, then a frame: the save dialog answers asynchronously and the frame takes its answer.
fn invoke(app: &mut FigApp, id: &str) {
menus::invoke(app, id);
let ctx = egui::Context::default();
let ctx = figcraft_ui_egui::framework::headless_context();
for _ in 0..2 {
let input =
egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1440.0, 900.0))), ..Default::default() };
app.before_input(&ctx);
ctx.run_ui(input, |ui| app.ui(ui)).textures_delta.clear();
}
}
@@ -4,6 +4,7 @@ use figcraft_ui_egui::{FigApp, NoServices};
use serde_json::json;
fn frame(ctx: &egui::Context, app: &mut FigApp, size: Vec2) {
app.before_input(ctx);
let mut out = ctx.run_ui(RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, size)), ..Default::default() }, |ui| app.ui(ui));
out.textures_delta.clear();
}
@@ -15,7 +16,7 @@ fn scene(selected: bool, rulers: bool) -> (egui::Context, FigApp) {
if selected {
session.execute("guide.select", &json!({"index": 0})).unwrap();
}
let ctx = egui::Context::default();
let ctx = figcraft_ui_egui::framework::headless_context();
let mut app = FigApp::new(session, Box::new(NoServices));
frame(&ctx, &mut app, vec2(1440.0, 900.0));
frame(&ctx, &mut app, vec2(1440.0, 900.0));
+2 -1
View File
@@ -13,13 +13,14 @@ fn row(view: &str, path: &str, prefix: &str, exclude: &str) -> (String, Option<S
session.prefs.home_views.insert("recents".into(), view.into());
let mut app = FigApp::new(session, Box::new(NoServices));
app.ui.home = true;
let ctx = Context::default();
let ctx = figcraft_ui_egui::framework::headless_context();
ctx.enable_accesskit();
let mut found = None;
for frame in 0..4 {
if frame >= 2 {
ctx.memory_mut(|m| m.request_focus(Id::unique(("home_recent_file", path))));
}
app.before_input(&ctx);
let mut out = ctx.run_ui(
RawInput {
screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1440.0, 900.0))),
@@ -16,7 +16,7 @@ fn widths(language: &str) -> Vec<f32> {
// Truncating text also shows Max lines.
let text = s.execute("text.create", &json!({"text": "Type", "props": {"textAutoResize": "truncate"}})).unwrap()["id"].clone();
s.execute("select.set", &json!({"ids": [text]})).unwrap();
let ctx = egui::Context::default();
let ctx = figcraft_ui_egui::framework::headless_context();
let mut app = FigApp::new(s, Box::new(NoServices));
let open = Id::unique("ty_settings_open");
let mut widths = Vec::new();
@@ -26,6 +26,7 @@ fn widths(language: &str) -> Vec<f32> {
}
let raw =
RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1440.0, 900.0))), time: Some(i as f64 / 60.0), ..Default::default() };
app.before_input(&ctx);
ctx.run_ui(raw, |ui| app.ui(ui)).textures_delta.clear();
// From the frame after the one it opened on (egui's sizing pass).
if i > 3 {