Merge pull request #9272 from dotCooCoo/fix/test-frames-before-input-once

Tests: the frame helpers give the runtime its input once per frame
This commit is contained in:
BFlat authored and GitHub committed 2026-11-25 19:56:15 +07:00
commit 2a5dbc479f
10 files changed
+66 -35

No files matched your search

+21 -10
View File
@@ -40,20 +40,31 @@ fn settled(app: &mut VectorcraftApp, view: &CanvasView, ids: &[NodeId]) -> Vec<A
/// An unchanged type object keeps its memo entry; an edit lays out only the object edited; a zoom
/// reuses the entries (the marks are in document points); a new font generation lays everything out.
/// Other tests change the fonts while this one runs, so the edit and the zoom are tried again on a
/// new document until the fonts stay the same from the settled pass through the edited one to the
/// zoomed one.
#[test]
fn hidden_characters_lay_out_only_type_that_changed() {
let mut app = app();
let ids = [text(&mut app, 20, 40, "a b\nc d"), text(&mut app, 20, 160, "e f")];
app.ui.view.hidden_chars = true;
let before = settled(&mut app, &view(), &ids);
app.session.execute("text.setText", &json!({"id": ids[1].0, "text": "e f g"})).unwrap();
marks_of(&mut app, &view());
let after = kept_hidden(&app, &ids);
let zoomed = CanvasView::new(view().rect, Point::new(100.0, 100.0), 2.0);
let (mut app, ids, before, after, zoom) = (0..100)
.find_map(|_| {
let mut app = app();
let ids = [text(&mut app, 20, 40, "a b\nc d"), text(&mut app, 20, 160, "e f")];
app.ui.view.hidden_chars = true;
let before = settled(&mut app, &view(), &ids);
let inputs = app.canvas.hidden_chars.inputs.clone();
app.session.execute("text.setText", &json!({"id": ids[1].0, "text": "e f g"})).unwrap();
marks_of(&mut app, &view());
let edited = app.canvas.hidden_chars.inputs == inputs;
let after = kept_hidden(&app, &ids);
marks_of(&mut app, &zoomed);
let zoom = kept_hidden(&app, &ids);
(edited && app.canvas.hidden_chars.inputs == inputs).then_some((app, ids, before, after, zoom))
})
.expect("the fonts settle");
assert!(Arc::ptr_eq(&before[0], &after[0]), "the object not edited is not laid out again");
assert!(!Arc::ptr_eq(&before[1], &after[1]), "the edited object is");
let zoomed = CanvasView::new(view().rect, Point::new(100.0, 100.0), 2.0);
marks_of(&mut app, &zoomed);
assert!(kept_hidden(&app, &ids).iter().zip(&after).all(|(a, b)| Arc::ptr_eq(a, b)), "a zoom lays out no type");
assert!(zoom.iter().zip(&after).all(|(a, b)| Arc::ptr_eq(a, b)), "a zoom lays out no type");
app.canvas.hidden_chars.inputs = (u64::MAX, String::new());
marks_of(&mut app, &view());
assert!(kept_hidden(&app, &ids).iter().zip(&after).all(|(a, b)| !Arc::ptr_eq(a, b)), "other fonts lay all type out again");
+19
View File
@@ -2010,6 +2010,25 @@ mod tests {
out.textures_delta.clear();
}
/// Frames of the app with the dialog open ask for no rerun once its first frame has sized it: the commands of its
/// set row publish the state they had the frame before.
#[test]
fn an_open_dialog_asks_for_no_rerun_after_its_first_frame() {
let mut app = crate::testing::windowed(VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()));
let ctx = app.ui_ctx.clone().unwrap();
let raw =
|| egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1600.0, 1000.0))), ..Default::default() };
for _ in 0..3 {
crate::testing::app_frame(&mut app, &ctx, raw());
}
open(&mut app);
crate::testing::app_frame(&mut app, &ctx, raw());
for frame in 0..4 {
let out = crate::testing::app_frame(&mut app, &ctx, raw());
assert_eq!(out.platform_output.num_completed_passes, 1, "frame {frame} after the first is drawn again");
}
}
/// An open dialog lists a live-effect plug-in installed while it is open, with the shortcut its
/// set gives it, and drops the row while the plug-in is removed, keeping that shortcut in the
/// set.
+12 -4
View File
@@ -2,7 +2,7 @@
//! gives a real window, so a test lays text out and paints in the app's look; and the frame the
//! hosts run.
use craft::ui::runtime::frame::{FrameInput, set_input};
use craft::ui::runtime::frame::{FrameInput, set_input, take_output};
use craft::ui::shell::embed;
/// Installs the runtime with a window system that has no OS services, the app's interface fonts
@@ -36,8 +36,9 @@ pub(crate) fn ui_context() -> egui::Context {
/// One frame of the whole app on `ctx` as the hosts run it (kb.C26): the app has the window's context, as the hosts
/// hand it when they create the app, gives the input of the frame
/// (`embed::before_input`), the window draws with `raw`, and the app takes what the runtime gathered in it, running the
/// commands it fired, as the host's next frame begins. The frame's texture uploads are handled.
/// (`embed::before_input`, once, as the hosts call it), the window draws with `raw`, and the app takes what the runtime
/// gathered in it, running the commands it fired, as the host's next frame begins ([`run_fired`]). The frame's texture
/// uploads are handled.
pub(crate) fn app_frame(app: &mut crate::VectorcraftApp, ctx: &egui::Context, raw: egui::RawInput) -> egui::FullOutput {
part_frame(app, ctx, raw, |app, ui| {
app.tick(ui.ctx());
@@ -56,11 +57,18 @@ pub(crate) fn part_frame(
app.raw_input(ctx, &mut raw);
embed::before_input(ctx, |out| app.frame_input(out));
let mut out = ctx.run_ui(raw, |ui| draw(app, ui));
embed::before_input(ctx, |out| app.frame_input(out));
run_fired(app, ctx);
out.textures_delta.clear();
out
}
/// The app takes what the runtime gathered on `ctx` since the last frame began and runs the commands it fired, as the
/// host's next `embed::before_input` does, without giving the runtime its input: the next frame gives it. A second
/// input in one frame makes every command state the next frame publishes look changed, and the frame asks for a rerun.
pub(crate) fn run_fired(app: &mut crate::VectorcraftApp, ctx: &egui::Context) {
let _ = app.frame_input(take_output(ctx));
}
/// Held by a test that changes the custom dictionary, which the whole process shares, or that needs it to hold still:
/// every change moves the dictionary's generation, and a Check Spelling walk that sees it move checks its scope again
/// from the start.
+1 -1
View File
@@ -64,7 +64,7 @@ fn run_frame(
}
});
// The commands the frame fired run as the host's next frame begins (`testing::app_frame`).
craft::ui::shell::embed::before_input(ctx, |output| app.frame_input(output));
crate::testing::run_fired(app, ctx);
out.textures_delta.clear();
(passes, out.platform_output.ime)
}
+1 -4
View File
@@ -125,10 +125,7 @@ impl Mac {
screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1600.0, 850.0))),
..Default::default()
};
let app = &mut self.app;
craft::ui::shell::embed::before_input(&self.ctx, |out| app.frame_input(out));
crate::testing::app_frame(app, &self.ctx, raw)
crate::testing::app_frame(&mut self.app, &self.ctx, raw)
}
/// AppKit chose an item by its key equivalent `sc`. A paste the menu asks the host for
+4 -7
View File
@@ -48,14 +48,11 @@ pub(super) fn window(app: VectorcraftApp) -> Window {
/// commands the pass fired run as the next frame begins.
pub(super) fn app_step(h: &mut Window) {
let ctx = h.ctx.clone();
let input = |h: &mut Window| {
let app = h.state_mut();
app.adopt_context(&ctx);
craft::ui::shell::embed::before_input(&ctx, |out| app.frame_input(out));
};
input(h);
let app = h.state_mut();
app.adopt_context(&ctx);
craft::ui::shell::embed::before_input(&ctx, |out| app.frame_input(out));
h.step();
input(h);
crate::testing::run_fired(h.state_mut(), &ctx);
}
/// Draws a frame of `h` at `time` seconds.
+1 -5
View File
@@ -315,11 +315,7 @@ pub(super) fn frame(app: &mut VectorcraftApp, events: Vec<egui::Event>) -> egui:
static CTX: egui::Context = crate::testing::ui_context();
}
let ctx = CTX.with(Clone::clone);
craft::ui::shell::embed::before_input(&ctx, |output| app.frame_input(output));
let mut out = crate::testing::app_frame(app, &ctx, egui::RawInput { events, ..Default::default() });
craft::ui::shell::embed::before_input(&ctx, |output| app.frame_input(output));
out.textures_delta.clear();
out
crate::testing::app_frame(app, &ctx, egui::RawInput { events, ..Default::default() })
}
/// The paste egui sends for a clipboard with a picture and no text.
+2 -1
View File
@@ -4,6 +4,7 @@
use std::sync::{Mutex, MutexGuard};
use craft::ui::runtime::frame::take_output;
use craft::ui::shell::embed;
use egui::{Event, Rect, vec2};
use serde_json::json;
@@ -99,7 +100,7 @@ impl Frames {
},
|ui| chrome::control_bar(app, ui),
);
embed::before_input(&self.ctx, |out| app.frame_input(out));
let _ = app.frame_input(take_output(&self.ctx));
let nodes =
output.platform_output.accesskit_update.take().map(|update| update.nodes.into_iter().map(|(_, node)| node).collect()).unwrap_or_default();
output.textures_delta.clear();
+1 -1
View File
@@ -74,7 +74,7 @@ impl Scene {
// As the hosts run a frame: the app gives its input, and the commands the pass fired run as the next frame begins.
craft::ui::shell::embed::before_input(&self.ctx, |out| self.app.frame_input(out));
let mut out = self.ctx.run_ui(raw, |ui| self.app.ui(ui));
craft::ui::shell::embed::before_input(&self.ctx, |out| self.app.frame_input(out));
let _ = self.app.frame_input(craft::ui::runtime::frame::take_output(&self.ctx));
out.textures_delta.clear();
}
@@ -4,6 +4,7 @@
use std::sync::{Mutex, MutexGuard};
use craft::ui::runtime::frame::take_output;
use craft::ui::shell::embed;
use egui::{Event, Key, Modifiers};
use serde_json::json;
@@ -65,6 +66,7 @@ impl Keyboard {
fn frame(&mut self, app: &mut VectorcraftApp, events: Vec<Event>) {
self.time += 0.05;
app.adopt_context(&self.ctx);
embed::before_input(&self.ctx, |out| app.frame_input(out));
let mut out = self.ctx.run_ui(
egui::RawInput {
@@ -79,8 +81,8 @@ impl Keyboard {
app.ui(ui);
},
);
// The commands the pass fired run as the host's next frame begins.
embed::before_input(&self.ctx, |out| app.frame_input(out));
// The commands the pass fired run as the host's next frame begins; the next frame gives the input.
let _ = app.frame_input(take_output(&self.ctx));
out.textures_delta.clear();
}