mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 20:38:21 +00:00
Tests: the frame helpers give the runtime its input once per frame, as the apps do, and run the commands a pass fired without a second input, which made every command state of the next frame look changed and asked for a rerun
This commit is contained in:
@@ -1992,6 +1992,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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user