Compare commits

..
Author SHA1 Message Date
skylartaylor b81421cab6 nightly: a refused launch exits 2 on macOS instead of hanging
A refused launch profile printed its reason and then, on a macOS desktop
session, opened rfd's message box before eframe's event loop existed.
That alert needs the AppKit run loop this start never reaches, so the
process sat in an invisible modal and had to be killed instead of
exiting (GridCraft Mac smoke of run 45749038918: refused without `--`,
no window, killed with SIGTERM).

The refusal now adds the box only where one renders without the app's
event loop (Windows' MessageBox, GTK on X11/Wayland) and otherwise
leaves the reason on standard error, so the caller's exit(2) is
reached. The rule is a pure function with a unit test.
2026-11-26 05:18:14 +01:00
101 changed files with 880 additions and 2998 deletions
Generated
+103 -1400
View File
File diff suppressed because it is too large Load Diff
+31 -37
View File
@@ -12,17 +12,17 @@ repository = "https://github.com/storytold/deckcraft"
[workspace.dependencies]
# OPC part-name primitives and package reader/writer.
craft-opc = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "0.1.0" }
craft-opc = { git = "https://github.com/storytold/craft-libs", rev = "8048f8ef92da80fb3ce5a056d59ca591ee66faf1", version = "0.1.0" }
# Compound File Binary directory reads (password-protected deck detection).
craft-cfb = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "0.1.0" }
craft-cfb = { git = "https://github.com/storytold/craft-libs", rev = "8048f8ef92da80fb3ce5a056d59ca591ee66faf1", version = "0.1.0" }
# Bounded XML reader and writer primitives.
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "0.1.0" }
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "8048f8ef92da80fb3ce5a056d59ca591ee66faf1", version = "0.1.0" }
# DrawingML colours, themes, charts, tables and text (craft-libs#778, #792).
craft-drawingml = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "0.1.0" }
craft-drawingml = { git = "https://github.com/storytold/craft-libs", rev = "8048f8ef92da80fb3ce5a056d59ca591ee66faf1", version = "0.1.0" }
# PresentationML PPTX/POTX/PPSX reader and writer (craft-libs#778).
craft-pptx = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "0.1.0" }
craft-pptx = { git = "https://github.com/storytold/craft-libs", rev = "8048f8ef92da80fb3ce5a056d59ca591ee66faf1", version = "0.1.0" }
# Shared MCP stdio framing and protocol constants (craft-libs#778).
craft-mcp-server = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "0.1.0" }
craft-mcp-server = { git = "https://github.com/storytold/craft-libs", rev = "bc186ca719958fcce3b6ee24794277eabed14609", version = "0.1.0" }
# internal
deckcraft-geom = { path = "crates/geom" }
deckcraft-color = { path = "crates/color" }
@@ -62,27 +62,21 @@ vello_cpu = "0.2"
vello_common = { version = "0.2", default-features = false }
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "webp", "gif", "tiff", "bmp"] }
# Base64 for command payloads (engine); base64_compat keeps the legacy lenient decoder. Same rev as craft-deckcraft-format.
craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "=0.1.0" }
craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "254e9a409b410dc93c0e06ff66cd1e767893ac32", version = "=0.1.0" }
# craft-media, craft-audio and craft-video share types and stay on one rev.
# The .deckcraft package layer (identity, manifest, member names, bounded reads); crates/format maps the presentation onto it.
craft-deckcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "=0.1.0" }
craft-rtf = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "=0.1.0" }
craft-media = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "=0.1.0", default-features = false }
craft-audio = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "=0.1.0", default-features = false, features = ["opus-decode"] }
craft-deckcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "254e9a409b410dc93c0e06ff66cd1e767893ac32", version = "=0.1.0" }
craft-rtf = { git = "https://github.com/storytold/craft-libs", rev = "d0193d7e94b5ec180ecc2a152ea72047d39ac632", version = "=0.1.0" }
craft-media = { git = "https://github.com/storytold/craft-libs", rev = "010702ee9b030844c852939095b1da0d0656a890", version = "=0.1.0", default-features = false }
craft-audio = { git = "https://github.com/storytold/craft-libs", rev = "010702ee9b030844c852939095b1da0d0656a890", version = "=0.1.0", default-features = false, features = ["opus-decode"] }
# H.264, HEVC, VP9 and AV1 decoders.
craft-video = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "=0.1.0", default-features = false, features = ["h264-decode", "hevc-decode", "vp9-decode", "av1-decode", "threads"] }
craft-video = { git = "https://github.com/storytold/craft-libs", rev = "010702ee9b030844c852939095b1da0d0656a890", version = "=0.1.0", default-features = false, features = ["h264-decode", "hevc-decode", "vp9-decode", "av1-decode", "threads"] }
# WMF, EMF and EMF+ reader.
craft-metafile = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "=0.1.0" }
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "=0.1.0", default-features = false, features = ["write", "write-simple-text"] }
craft-metafile = { git = "https://github.com/storytold/craft-libs", rev = "f428c3d36e0faf3924b76956a01334c051543527", version = "=0.1.0" }
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "63196e66f3033a6623eb629af95a104d26986725", version = "=0.1.0", default-features = false, features = ["write", "write-simple-text"] }
# craft-update: app-specific pretend versions apply to startup and manual checks.
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", features = ["ui"] }
craft-ui = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "=0.1.0" }
# The framework runtime's host: the app's identity, its window services, its key overrides and the theme mode
# the framework's components draw in.
craft-host = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "=0.1.0" }
craft-keymap = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "=0.1.0" }
craft-theme = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "=0.1.0" }
craft-window = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "=0.1.0" }
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "63196e66f3033a6623eb629af95a104d26986725", features = ["egui"] }
craft-ui = { git = "https://github.com/storytold/craft-libs", rev = "63196e66f3033a6623eb629af95a104d26986725", version = "=0.1.0" }
i_overlay = "9"
quick-xml = "0.41"
zip = { version = "3", default-features = false, features = ["deflate"] }
@@ -129,19 +123,19 @@ codegen-units = 16
debug = 0
[patch.crates-io]
krilla = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "=0.8.2" }
ecolor = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
emath = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
epaint = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
egui = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
egui-winit = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
egui_glow = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
egui_extras = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
egui_system_font_provider = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
eframe = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
egui_demo_lib = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
egui_inspection = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
krilla = { git = "https://github.com/storytold/craft-libs", rev = "63196e66f3033a6623eb629af95a104d26986725", version = "=0.8.2" }
ecolor = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
emath = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
epaint = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
egui = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
egui-winit = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
egui_glow = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
egui_extras = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
egui_system_font_provider = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
eframe = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
egui_demo_lib = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
egui_inspection = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
winit = { git = "https://github.com/storytold/winit.git", rev = "a517b3846ee8457d84ee4975110bfda6797c44dc" }
+2 -2
View File
@@ -17,9 +17,9 @@ path = "src/main.rs"
deckcraft-engine = { workspace = true }
deckcraft-ui-egui = { workspace = true }
# The page command API (storytold/craft-libs#413): window.deckcraft over the control channel.
craft-web-api = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "0.1.0" }
craft-web-api = { git = "https://github.com/storytold/craft-libs", rev = "fd5e2feff6ea25bed371a99cc732b3968d621505", version = "0.1.0" }
# The host messages (storytold/craft-libs): one contract and one bridge for the web builds.
craft-web-host = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "0.1.0" }
craft-web-host = { git = "https://github.com/storytold/craft-libs", rev = "fd5e2feff6ea25bed371a99cc732b3968d621505", version = "0.1.0" }
egui = { workspace = true }
log = { workspace = true }
serde_json = { workspace = true }
-5
View File
@@ -49,13 +49,10 @@ pub fn start() {
log::info!("deckcraft-web {}: wgpu backend {:?}", env!("CARGO_PKG_VERSION"), rs.adapter.get_info().backend);
}
deckcraft_ui_egui::install_ime_pass_hooks(&cc.egui_ctx);
// The presenter popup draws DeckCraft's presenter view only, with no framework component, so
// it runs without the framework runtime.
if let Some(token) = crate::presenter::token() {
let presenter = crate::presenter::Popup::new(token, cc.egui_ctx.clone()).map_err(std::io::Error::other)?;
return Ok(Box::new(presenter) as Box<dyn eframe::App>);
}
deckcraft_ui_egui::framework::install_headless(&cc.egui_ctx);
let inbox: Inbox = Inbox::default();
let mut services = services(inbox.clone(), cc.egui_ctx.clone());
if let Some(bridge) = &app_bridge {
@@ -134,7 +131,6 @@ impl eframe::App for WebShell {
bridge.open_files(&mut self.app);
}
self.app.logic(ctx);
self.app.close_path(ctx);
if let Some(bridge) = &self.bridge {
bridge.report_dirty(&self.app);
}
@@ -170,7 +166,6 @@ impl eframe::App for WebShell {
});
}
self.app.raw_input_hook(ctx, raw);
self.app.before_input(ctx);
}
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
+25 -10
View File
@@ -49,16 +49,12 @@ impl eframe::App for App {
#[cfg(target_os = "macos")]
apple_events::poll(&self.1, &mut self.0, ctx);
self.0.logic(ctx);
self.0.close_path(ctx);
}
/// Forward native raw input to the wrapped application once per frame, then hand the framework
/// runtime this frame's root values.
/// Forward native raw input to the wrapped application once per pass.
fn raw_input_hook(&mut self, ctx: &egui::Context, raw: &mut egui::RawInput) {
self.0.raw_input_hook(ctx, raw);
self.0.before_input(ctx);
}
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
deckcraft_ui_egui::framework::before_ui(ui.ctx(), &*frame);
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
self.0.ui(ui);
}
fn on_exit(&mut self) {
@@ -257,12 +253,20 @@ fn initialize_nightly_process_identity() -> Result<(), process_identity::Identit
)
}
/// Whether a refusal may also open a native message box. Standard error always carries the reason;
/// this only adds a box where one renders without the app's event loop. Never on macOS: rfd's alert
/// there needs the AppKit run loop this start has not reached, so a refused nightly launch hung in
/// an invisible modal instead of exiting (GridCraft Mac smoke, 2026-11-26).
fn refusal_dialog(flavor: build_flavor::BuildFlavor, desktop_session: bool, macos: bool) -> bool {
build_flavor::needs_native_error(flavor, desktop_session) && !macos
}
fn report_launch_profile_error(error: &str) {
eprintln!("DeckCraft launch profile: {error}");
let desktop_session = cfg!(windows)
|| cfg!(target_os = "macos")
|| (cfg!(target_os = "linux") && ["DISPLAY", "WAYLAND_DISPLAY"].into_iter().any(|key| std::env::var_os(key).is_some_and(|v| !v.is_empty())));
if build_flavor::needs_native_error(build_flavor::COMPILED, desktop_session) {
if refusal_dialog(build_flavor::COMPILED, desktop_session, cfg!(target_os = "macos")) {
if let Err(error) = initialize_nightly_process_identity() {
eprintln!("DeckCraft launch profile: {error}");
return;
@@ -365,8 +369,6 @@ fn main() -> eframe::Result {
}
};
// `Default` lets winit choose, and winit takes Wayland whenever `WAYLAND_DISPLAY` is set.
#[cfg(not(all(unix, not(target_os = "macos"))))]
let x11 = false;
#[cfg(all(unix, not(target_os = "macos")))]
let native_wayland = !x11 && std::env::var_os("WAYLAND_DISPLAY").is_some_and(|w| !w.is_empty());
#[cfg(not(all(unix, not(target_os = "macos"))))]
@@ -397,7 +399,6 @@ fn main() -> eframe::Result {
deckcraft_ui_egui::os_window::name_for(deckcraft_ui_egui::os_window::identity()),
options,
Box::new(move |cc| {
deckcraft_ui_egui::framework::install(&cc.egui_ctx, x11)?;
deckcraft_ui_egui::install_ime_pass_hooks(&cc.egui_ctx);
let mut app = SlideApp::new(Session::new(), services);
// Presenter View asks winit how many displays there are when a show starts.
@@ -679,3 +680,17 @@ mod tests {
assert!(script.contains("has no embedded icon"), "package.ps1 does not reject an iconless exe");
}
}
#[cfg(test)]
mod refusal_dialog_tests {
use super::refusal_dialog;
use crate::build_flavor::BuildFlavor;
#[test]
fn a_refusal_never_blocks_on_a_modal_before_the_event_loop_on_macos() {
assert!(refusal_dialog(BuildFlavor::NightlyV1, true, false), "a desktop refusal still shows the box where one renders");
assert!(!refusal_dialog(BuildFlavor::NightlyV1, true, true), "macOS has no run loop yet: the modal would hang");
assert!(!refusal_dialog(BuildFlavor::NightlyV1, false, false), "a headless session has no box");
assert!(!refusal_dialog(BuildFlavor::Stable, true, false), "only a nightly refusal explains itself in a box");
}
}
+3
View File
@@ -2,4 +2,7 @@ allow-unwrap-in-tests = true
allow-expect-in-tests = true
allow-panic-in-tests = true
allow-indexing-slicing-in-tests = true
disallowed-types = [
{ path = "egui::ComboBox", reason = "use craft_ui::ComboBox: egui's combo box menu can't grow back while open (egui#5225)" },
]
cognitive-complexity-threshold = 30
-8
View File
@@ -293,14 +293,6 @@ impl Session {
Ok(true)
}
/// Whether Tab has something to do here: text is being edited (it indents, types a tab or goes to the next table
/// cell), or the slide has an object after the selected one. Past the last object it has nothing left to select.
pub fn tab_has_work(&self) -> bool {
let Some(st) = self.active() else { return false };
let last = st.shapes().iter().rev().find(|s| !s.hidden).map(|s| s.id);
st.selection.text.is_some() || (last.is_some() && st.selection.shapes.first().copied() != last)
}
fn cycle_selection(&mut self, forward: bool) -> Result<()> {
let st = self.doc()?;
let ids: Vec<_> = st.shapes().iter().filter(|s| !s.hidden).map(|s| s.id).collect();
+2 -3
View File
@@ -1181,8 +1181,7 @@ mod tests {
c.y_format = Some(r#"_-* #\ ##0\ "₽"_-;\-* #\ ##0\ "₽"_-;_-* "-"??\ "₽"_-;_-@_-"#.into());
c.lang = Some("ru-RU".into());
assert_eq!(c.axis_label(false, 800_000.0), "800\u{a0}000 ₽");
// Excel shows each `?` of the zero section as a space.
assert_eq!(c.axis_label(false, 0.0), "- ₽");
assert_eq!(c.axis_label(false, 0.0), "- ₽");
// No format: General.
assert_eq!(c.axis_label(true, 2.5), "2,5");
c.lang = None;
@@ -1191,7 +1190,7 @@ mod tests {
c.lang = Some("ru-RU".into());
c.series[0].number_format = Some(r#"#,##0\ "₽""#.into());
assert_eq!(c.data_label(&c.series[0], 516_600_000.0), "516\u{a0}600\u{a0}000 ₽");
assert_eq!(c.data_label(&c.series[1], 0.0), "- ₽");
assert_eq!(c.data_label(&c.series[1], 0.0), "- ₽");
}
#[test]
-3
View File
@@ -1298,9 +1298,6 @@ fn chart_to(c: &dm_chart::Chart) -> cd_chart::Chart {
gridlines: c.gridlines,
minor_gridlines: c.minor_gridlines,
axis_titles: c.axis_titles.clone(),
// DeckCraft's chart model keeps the raw category labels and the 1900 date system.
category_format: None,
date_1904: false,
style: c.style,
palette: c.palette.clone(),
plot_fill: c.plot_fill.as_ref().map(fill_to),
-4
View File
@@ -21,10 +21,6 @@ deckcraft-media = { workspace = true }
egui = { workspace = true, features = ["default_fonts", "monochrome_emoji_fonts"] }
egui_extras = { workspace = true }
craft-ui = { workspace = true }
craft-host = { workspace = true }
craft-keymap = { workspace = true }
craft-theme = { workspace = true }
craft-window = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
log = { workspace = true }
+7 -11
View File
@@ -21,17 +21,13 @@ fn harness() -> Harness<'static, SlideApp> {
}
let mut app = SlideApp::new(s, Services::default());
app.ui.pane = Some("animation".into());
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1400.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
h
}
+8 -8
View File
@@ -13,7 +13,6 @@ use super::{
mod clipboard;
mod commands;
mod control;
mod document_focus;
pub(crate) mod files;
mod frame;
mod ime;
@@ -23,7 +22,6 @@ mod playback;
#[cfg(test)]
pub(crate) use clipboard::{OBJECTS_MARKER, system_clipboard_text};
pub(crate) use document_focus::DocumentFocus;
#[cfg(test)]
pub(crate) use files::web_image_files;
pub use keys::key_name;
@@ -71,7 +69,6 @@ impl SlideApp {
synthetic_generation: 0,
synthetic_target: None,
synthetic_focus: None,
document_focus: DocumentFocus::default(),
synthetic_injected_time: None,
ribbon_scroll: HashMap::new(),
show_instance: 0,
@@ -89,8 +86,6 @@ impl SlideApp {
print_previews: files::PrintPreviews::default(),
#[cfg(not(target_arch = "wasm32"))]
updates_rt: updates_ui::Runtime::default(),
framework_dialogs: craft_ui::dialog::DialogHost::new(),
framework_host: crate::framework::host(),
pending_copy: None,
capture: capture::Capture::default(),
styled: false,
@@ -252,6 +247,14 @@ impl SlideApp {
if !self.synthetic.is_empty() || !self.synthetic_next.is_empty() || self.synthetic_pending {
ctx.request_repaint();
}
// Closing the window with unsaved changes asks first.
if ctx.input(|i| i.viewport().close_requested()) && !self.quit_confirmed && self.session.documents().iter().any(|d| d.is_dirty()) {
ctx.send_viewport_cmd(egui::ViewportCommand::CancelClose);
self.show = None;
if self.dialog.as_ref().is_none_or(|d| d.id != "quit") {
self.dialog = Some(dialogs::Dialog::new("quit"));
}
}
self.autosave_if_due(ctx);
self.tick_media_clock(ctx);
self.note_settled_composition(ctx);
@@ -290,7 +293,6 @@ impl SlideApp {
let ctx = ui.ctx().clone();
self.ime_frame_viewport = Some(ctx.viewport_id());
self.ime_pending = None;
let document_before = self.document_focus.drawn.take();
if !self.ui_setup(&ctx) {
// This pass is discarded for the new fonts. The input events were already consumed
// by egui, so keep them queued for the next frame instead of silently losing them.
@@ -354,13 +356,11 @@ impl SlideApp {
}
}
});
self.finish_document(&ctx, document_before);
toast::note_missing_fonts(self);
toast::show(self, &ctx);
dialogs::show(self, &ctx);
#[cfg(not(target_arch = "wasm32"))]
updates_ui::show(self, &ctx);
self.framework_dialogs.run(ui);
menus::palette(self, &ctx);
for url in std::mem::take(&mut self.pending_urls) {
ctx.open_url(egui::OpenUrl::new_tab(url));
-125
View File
@@ -1,125 +0,0 @@
//! The document window (the slide canvas, the slide sorter or the notes page) as the window's one document canvas: its
//! widget, its Tab stop and when it takes the keyboard focus.
use craft_ui::runtime::overlay::{self, OpenFilter};
use super::{SlideApp, ViewMode};
use crate::framework::{document_id, focus_document, focused_widget, host_canvas};
/// How many passes the document asks for the focus: egui names the widget of a closed palette, dialog or menu as
/// focused for one pass after it was last drawn.
const ASKING_PASSES: u8 = 2;
/// What the document window's focus depends on from pass to pass.
#[derive(Default)]
pub(crate) struct DocumentFocus {
/// The presentation (its uid) whose document window the pass drew; `None` on the start screen, the File tab and in
/// a slide show.
pub(super) drawn: Option<u64>,
/// The passes left in which a presentation that opened or became active asks for the focus.
opened: u8,
/// The passes left in which the document asks for the focus after a dialog, menu or popup closed.
uncovered: u8,
}
impl SlideApp {
/// Draws the document window's widget over `rect` and declares it as the window's canvas. A press in it gives it
/// the focus, unless a dialog is open. Real presses only: with the document focused, egui makes Enter and Space
/// clicks of it.
pub(crate) fn document_widget(&mut self, ui: &egui::Ui, rect: egui::Rect, sense: egui::Sense) -> egui::Response {
let resp = ui.interact(rect, document_id(), sense);
self.document_focus.drawn = self.session.active().map(|d| d.uid);
host_canvas(ui.ctx(), self.document_keeps_tab(ui.ctx()));
if resp.is_pointer_button_down_on() && ui.input(|i| i.pointer.any_pressed()) && !self.dialog_open(ui.ctx()) {
focus_document(ui.ctx());
}
resp
}
/// [`Self::document_widget`] behind widgets that take the presses (the slide sorter's thumbnails): a press on any of
/// them gives the document the focus, unless a text field has it.
pub(crate) fn document_behind(&mut self, ui: &egui::Ui, rect: egui::Rect) {
self.document_widget(ui, rect, egui::Sense::focusable_noninteractive());
let pressed = ui.input(|i| i.pointer.any_pressed()) && ui.rect_contains_pointer(rect);
if pressed && !ui.ctx().text_edit_focused() && !self.overlay_open(ui.ctx()) {
focus_document(ui.ctx());
}
}
/// Whether the document window is the slide being edited, where Tab can have work.
fn editing_slide(&self) -> bool {
self.backstage.is_none() && matches!(self.ui.view, ViewMode::Normal | ViewMode::Outline | ViewMode::Reading)
}
/// Whether the focused document keeps Tab: on the slide, while the session has something for it to do. A modal
/// dialog, a menu or a popup that is up gets it instead.
fn document_keeps_tab(&self, ctx: &egui::Context) -> bool {
self.editing_slide() && self.session.tab_has_work() && !self.overlay_open(ctx)
}
/// Whether a dialog, DeckCraft's or a modal one of the framework's, the palette or the opening overlay is up.
fn dialog_open(&self, ctx: &egui::Context) -> bool {
self.dialog.as_ref().is_some_and(|d| d.modal())
|| self.palette.is_some()
|| self.opening.is_some()
|| overlay::any_open(ctx, OpenFilter::Modal)
}
/// Whether a dialog ([`Self::dialog_open`]), or an egui menu or popup, is up.
fn overlay_open(&self, ctx: &egui::Context) -> bool {
self.dialog_open(ctx) || ctx.any_popup_open() || egui::Popup::is_any_open(ctx)
}
/// Whether the document may take the focus: no text field and no widget of another layer (the framework's update
/// notice) has it.
fn focus_is_free(ctx: &egui::Context) -> bool {
let layer = |id| ctx.read_response(id).map(|widget| widget.layer_id);
!ctx.text_edit_focused() && focused_widget(ctx).is_none_or(|id| layer(id) == layer(document_id()))
}
/// Ends the document window's pass, after the views; `before` is the presentation the last pass drew. The pass's
/// input has changed what Tab has to do, so the document is declared again. A presentation that opened or became
/// active asks for the focus. So does the document with nothing focused, when a dialog, menu or popup has closed, and
/// while Tab has work on the slide (a ribbon field committed with Enter leaves nothing focused). All wait for the
/// last dialog, menu or popup to close.
pub(super) fn finish_document(&mut self, ctx: &egui::Context, before: Option<u64>) {
let drawn = self.document_focus.drawn;
if drawn.is_none() {
self.document_focus.opened = 0;
self.document_focus.uncovered = 0;
return;
}
let keeps_tab = self.document_keeps_tab(ctx);
host_canvas(ctx, keeps_tab);
if drawn != before {
self.document_focus.opened = ASKING_PASSES;
}
if self.overlay_open(ctx) {
self.document_focus.uncovered = ASKING_PASSES;
return;
}
let unfocused = ctx.memory(|m| m.focused().is_none());
let DocumentFocus { opened, uncovered, .. } = &mut self.document_focus;
if *opened == 0 && *uncovered == 0 && !(unfocused && keeps_tab) {
return;
}
if unfocused || (*opened > 0 && Self::focus_is_free(ctx)) {
(*opened, *uncovered) = (0, 0);
focus_document(ctx);
} else {
(*opened, *uncovered) = (opened.saturating_sub(1), uncovered.saturating_sub(1));
ctx.request_repaint();
}
}
/// While slide text is being edited, the text owns the keyboard (#93). The focus on an ordinary widget (the ribbon
/// button whose Space inserted the text box) would swallow every later key and end text entry, and with nothing
/// focused (a ribbon field committed with Enter) Tab would leave the text. The document takes the focus; a text
/// field or an open menu keeps its keys.
pub(super) fn edited_text_takes_focus(&self, ctx: &egui::Context) {
let editing = self.editing_slide() && self.session.active().is_some_and(|d| d.selection.text.is_some());
if editing && !ctx.memory(|m| m.has_focus(document_id())) && !self.overlay_open(ctx) && Self::focus_is_free(ctx) {
focus_document(ctx);
}
}
}
+1 -1
View File
@@ -145,7 +145,7 @@ impl SlideApp {
&& ctx.input(|i| i.viewport().focused.unwrap_or(true))
&& ctx.input(|i| i.viewport().visible() != Some(false))
&& !ctx.input(|i| i.viewport().close_requested())
&& !crate::framework::widget_has_keyboard(ctx)
&& ctx.memory(|m| m.focused().is_none())
&& self.dialog.as_ref().is_none_or(|d| !d.modal())
&& self.palette.is_none()
&& self.backstage.is_none()
+2 -2
View File
@@ -140,7 +140,7 @@ impl SlideApp {
return;
}
let current = self.input_target();
let focus = crate::framework::focused_widget(ctx);
let focus = ctx.memory(|m| m.focused());
if self.synthetic_target == Some(current) && focus == self.synthetic_focus {
return;
}
@@ -210,7 +210,7 @@ impl SlideApp {
Err(e) => self.set_status(e),
}
}
let focus = crate::framework::focused_widget(ctx);
let focus = ctx.memory(|m| m.focused());
if self.synthetic_pending {
let current = self.input_target();
if self.synthetic_target != Some(current) || focus != self.synthetic_focus {
+22 -9
View File
@@ -1,6 +1,5 @@
use super::clipboard::OBJECTS_MARKER;
use super::{Mods, SlideApp, Value, backstage, json, menus};
use crate::framework::widget_has_keyboard;
impl SlideApp {
/// The app shortcuts that still make sense on the empty File/start screen: create, open,
@@ -48,12 +47,9 @@ impl SlideApp {
}
}
/// Keyboard and clipboard for the slide (with nothing or the document window focused).
/// Keyboard and clipboard for the slide (when no text field has focus).
pub(super) fn keyboard(&mut self, ctx: &egui::Context) {
let mut events = ctx.input(|i| i.events.clone());
if crate::framework::window_escape(ctx) {
events.push(crate::framework::ESCAPE_PRESS);
}
let events = ctx.input(|i| i.events.clone());
// Ctrl+V with only an image on the clipboard: egui-winit sends no Paste event and swallows the
// key press, so the release of a V press never seen is the paste. Tracked even while a text
// field has focus, so that a V typed there is not taken for one.
@@ -80,15 +76,26 @@ impl SlideApp {
// File-tab navigation and document-free shortcuts remain available.
self.suspend_ime_reset(viewport);
self.route_ime_controls_only(ctx, &events);
if self.palette.is_none() && self.dialog.as_ref().is_none_or(|d| !d.modal()) && !widget_has_keyboard(ctx) {
if self.palette.is_none() && self.dialog.as_ref().is_none_or(|d| !d.modal()) && ctx.memory(|m| m.focused().is_none()) {
self.route_backstage_keys(events);
}
self.drain_requests();
return;
}
let modal = self.dialog.as_ref().is_some_and(|d| d.modal()) || self.palette.is_some();
self.edited_text_takes_focus(ctx);
if widget_has_keyboard(ctx) || modal {
// While slide text is being edited, the text owns the keyboard (#93). Tab and the arrow
// keys move egui's keyboard focus onto ordinary widgets (the window's drag handle, ribbon
// buttons), and that stray focus would swallow every later key and end text entry. Let it
// go; a real text field or an open menu keeps its keys.
if !modal
&& self.session.active().is_some_and(|d| d.selection.text.is_some())
&& !ctx.text_edit_focused()
&& !ctx.any_popup_open()
&& let Some(id) = ctx.memory(|m| m.focused())
{
ctx.memory_mut(|m| m.surrender_focus(id));
}
if ctx.memory(|m| m.focused().is_some()) || modal {
// A stock field/modal/palette owns input now. Retire the custom fence, then visit
// controls in raw order; stock text/key events are left for the stock widgets.
self.suspend_ime_reset(viewport);
@@ -170,6 +177,12 @@ impl SlideApp {
}
}
egui::Event::Key { key, pressed: true, modifiers, .. } => {
if key == egui::Key::Tab {
// The slide has the keyboard, so Tab is ours (indent, tab character, next
// shape). Left to egui it would also focus the first ribbon widget, and
// every key after it would go there instead of the slide (#78).
ctx.memory_mut(|m| m.move_focus(egui::FocusDirection::None));
}
if key == egui::Key::Escape && self.anim_preview.is_some() && !modifiers.command && !modifiers.ctrl && !modifiers.alt {
self.anim_preview = None;
continue;
+2 -2
View File
@@ -156,7 +156,7 @@ pub(super) fn save_as(app: &mut SlideApp, ui: &mut Ui, bs: &mut Backstage, out:
ui.add_space(14.0);
let current = SAVE_TYPES.iter().find(|s| s.0 == bs.file_type).map_or(SAVE_TYPES[0].1, |s| s.1);
ui.horizontal(|ui| {
egui::ComboBox::from_id_salt("backstage_save_type")
craft_ui::ComboBox::from_id_salt("backstage_save_type")
.width(340.0)
// Every type in view: at the default height the last ones were behind a scroll.
.height(f32::INFINITY)
@@ -234,7 +234,7 @@ pub(super) fn about(app: &mut SlideApp, ui: &mut Ui) {
ui.set_width(340.0);
heading(ui, "Appearance");
let dark = app.ui.brightness == theme::Brightness::Dark;
egui::ComboBox::from_id_salt("backstage_appearance")
craft_ui::ComboBox::from_id_salt("backstage_appearance")
.width(260.0)
.selected_text(if dark { "Dark" } else { "Light" })
.show_ui(ui, |ui| {
+5 -5
View File
@@ -96,7 +96,7 @@ pub(super) fn print(app: &mut SlideApp, ui: &mut Ui, bs: &mut Backstage) {
PrintScope::Current => "Print Current Slide",
PrintScope::Custom => "Custom Range",
};
let combo = egui::ComboBox::from_id_salt("backstage_print_scope").width(240.0).selected_text(scope).show_ui(ui, |ui| {
let combo = craft_ui::ComboBox::from_id_salt("backstage_print_scope").width(240.0).selected_text(scope).show_ui(ui, |ui| {
for (s, label) in
[(PrintScope::All, "Print All Slides"), (PrintScope::Current, "Print Current Slide"), (PrintScope::Custom, "Custom Range")]
{
@@ -119,7 +119,7 @@ pub(super) fn print(app: &mut SlideApp, ui: &mut Ui, bs: &mut Backstage) {
});
ui.add_space(4.0);
let layout = LAYOUTS.iter().find(|l| l.0 == bs.print_layout).map_or("Full Page Slides", |l| l.1);
let combo = egui::ComboBox::from_id_salt("backstage_print_layout").width(240.0).selected_text(layout).show_ui(ui, |ui| {
let combo = craft_ui::ComboBox::from_id_salt("backstage_print_layout").width(240.0).selected_text(layout).show_ui(ui, |ui| {
for (id, label) in LAYOUTS {
if ui.selectable_label(bs.print_layout == id, label).clicked() {
bs.print_layout = id;
@@ -133,7 +133,7 @@ pub(super) fn print(app: &mut SlideApp, ui: &mut Ui, bs: &mut Backstage) {
// for notes pages and handouts.
ui.add_enabled_ui(bs.print_layout != "slides", |ui| {
let paper = deckcraft_engine::cmd::file::PAPERS.iter().find(|p| p.0 == bs.print_paper).map_or("Letter", |p| p.1);
egui::ComboBox::from_id_salt("backstage_print_paper")
craft_ui::ComboBox::from_id_salt("backstage_print_paper")
.width(240.0)
.selected_text(paper)
.show_ui(ui, |ui| {
@@ -147,7 +147,7 @@ pub(super) fn print(app: &mut SlideApp, ui: &mut Ui, bs: &mut Backstage) {
.widget_info(|| egui::WidgetInfo::labeled(egui::Role::ComboBox, true, "Paper size"));
ui.add_space(4.0);
let orient = if bs.print_landscape { "Landscape Orientation" } else { "Portrait Orientation" };
egui::ComboBox::from_id_salt("backstage_print_orientation")
craft_ui::ComboBox::from_id_salt("backstage_print_orientation")
.width(240.0)
.selected_text(orient)
.show_ui(ui, |ui| {
@@ -321,7 +321,7 @@ pub(super) fn export(app: &mut SlideApp, ui: &mut Ui, bs: &mut Backstage) {
ExportTask::Handouts => {
ui.label(RichText::new("Create Handouts").font(theme::font(16.0)).color(t.text));
bullets(ui, &["Several slides on each page of a PDF", "Three a page leaves lines for notes", "Print them for your audience"]);
let combo = egui::ComboBox::from_id_salt("backstage_handouts")
let combo = craft_ui::ComboBox::from_id_salt("backstage_handouts")
.width(240.0)
.selected_text(format!("{} slides per page", bs.handouts_per_page))
.show_ui(ui, |ui| {
+3 -3
View File
@@ -16,7 +16,7 @@ use crate::backstage::{Backstage, NAV_W, Nav, Page, PrintScope, entries, format_
use crate::{Services, SlideApp};
fn harness(app: SlideApp) -> Harness<'static, SlideApp> {
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
@@ -184,7 +184,7 @@ fn every_page_renders() {
/// In a window narrower than the page's maximum width the New tiles stay inside the right margin (#1421).
#[test]
fn new_tiles_keep_the_right_margin_in_a_narrow_window() {
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1000.0, 900.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1000.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
@@ -847,7 +847,7 @@ fn about_has_product_links_and_credits_without_account_controls() {
/// At the 900-point minimum window width the About columns stack and Appearance stays on the page.
#[test]
fn about_appearance_stays_on_the_page_at_minimum_width() {
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(900.0, 900.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(900.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
+7 -11
View File
@@ -33,17 +33,13 @@ fn browse_button_applies_the_picked_files_theme() {
s.execute("slide.new", &json!({"layout": "title", "title": "Hello"})).unwrap();
let mut app = SlideApp::new(s, services);
app.ui.tab = "Design".into();
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1600.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
h.get_by_label("Browse for Themes…").click();
h.run_steps(3);
+3 -6
View File
@@ -112,11 +112,9 @@ fn wheel_navigation(app: &mut SlideApp, ui: &mut Ui, carry_id: egui::Id, doc_uid
}
fn empty_deck_prompt(app: &mut SlideApp, ui: &mut Ui, avail: Rect, t: &Tokens) {
ui.advance_cursor_after_rect(avail);
let resp = app.document_widget(ui, avail, Sense::click());
let resp = ui.allocate_rect(avail, Sense::click());
ui.painter().text(avail.center(), Align2::CENTER_CENTER, "Click to add first slide", theme::font(22.0), t.text_dim);
// Enter on the focused document is the session's New Slide, not a click of the prompt.
if resp.clicked_by(egui::PointerButton::Primary) || ui.input(|i| i.has_accesskit_action_request(resp.id, egui::accesskit::Action::Click)) {
if resp.clicked() {
let _ = app.run("slide.new", json!({"layout": "title"}));
}
}
@@ -174,8 +172,7 @@ pub fn show(app: &mut SlideApp, ui: &mut Ui) {
let last_id = scroll_id.with("last");
let mut offset: egui::Vec2 = ui.data_mut(|d| d.get_temp(scroll_id).unwrap_or_default());
let last: Option<(Rect, f32)> = ui.data_mut(|d| d.get_temp(last_id));
ui.advance_cursor_after_rect(avail);
let resp = app.document_widget(ui, avail, Sense::click_and_drag());
let resp = ui.allocate_rect(avail, Sense::click_and_drag());
let (wheel, zoom_delta, hover) = ui.input(|i| (i.smooth_scroll_delta, i.zoom_delta(), i.pointer.hover_pos()));
let zooming = resp.hovered() && (zoom_delta - 1.0).abs() > 1e-3;
if zooming {
+1 -3
View File
@@ -7,9 +7,7 @@ pub(super) fn context_menu(app: &mut SlideApp, resp: &egui::Response) {
{
app.session.tool.edit_vertex = Some((path, index));
}
// Real clicks only: with the canvas focused, egui's own context menu would close on Enter and Space.
let open = if resp.secondary_clicked() { Some(true) } else { resp.clicked_by(egui::PointerButton::Primary).then_some(false) };
egui::Popup::context_menu(resp).open_memory(open.map(egui::SetOpenCommand::Bool)).show(|ui| {
resp.context_menu(|ui| {
let editing = app.session.active().and_then(|d| app.session.tool.editing_points(d).and_then(|id| d.shape(id).cloned()));
if let Some(sh) = editing {
edit_points_menu(app, ui, &sh);
+7 -11
View File
@@ -14,17 +14,13 @@ fn turn_guides_on_drag_one_and_drop_it_off_the_slide() {
let mut s = Session::with_new();
s.execute("slide.new", &json!({"layout": "blank"})).unwrap();
let app = SlideApp::new(s, Services::default());
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1400.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
h.state_mut().run("view.guides", json!({"on": true})).unwrap();
h.run_steps(2);
+1 -1
View File
@@ -34,7 +34,7 @@ pub fn ime_area(app: &SlideApp, xf: Xf) -> Option<Rect> {
/// has settled.
pub(super) fn ime_output(app: &mut SlideApp, ui: &Ui, xf: Xf) {
let ctx = ui.ctx();
if crate::framework::widget_has_keyboard(ctx) || app.dialog.as_ref().is_some_and(|d| d.modal()) || app.palette.is_some() || app.backstage_open() {
if ctx.memory(|m| m.focused().is_some()) || app.dialog.as_ref().is_some_and(|d| d.modal()) || app.palette.is_some() || app.backstage_open() {
return;
}
let Some(r) = ime_area(app, xf) else { return };
+14 -22
View File
@@ -42,17 +42,13 @@ fn drag_indents_add_move_and_remove_tabs_on_the_ruler() {
s.execute("text.insert", &json!({"text": "Name\tRole\tTeam"})).unwrap();
let mut app = SlideApp::new(s, Services::default());
app.ui.ruler = true;
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1400.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
let (slide, k) = (h.state().slide_rect.unwrap(), h.state().canvas_scale);
let x0 = ruler(&mut h)["x"].as_f64().unwrap() as f32;
@@ -97,17 +93,13 @@ fn editing_harness() -> Harness<'static, SlideApp> {
s.execute("text.insert", &json!({"text": "Item\t9.50"})).unwrap();
let mut app = SlideApp::new(s, Services::default());
app.ui.ruler = true;
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1400.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
h
}
+8 -9
View File
@@ -95,7 +95,7 @@ fn a_placeholder_that_inherits_its_box_has_a_resize_cursor() {
}
fn harness() -> Harness<'static, SlideApp> {
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
@@ -315,14 +315,13 @@ fn app_with_table() -> (egui_kittest::Harness<'static, SlideApp>, deckcraft_mode
let r = s.execute("insert.table", &json!({"rows": 2, "cols": 2, "rect": [100.0, 100.0, 400.0, 80.0], "data": data})).unwrap();
let id = deckcraft_model::ShapeId(r["id"].as_u64().unwrap() as u32);
s.execute("edit.deselect", &json!({})).unwrap();
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(s, Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(s, Services::default()),
);
// The app keeps requesting repaints, so step frames instead of run().
harness.run_steps(2);
(harness, id)
+7 -11
View File
@@ -22,17 +22,13 @@ fn harness() -> (Harness<'static, SlideApp>, usize) {
s.set_active(0);
s.execute("review.compare", &json!({"name": "Q3 review.deckcraft", "data": rev})).unwrap();
let app = SlideApp::new(s, Services::default());
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1400.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(4);
(h, n)
}
+1 -1
View File
@@ -12,7 +12,7 @@ use crate::{Services, SlideApp};
fn harness() -> Harness<'static, SlideApp> {
let mut app = SlideApp::new(Session::with_new(), Services::default());
app.ui.tab = "Insert".into();
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1800.0, 1100.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1800.0, 1100.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
+2 -2
View File
@@ -109,7 +109,7 @@ pub fn show(app: &mut SlideApp, ctx: &egui::Context) {
}
close = body(app, ui, &mut d);
});
let escape = crate::framework::escape_pressed(ctx);
let escape = ctx.input(|i| i.key_pressed(egui::Key::Escape));
if open && !close && !escape {
app.dialog = Some(d);
} else if !close && d.id == "preferences" {
@@ -262,7 +262,7 @@ fn color_label(v: &Value) -> String {
fn choice(ui: &mut Ui, d: &mut Dialog, salt: &str, name: &str, key: &str, choices: &[(&str, &str)]) {
let cur = d.get(key, "");
let label = choices.iter().find(|(v, _)| *v == cur).map(|(_, l)| *l).unwrap_or(cur.as_str());
let combo = egui::ComboBox::from_id_salt(salt).selected_text(label).width(140.0).show_ui(ui, |ui| {
let combo = craft_ui::ComboBox::from_id_salt(salt).selected_text(label).width(140.0).show_ui(ui, |ui| {
for (v, l) in choices {
if ui.selectable_label(cur == *v, *l).clicked() {
d.fields.insert((*key).into(), (*v).into());
+7 -11
View File
@@ -85,17 +85,13 @@ mod about_credits_tests {
fn about_dialog_tabs_keep_responding() {
let mut app = SlideApp::new(deckcraft_engine::Session::with_new(), Services::default());
app.dialog = Some(Dialog::new("about"));
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1440.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(4);
assert_eq!(tab_of(&h), "about");
for label in ["Contributors", "Models", "About", "Models", "Contributors"] {
+7 -7
View File
@@ -101,7 +101,7 @@ fn dlg_slide_size(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
}
let label = ui.label("Slides sized for:");
let preset = d.get("preset", "");
let combo = egui::ComboBox::from_id_salt("sizes").selected_text(if preset.is_empty() { "Custom" } else { &preset }).show_ui(ui, |ui| {
let combo = craft_ui::ComboBox::from_id_salt("sizes").selected_text(if preset.is_empty() { "Custom" } else { &preset }).show_ui(ui, |ui| {
for (label, w, h) in deckcraft_model::defaults::SLIDE_SIZES {
if ui.selectable_label(preset == *label, *label).clicked() {
d.fields.insert("preset".into(), label.to_string());
@@ -149,7 +149,7 @@ fn dlg_header_footer(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
ui.add_enabled_ui(date && automatic, |ui| {
ui.horizontal(|ui| {
ui.label(" Format:");
egui::ComboBox::from_id_salt("hf-date-format").selected_text(label).width(200.0).show_ui(ui, |ui| {
craft_ui::ComboBox::from_id_salt("hf-date-format").selected_text(label).width(200.0).show_ui(ui, |ui| {
for (kind, sample) in &rows {
if ui.selectable_label(fmt == *kind, sample).clicked() {
d.fields.insert("dateFormat".into(), (*kind).to_string());
@@ -264,7 +264,7 @@ fn dlg_setup_show(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
let chosen = d.fields.entry("custom".into()).or_insert_with(|| sh.custom_show.clone().unwrap_or_default()).clone();
let field = ui.label("Slides");
let label = if chosen.is_empty() { "All slides".to_string() } else { chosen.clone() };
let combo = egui::ComboBox::from_id_salt("setup_custom").selected_text(label).show_ui(ui, |ui| {
let combo = craft_ui::ComboBox::from_id_salt("setup_custom").selected_text(label).show_ui(ui, |ui| {
if ui.selectable_label(chosen.is_empty(), "All slides").clicked() {
d.fields.insert("custom".into(), String::new());
}
@@ -428,7 +428,7 @@ fn dlg_bullets(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
let color = d.get("color", "");
ui.horizontal(|ui| {
let field = ui.add_sized(vec2(120.0, 20.0), egui::Label::new("Color:"));
let combo = egui::ComboBox::from_id_salt("bullet-color")
let combo = craft_ui::ComboBox::from_id_salt("bullet-color")
.selected_text(colors.iter().find(|c| c.0 == color).map_or("Automatic", |c| c.1))
.show_ui(ui, |ui| {
for (k, l) in colors {
@@ -535,7 +535,7 @@ fn dlg_action(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
];
let shown = targets.iter().find(|t| t.0 == kind).map_or("Next Slide", |t| t.1);
ui.add_enabled_ui(hyperlink, |ui| {
let combo = egui::ComboBox::from_id_salt("action-target").selected_text(shown).show_ui(ui, |ui| {
let combo = craft_ui::ComboBox::from_id_salt("action-target").selected_text(shown).show_ui(ui, |ui| {
for (k, l) in targets {
if ui.selectable_label(kind == k, l).clicked() {
d.fields.insert("kind".into(), k.into());
@@ -733,7 +733,7 @@ fn dlg_export(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
ui.add_space(4.0);
ui.horizontal(|ui| {
let field = ui.label("Print layout:");
let combo = egui::ComboBox::from_id_salt("pdf_layout")
let combo = craft_ui::ComboBox::from_id_salt("pdf_layout")
.selected_text(match pdf_layout.as_str() {
"notes" => "Notes Pages",
"h1" => "Handouts (1 slide per page)",
@@ -818,7 +818,7 @@ fn dlg_replace_fonts(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
let mut to = d.get("to", "");
egui::Grid::new("replace_fonts").num_columns(2).spacing(vec2(10.0, 8.0)).show(ui, |ui| {
let field = ui.label("Replace:");
let combo = egui::ComboBox::from_id_salt("rf_from").width(240.0).selected_text(from.clone()).show_ui(ui, |ui| {
let combo = craft_ui::ComboBox::from_id_salt("rf_from").width(240.0).selected_text(from.clone()).show_ui(ui, |ui| {
for f in &used {
ui.selectable_value(&mut from, f.clone(), f);
}
@@ -31,17 +31,13 @@ fn two_boxes() -> Harness<'static, SlideApp> {
fn harness_of(s: Session) -> Harness<'static, SlideApp> {
let app = SlideApp::new(s, Services::default());
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1440.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(4);
h
}
+1 -1
View File
@@ -223,7 +223,7 @@ pub fn contributors_ui(ui: &mut egui::Ui) {
}
ui.separator();
let field = ui.label("Sort");
let combo = egui::ComboBox::from_id_salt("credits_sort").selected_text(v.key.label().0).show_ui(ui, |ui| {
let combo = craft_ui::ComboBox::from_id_salt("credits_sort").selected_text(v.key.label().0).show_ui(ui, |ui| {
for k in SortKey::ALL {
if ui.selectable_label(v.key == k, k.label().0).clicked() {
v.key = k;
+1 -1
View File
@@ -49,7 +49,7 @@ pub(super) fn date_time_dialog(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog)
let lang_label = DATE_LANGS.iter().find(|(k, _)| *k == lang).map(|(_, l)| *l).unwrap_or("English (United States)");
ui.horizontal(|ui| {
ui.label("Language:");
let opened = egui::ComboBox::from_id_salt("date-lang").selected_text(lang_label).width(240.0).show_ui(ui, |ui| {
let opened = craft_ui::ComboBox::from_id_salt("date-lang").selected_text(lang_label).width(240.0).show_ui(ui, |ui| {
for (k, l) in DATE_LANGS {
if ui.selectable_label(lang == *k, *l).clicked() {
d.fields.insert("language".into(), (*k).to_string());
+1 -1
View File
@@ -16,7 +16,7 @@ pub(super) fn gif_options(app: &SlideApp, ui: &mut Ui, d: &mut Dialog) -> Result
ui.add_space(4.0);
ui.horizontal(|ui| {
let field = ui.add_sized(vec2(120.0, 20.0), egui::Label::new("Size:"));
let combo = egui::ComboBox::from_id_salt("gif_size").selected_text(size_label(&size)).show_ui(ui, |ui| {
let combo = craft_ui::ComboBox::from_id_salt("gif_size").selected_text(size_label(&size)).show_ui(ui, |ui| {
for k in SIZE_PRESETS.iter().map(|(k, _)| *k).chain(["custom"]) {
if ui.selectable_label(size == k, size_label(k)).clicked() {
d.fields.insert("gifSize".into(), k.into());
+2 -2
View File
@@ -26,7 +26,7 @@ pub(super) fn font_dialog(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bo
}
ui.horizontal(|ui| {
let field = ui.add_sized(vec2(88.0, 20.0), egui::Label::new("Font"));
let combo = egui::ComboBox::from_id_salt("font_dialog_family")
let combo = craft_ui::ComboBox::from_id_salt("font_dialog_family")
.selected_text(if family.is_empty() { " " } else { family.as_str() })
.width(300.0)
.show_ui(ui, |ui| {
@@ -75,7 +75,7 @@ pub(super) fn font_dialog(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bo
let mut spacing = d.get("spacing", "0");
let edited = ui.add(egui::TextEdit::singleline(&mut spacing).desired_width(64.0).hint_text("pt"));
let mut picked = None;
let combo = egui::ComboBox::from_id_salt("font_dialog_spacing")
let combo = craft_ui::ComboBox::from_id_salt("font_dialog_spacing")
.selected_text(match spacing.as_str() {
"-3" => "Very tight",
"-1.5" => "Tight",
@@ -13,17 +13,13 @@ fn harness() -> Harness<'static, SlideApp> {
// A selected shape, not a caret: the dialog then formats the text that is already there.
let _ = s.execute("text.exit", &json!({}));
let app = SlideApp::new(s, Services::default());
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1440.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(4);
h
}
+13 -12
View File
@@ -103,19 +103,20 @@ pub(super) fn paragraph_dialog(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog)
let field = ui.add_sized(vec2(110.0, 20.0), egui::Label::new("Line spacing"));
let kind = d.get("lineKind", "multiple");
let value = d.get("lineValue", "1");
let combo = egui::ComboBox::from_id_salt("paragraph_line").selected_text(line_preset_label(&kind, &value)).width(140.0).show_ui(ui, |ui| {
for (label, k, v) in [
("Single", "multiple", Some("1")),
("1.5 lines", "multiple", Some("1.5")),
("Double", "multiple", Some("2")),
("Multiple", "multiple", None),
("Exactly", "exactly", None),
] {
if ui.selectable_label(line_preset_label(&kind, &value) == label, label).clicked() {
picked = Some((k, v));
let combo =
craft_ui::ComboBox::from_id_salt("paragraph_line").selected_text(line_preset_label(&kind, &value)).width(140.0).show_ui(ui, |ui| {
for (label, k, v) in [
("Single", "multiple", Some("1")),
("1.5 lines", "multiple", Some("1.5")),
("Double", "multiple", Some("2")),
("Multiple", "multiple", None),
("Exactly", "exactly", None),
] {
if ui.selectable_label(line_preset_label(&kind, &value) == label, label).clicked() {
picked = Some((k, v));
}
}
}
});
});
let _ = combo.response.labelled_by(field.id);
ui.add_space(8.0);
let _ = labeled_text(ui, d, "At", "lineValue", 64.0);
@@ -13,17 +13,13 @@ fn harness() -> Harness<'static, SlideApp> {
s.execute("shape.insert", &json!({"preset": "rect", "rect": [80.0, 80.0, 320.0, 80.0], "text": "Hello"})).unwrap();
let _ = s.execute("text.exit", &json!({}));
let app = SlideApp::new(s, Services::default());
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1440.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(4);
h
}
+1 -1
View File
@@ -69,7 +69,7 @@ fn pick_album_picture(app: &mut SlideApp) -> Option<Value> {
fn album_choice(ui: &mut Ui, d: &mut Dialog, id: &str, name: &str, key: &str, default: &str, choices: &[(&str, &str)]) {
let cur = d.get(key, default);
let label = choices.iter().find(|(k, _)| *k == cur).map(|(_, l)| *l).unwrap_or(default);
let opened = egui::ComboBox::from_id_salt(id).selected_text(label).width(220.0).show_ui(ui, |ui| {
let opened = craft_ui::ComboBox::from_id_salt(id).selected_text(label).width(220.0).show_ui(ui, |ui| {
for (k, l) in choices {
if ui.selectable_label(cur == *k, *l).clicked() {
d.fields.insert(key.into(), (*k).to_string());
@@ -18,17 +18,13 @@ fn png() -> Vec<u8> {
}
fn harness(app: SlideApp) -> Harness<'static, SlideApp> {
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1600.0, 1200.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1200.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
h
}
@@ -18,7 +18,7 @@ fn interface_size<'a>(h: &'a Harness<'_, SlideApp>) -> Node<'a> {
}
fn harness() -> Harness<'static, SlideApp> {
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
@@ -7,7 +7,7 @@ use serde_json::json;
use crate::{Services, SlideApp};
fn harness() -> Harness<'static, SlideApp> {
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1600.0, 900.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
+4 -4
View File
@@ -17,7 +17,7 @@ fn spelling_dialog_changes_and_ignores_words() {
let mut app = SlideApp::new(Session::with_new(), Services::default());
app.session.execute("shape.insert", &json!({"preset": "rect", "rect": [100, 100, 500, 120], "text": "Our plna for teh quarter"})).unwrap();
app.dialog = Some(crate::dialogs::Dialog::new("spelling"));
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1100.0, 700.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1100.0, 700.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
@@ -82,7 +82,7 @@ fn squiggles_mark_misspelt_words_in_the_background() {
let st = app.session.active().unwrap().clone();
let lines = app.squiggles.settle(&st);
assert_eq!(lines.len(), 3, "{lines:?}");
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1100.0, 700.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1100.0, 700.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
@@ -153,7 +153,7 @@ fn squiggles_in_table_cells_and_notes_and_on_the_ui_thread() {
// Each under its own cell: the first in the top-left one, the second in the bottom-right one.
assert!(lines[0].0.x < 380.0 && lines[0].0.y < 160.0 && lines[1].0.x > 380.0 && lines[1].0.y > 160.0, "{lines:?}");
assert_eq!(app.squiggles.settle_notes("Remmeber to show the totl", "xx-TB"), vec![(0, 8), (21, 25)]);
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1100.0, 760.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1100.0, 760.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
@@ -226,7 +226,7 @@ fn notes_menu_language_dialog_and_repeated_words() {
let st = app.session.active().unwrap().clone();
// "is is" is flagged as repeated, "wrok" as misspelt.
assert_eq!(app.squiggles.settle(&st).len(), 2);
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1100.0, 760.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1100.0, 760.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
+21 -24
View File
@@ -48,14 +48,13 @@ fn header_footer_apply_keeps_an_existing_date_format() {
})
.collect()
};
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(vec2(1200.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(session, crate::Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(vec2(1200.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(session, crate::Services::default()),
);
harness.run_steps(2);
assert_eq!(date_fields(harness.state()), vec!["datetime4".to_string()]);
harness.state_mut().run("app.dialog", json!({"id": "headerFooter"})).unwrap();
@@ -90,14 +89,13 @@ fn export_dialog_writes_an_animated_gif() {
};
let mut session = deckcraft_engine::Session::with_new();
session.execute("slide.new", &json!({})).unwrap();
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(vec2(1200.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(session, services),
);
let mut harness = egui_kittest::Harness::builder().with_size(vec2(1200.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(session, services),
);
harness.run_steps(2);
harness.state_mut().run("app.exportDialog", json!({})).unwrap();
harness.run_steps(2);
@@ -142,14 +140,13 @@ fn export_dialog_writes_a_png_with_a_transparent_background() {
let path = dir.join("slide.png");
let picked = path.to_string_lossy().to_string();
let services = crate::Services { pick_save: Some(Box::new(move |_: &str| Some(picked.clone()))), ..Default::default() };
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(vec2(1200.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(deckcraft_engine::Session::with_new(), services),
);
let mut harness = egui_kittest::Harness::builder().with_size(vec2(1200.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(deckcraft_engine::Session::with_new(), services),
);
harness.run_steps(2);
harness.state_mut().run("app.exportDialog", json!({})).unwrap();
harness.run_steps(2);
@@ -10,7 +10,7 @@ use crate::{Services, SlideApp};
fn harness() -> Harness<'static, SlideApp> {
let mut app = SlideApp::new(Session::with_new(), Services::default());
app.ui.tab = "Design".into();
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1800.0, 1100.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1800.0, 1100.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
+1 -1
View File
@@ -30,7 +30,7 @@ fn theme_font_choices(app: &SlideApp, selected: &str) -> Vec<String> {
/// Draw an accessible font combo box and update the selected family; the caller supplies the
/// visible label.
fn font_combo(ui: &mut Ui, label: &str, choices: &[String], selected: &mut String) {
let resp = egui::ComboBox::from_id_salt(label).selected_text(selected.as_str()).width(240.0).show_ui(ui, |ui| {
let resp = craft_ui::ComboBox::from_id_salt(label).selected_text(selected.as_str()).width(240.0).show_ui(ui, |ui| {
for face in choices {
if ui.selectable_label(selected == face, face).clicked() {
*selected = face.clone();
@@ -9,7 +9,7 @@ use crate::{Services, SlideApp};
fn harness() -> Harness<'static, SlideApp> {
let mut app = SlideApp::new(Session::with_new(), Services::default());
app.ui.tab = "Design".into();
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1800.0, 1100.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1800.0, 1100.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
+23 -63
View File
@@ -1,11 +1,8 @@
//! One background check at start-up (and on demand from Help) for a newer release, the modal
//! prompt that offers to update and restart, and the result of a check, as craft-update's dialogs
//! on the app's [`DialogHost`](craft_ui::dialog::DialogHost). The flow itself is
//! `craft_update::updater::Updater`.
//! One background check at start-up (and on demand from Help) for a newer release, and the modal
//! prompt that offers to update and restart. The flow itself is `craft_update::updater::Updater`.
use craft_ui::dialog::DialogResult;
use craft_update::stack_dialogs::{CheckChoice, UpdateCheckDialog};
use craft_update::updater::{Action, Status, Updater};
use craft_update::{CheckResultDialog, CheckResultResponse};
use crate::SlideApp;
@@ -66,62 +63,42 @@ pub(crate) fn tick(app: &mut SlideApp, ctx: &egui::Context) {
return;
}
if std::mem::take(&mut rt.check_requested) {
rt.updater.check_now();
rt.updater.check_now(ctx);
} else if rt.enabled {
rt.updater.check_at_start();
rt.updater.check_at_start(ctx);
}
rt.updater.tick(ctx);
}
/// One pass of the update flow, before the dialog host runs (`SlideApp::ui`): answers the result
/// dialog closed in the last pass, drives the startup prompt, and keeps the result dialog open and
/// current while the updater has something to report.
pub(crate) fn show(app: &mut SlideApp, ctx: &egui::Context) {
if !app.updates_rt.stable_services {
return;
}
// An installation starts, and a ready update asks the app to close, only while nothing is unsaved.
let clean = !app.session.documents().iter().any(|d| d.is_dirty());
// Answered before the dialog is kept open below, so a dismissed result does not open again.
if let Some(result) = app.framework_dialogs.take::<UpdateCheckDialog>() {
answer(&mut app.updates_rt, ctx, result, clean);
}
match app.updates_rt.updater.run(&mut app.framework_dialogs, clean) {
match app.updates_rt.updater.show_if(ctx, clean) {
Action::OpenUrl(url) => ctx.open_url(egui::OpenUrl::new_tab(url)),
// The app's close path asks about unsaved work; `on_exit` starts the restart helper.
Action::Close => ctx.send_viewport_cmd(egui::ViewportCommand::Close),
_ => {}
Action::None => {}
}
// The result dialog reports a requested check, and at the first start after an update what
// The result window reports a requested check, and at the first start after an update what
// that update came to (installed, or why it failed).
let updater = &app.updates_rt.updater;
let reports = !matches!(updater.status(), Status::Idle);
let (status, installing, message) = (updater.status().clone(), updater.is_installing(), updater.status_message());
let open = app.framework_dialogs.is_open::<UpdateCheckDialog>();
if reports && !open {
app.framework_dialogs.open(UpdateCheckDialog::new(VERSION));
} else if !reports && open {
app.framework_dialogs.cancel::<UpdateCheckDialog>(ctx);
}
if let Some(dialog) = app.framework_dialogs.get_mut::<UpdateCheckDialog>() {
dialog.set_status(status);
dialog.set_installing(installing);
dialog.set_message(message);
let rt = &mut app.updates_rt;
if !matches!(rt.updater.status(), Status::Idle) {
let response = CheckResultDialog::new(&crate::UPDATE_APP, VERSION).show(ctx, rt.updater.status());
answer(rt, response);
}
}
/// Acts on the result dialog's answer.
fn answer(rt: &mut Runtime, ctx: &egui::Context, result: DialogResult<CheckChoice>, clean: bool) {
match result {
DialogResult::Ok(CheckChoice::CheckNow | CheckChoice::CheckAgain) => rt.check_requested = true,
// The next pass's `run` asks the window to close once nothing is unsaved.
DialogResult::Ok(CheckChoice::RestartToUpdate) => rt.updater.restart_to_update(),
DialogResult::Ok(CheckChoice::Update) => {
rt.updater.request_install(clean);
}
DialogResult::Ok(CheckChoice::Download) => ctx.open_url(egui::OpenUrl::new_tab(crate::UPDATE_APP.releases_url())),
// OK, Esc and the close box dismiss the outcome it showed.
_ => rt.updater.dismiss_status(),
/// Acts on the result window's answer.
fn answer(rt: &mut Runtime, response: CheckResultResponse) {
match response {
CheckResultResponse::Close => rt.updater.dismiss_status(),
CheckResultResponse::CheckAgain => rt.check_requested = true,
// The next frame's `show_if` asks the window to close once nothing is unsaved.
CheckResultResponse::RestartToUpdate => rt.updater.restart_to_update(),
CheckResultResponse::None => {}
}
}
@@ -133,22 +110,9 @@ mod tests {
fn an_offered_release_opens_the_prompt() {
let mut app = SlideApp::new(deckcraft_engine::Session::new(), crate::Services::default());
let ctx = egui::Context::default();
crate::framework::install_headless(&ctx);
assert!(!app.updates_rt.updater.prompt_open());
app.updates_rt.updater.offer(craft_update::Release { tag: "v99.0.0".into(), ..Default::default() });
// The offer reads on a thread whether this copy can install the release itself; a later
// pass's tick opens the prompt.
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
while !app.updates_rt.updater.prompt_open() && std::time::Instant::now() < deadline {
ctx.run_ui(egui::RawInput::default(), |ui| {
tick(&mut app, ui.ctx());
show(&mut app, ui.ctx());
app.framework_dialogs.run(ui);
})
.textures_delta
.clear();
std::thread::sleep(std::time::Duration::from_millis(2));
}
ctx.run_ui(egui::RawInput::default(), |ui| show(&mut app, ui.ctx())).textures_delta.clear();
assert!(app.updates_rt.updater.prompt_open());
}
@@ -205,16 +169,14 @@ mod tests {
std::fs::write(root.join("data").join("self-update-done.txt"), VERSION).unwrap();
let mut app = app_with_records(&root);
let ctx = egui::Context::default();
crate::framework::install_headless(&ctx);
ctx.run_ui(egui::RawInput::default(), |ui| {
tick(&mut app, ui.ctx());
show(&mut app, ui.ctx());
app.framework_dialogs.run(ui);
})
.textures_delta
.clear();
assert!(matches!(app.updates_rt.updater.status(), Status::Updated(_)), "{:?}", app.updates_rt.updater.status());
answer(&mut app.updates_rt, &ctx, DialogResult::Ok(CheckChoice::Close), true);
answer(&mut app.updates_rt, CheckResultResponse::Close);
assert_eq!(app.updates_rt.updater.status(), &Status::Idle);
let _ = std::fs::remove_dir_all(&root);
}
@@ -227,16 +189,14 @@ mod tests {
std::fs::write(root.join("data").join("logs").join("self-update-error.txt"), "the disk is full").unwrap();
let mut app = app_with_records(&root);
let ctx = egui::Context::default();
crate::framework::install_headless(&ctx);
ctx.run_ui(egui::RawInput::default(), |ui| {
tick(&mut app, ui.ctx());
show(&mut app, ui.ctx());
app.framework_dialogs.run(ui);
})
.textures_delta
.clear();
assert_eq!(app.updates_rt.updater.status(), &Status::InstallFailed("the disk is full".into()));
answer(&mut app.updates_rt, &ctx, DialogResult::Ok(CheckChoice::CheckAgain), true);
answer(&mut app.updates_rt, CheckResultResponse::CheckAgain);
assert!(app.updates_rt.check_requested);
let _ = std::fs::remove_dir_all(&root);
}
-232
View File
@@ -1,232 +0,0 @@
//! The document window as the window's one canvas stop: Tab, real presses and its keys.
use deckcraft_engine::Session;
use egui::{Event, Id, Key, Modifiers, PointerButton, Role, vec2};
use egui_kittest::Harness;
use egui_kittest::kittest::Queryable as _;
use serde_json::json;
use crate::framework::document_id;
use crate::state::ViewMode;
use crate::{Services, SlideApp};
fn harness() -> Harness<'static, SlideApp> {
let mut session = Session::with_new();
session.prefs.autocorrect = false;
let mut app = SlideApp::new(session, Services::default());
app.ui.notes = false;
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(4);
h
}
fn focused(h: &Harness<'_, SlideApp>) -> Option<Id> {
h.ctx.memory(|m| m.focused())
}
fn press(h: &mut Harness<'_, SlideApp>, modifiers: Modifiers, key: Key) {
h.key_press_modifiers(modifiers, key);
h.run_steps(2);
}
fn tab(h: &mut Harness<'_, SlideApp>) {
press(h, Modifiers::NONE, Key::Tab);
}
fn selected(h: &Harness<'_, SlideApp>) -> Vec<deckcraft_model::ShapeId> {
h.state().session.active().unwrap().selection.shapes.clone()
}
#[test]
fn tab_selects_the_slides_objects_then_moves_on_and_shift_tab_walks_back() {
let mut h = harness();
assert_eq!(focused(&h), Some(document_id()), "an opened presentation has the keyboard");
let objects: Vec<_> = h.state().session.active().unwrap().shapes().iter().map(|s| s.id).collect();
assert!(objects.len() > 1);
for object in &objects {
tab(&mut h);
assert_eq!((selected(&h), focused(&h)), (vec![*object], Some(document_id())));
}
press(&mut h, Modifiers::SHIFT, Key::Tab);
let before = focused(&h);
assert!(before.is_some() && before != Some(document_id()), "with the last object selected, Shift+Tab leaves the slide");
tab(&mut h);
assert_eq!(focused(&h), Some(document_id()), "Tab from the stop before it stops at the slide");
tab(&mut h);
let after = focused(&h);
assert!(after.is_some() && after != Some(document_id()) && after != before, "past the last object, Tab moves on");
press(&mut h, Modifiers::SHIFT, Key::Tab);
assert_eq!(focused(&h), Some(document_id()), "Shift+Tab walks back to the slide");
assert_eq!(selected(&h), objects[objects.len() - 1..]);
}
#[test]
fn a_press_on_the_slide_takes_the_keyboard_from_a_focused_button() {
let mut h = harness();
h.get_by_role_and_label(Role::Button, "File").focus();
h.run_steps(2);
assert!(h.get_by_role_and_label(Role::Button, "File").is_focused());
let pos = h.state().canvas_rect.unwrap().right_bottom() - vec2(10.0, 10.0);
h.hover_at(pos);
h.run_steps(1);
for pressed in [true, false] {
h.event(Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE });
h.run_steps(1);
}
assert_eq!(focused(&h), Some(document_id()));
press(&mut h, Modifiers::NONE, Key::Enter);
assert!(!h.state().backstage_open(), "the File button isn't activated");
assert_eq!(h.state().session.active().unwrap().doc.slides.len(), 2, "Enter adds a slide");
}
#[test]
fn after_a_press_on_a_pane_tab_selects_the_next_object() {
let mut h = harness();
let pos = egui::pos2(h.state().ui.thumbs_width / 2.0, 300.0);
h.hover_at(pos);
h.run_steps(1);
for pressed in [true, false] {
h.event(Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE });
h.run_steps(2);
}
assert!(h.state().slides_focused, "the press is in the thumbnail pane");
let first = h.state().session.active().unwrap().shapes()[0].id;
tab(&mut h);
assert_eq!((selected(&h), focused(&h)), (vec![first], Some(document_id())));
}
#[test]
fn after_a_dialog_closes_tab_selects_the_next_object() {
let mut h = harness();
h.state_mut().dialog = Some(crate::dialogs::Dialog::new("find"));
h.run_steps(3);
assert!(h.ctx.text_edit_focused(), "the dialog's field has the focus");
h.state_mut().dialog = None;
h.run_steps(4);
let first = h.state().session.active().unwrap().shapes()[0].id;
tab(&mut h);
assert_eq!((selected(&h), focused(&h)), (vec![first], Some(document_id())));
}
#[test]
fn after_enter_in_a_ribbon_field_tab_selects_the_next_object() {
let mut h = harness();
h.state_mut().ui.tab = "Transitions".into();
tab(&mut h);
let objects: Vec<_> = h.state().session.active().unwrap().shapes().iter().map(|s| s.id).collect();
assert_eq!(selected(&h), objects[..1]);
h.get_by_role_and_label(Role::TextInput, "Duration value").focus();
h.run_steps(2);
assert!(h.ctx.text_edit_focused());
press(&mut h, Modifiers::NONE, Key::Enter);
assert!(!h.ctx.text_edit_focused(), "Enter commits the field");
assert!(h.state().session.active().unwrap().selection.text.is_none(), "and reaches nothing on the slide");
tab(&mut h);
assert_eq!((selected(&h), focused(&h)), (vec![objects[1]], Some(document_id())));
}
#[test]
fn a_press_in_the_sorter_takes_the_keyboard_from_a_focused_button() {
let mut h = harness();
h.state_mut().ui.view = ViewMode::Sorter;
h.run_steps(3);
h.get_by_role_and_label(Role::Button, "File").focus();
h.run_steps(2);
assert_ne!(focused(&h), Some(document_id()));
let pos = h.get_by_role_and_label(Role::Button, "Slide 1").rect().center();
h.hover_at(pos);
h.run_steps(1);
h.event(Event::PointerButton { pos, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
h.run_steps(2);
assert_eq!(focused(&h), Some(document_id()));
}
#[test]
fn edited_text_traps_no_focus_in_the_sorter_or_the_file_tab() {
let mut h = harness();
let title = h.state().session.active().unwrap().shapes()[0].id.0;
h.state_mut().session.execute("text.edit", &json!({"id": title})).unwrap();
h.run_steps(2);
h.state_mut().ui.view = ViewMode::Sorter;
h.run_steps(2);
tab(&mut h);
let stop = focused(&h);
assert!(stop.is_some_and(|id| id != document_id()), "Tab moves on from the sorter");
tab(&mut h);
assert!(focused(&h).is_some_and(|id| Some(id) != stop && id != document_id()), "and on again");
h.state_mut().open_backstage(crate::backstage::Page::Home);
h.run_steps(3);
tab(&mut h);
h.run_steps(2);
assert!(h.state().session.active().unwrap().selection.text.is_some());
assert!(focused(&h).is_some(), "Tab stays on a control of the File tab");
}
#[test]
fn a_presentation_opened_from_the_palette_gets_the_keyboard() {
let mut h = harness();
h.state_mut().run("app.palette", json!({})).unwrap();
h.run_steps(3);
assert!(h.ctx.text_edit_focused(), "the palette's field has the focus");
let app = h.state_mut();
app.palette = None;
app.run("file.new", json!({})).unwrap();
app.run("slide.new", json!({"layout": "blank"})).unwrap();
assert!(!app.session.tab_has_work(), "an empty slide, which asks for the focus only because it opened");
h.run_steps(4);
assert_eq!(focused(&h), Some(document_id()));
}
#[test]
fn the_focused_slide_takes_arrows_escape_typing_and_tab() {
let mut h = harness();
let left = |h: &Harness<'_, SlideApp>| {
let st = h.state().session.active().unwrap();
deckcraft_engine::cmd::xfrm_of(&st.doc, &st.selection, &st.shapes()[0]).x
};
tab(&mut h);
let x = left(&h);
press(&mut h, Modifiers::NONE, Key::ArrowRight);
assert!(left(&h) > x, "the arrow moves the object, not the focus");
press(&mut h, Modifiers::NONE, Key::Escape);
assert!(selected(&h).is_empty());
assert_eq!(focused(&h), Some(document_id()), "Escape leaves the focus on the slide");
tab(&mut h);
h.event(Event::Text("ab".into()));
h.run_steps(2);
tab(&mut h);
h.event(Event::Text("c".into()));
h.run_steps(2);
let st = h.state().session.active().unwrap();
assert_eq!(st.shapes()[0].text.as_ref().unwrap().text(), "ab\tc");
assert!(st.selection.text.is_some());
press(&mut h, Modifiers::NONE, Key::Escape);
assert!(h.state().session.active().unwrap().selection.text.is_none(), "Escape ends text editing");
assert_eq!(focused(&h), Some(document_id()));
}
#[test]
fn every_view_draws_the_document_and_the_file_tab_takes_its_focus() {
let mut h = harness();
for view in [ViewMode::Outline, ViewMode::Reading, ViewMode::NotesPage, ViewMode::Sorter] {
h.state_mut().ui.view = view;
h.run_steps(3);
assert_eq!(focused(&h), Some(document_id()), "the focus stays in the document window");
}
tab(&mut h);
assert!(focused(&h).is_some_and(|id| id != document_id()), "Tab has no work in the slide sorter");
h.state_mut().ui.view = ViewMode::Normal;
h.state_mut().open_backstage(crate::backstage::Page::Home);
h.run_steps(3);
assert!(h.state().backstage_open());
h.key_press(Key::Escape);
h.run_steps(3);
assert!(!h.state().backstage_open(), "Escape leaves the File tab");
assert_eq!(focused(&h), Some(document_id()), "and the slide has the keyboard again");
}
+4 -5
View File
@@ -123,11 +123,10 @@ fn hex(c: [u8; 4]) -> String {
}
/// The slide canvas while the Eyedropper waits: the pointer is a crosshair with the colour under it
/// beside it, a real click takes it (Enter and Space are egui's fake clicks of the focused canvas). Returns true when it
/// used the pointer (the tools get none).
/// beside it, a click takes it. Returns true when it used the pointer (the tools get none).
pub fn canvas(app: &mut SlideApp, ui: &Ui, resp: &egui::Response, xf: Xf) -> bool {
let Some(state) = app.eyedropper.as_ref() else { return false };
let escape = crate::framework::escape_pressed(ui.ctx());
let escape = ui.input(|i| i.key_pressed(egui::Key::Escape));
if escape || resp.secondary_clicked() {
app.eyedropper = None;
return true;
@@ -136,7 +135,7 @@ pub fn canvas(app: &mut SlideApp, ui: &Ui, resp: &egui::Response, xf: Xf) -> boo
let on_slide = app.slide_rect.is_some_and(|r| r.contains(pos));
if !on_slide {
ui.ctx().set_cursor_icon(CursorIcon::NotAllowed);
if resp.clicked_by(egui::PointerButton::Primary) {
if resp.clicked() {
app.eyedropper = None;
}
return true;
@@ -147,7 +146,7 @@ pub fn canvas(app: &mut SlideApp, ui: &Ui, resp: &egui::Response, xf: Xf) -> boo
if let Some(c) = under {
loupe(ui, pos, c);
}
if resp.clicked_by(egui::PointerButton::Primary) {
if resp.clicked() {
let (pick, slide) = (state.pick, state.slide);
app.eyedropper = None;
match pick {
+2 -15
View File
@@ -15,7 +15,7 @@ fn harness() -> Harness<'static, SlideApp> {
session.execute("slide.new", &json!({"layout": "blank"})).unwrap();
session.execute("shape.insert", &json!({"preset": "rect", "rect": [100, 100, 200, 100]})).unwrap();
session.execute("shape.fill", &json!({"color": "#ff0000"})).unwrap();
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
@@ -59,19 +59,6 @@ fn selection(h: &Harness<'static, SlideApp>) -> Vec<u32> {
h.state().session.doc().unwrap().selection.shapes.iter().map(|s| s.0).collect()
}
#[test]
fn space_on_the_focused_slide_picks_no_colour() {
let mut h = harness();
ask(&mut h);
let on_shape = at(&h, 150.0, 150.0);
h.input_mut().events.push(Event::PointerMoved(on_shape));
h.run_steps(3);
assert!(h.ctx.memory(|m| m.has_focus(crate::framework::document_id())));
h.key_press(egui::Key::Space);
h.run_steps(3);
assert!(h.state().eyedropper.is_some() && !result_waits_for(&h.ctx, menu()));
}
#[test]
fn a_click_on_the_slide_takes_the_colour_under_it_and_nothing_else_happens() {
let mut h = harness();
@@ -138,7 +125,7 @@ fn set_transparent_color_takes_the_colour_clicked_in_the_picture() {
session.execute("insert.picture", &json!({"data": data, "name": "a.png", "rect": [100, 100, 400, 200]})).unwrap();
let mut app = SlideApp::new(session, Services::default());
app.ui.tab = "Picture Format".into();
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1600.0, 1200.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1200.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
+7 -11
View File
@@ -13,17 +13,13 @@ use serde_json::json;
use crate::{Services, SlideApp, theme};
fn harness(app: SlideApp) -> Harness<'static, SlideApp> {
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1400.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
// The app keeps asking for frames, so step instead of run().
h.run_steps(3);
h
+7 -11
View File
@@ -14,17 +14,13 @@ fn ctrl_f_puts_the_caret_in_find_what() {
s.execute("text.exit", &json!({})).unwrap();
s.doc_mut().unwrap().selection.shapes.clear();
let app = SlideApp::new(s, Services::default());
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1400.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::F);
h.run_steps(3);
-182
View File
@@ -1,182 +0,0 @@
//! The craft-ui runtime, hosted from DeckCraft's own eframe `App` (craft-libs docs/craft-framework.md, section 2.2).
//! The desktop app calls [`install`] once, [`SlideApp::before_input`] in `raw_input_hook`, [`SlideApp::close_path`]
//! last in `logic`, and [`before_ui`] first in `ui`; the browser build and tests install with [`install_headless`].
//! `SlideApp::ui` runs the framework dialogs ([`SlideApp::framework_dialogs`]) after DeckCraft's own UI.
//!
//! The runtime takes Escape, Tab and the clipboard events for the whole window unless one of DeckCraft's own egui
//! widgets has the keyboard. The window's Escape is read with [`escape_pressed`] or [`take_window_cancel`]; the
//! document window is declared to the runtime with [`host_canvas`] each pass that draws it, which keeps the edit chords
//! and the clipboard events, and Tab while it has the focus and Tab has work, in egui's input for DeckCraft's own key
//! routing (`SlideApp::keyboard`). That routing has the keyboard unless [`widget_has_keyboard`].
use std::sync::Arc;
use craft_host::target::ShellInfo;
use craft_host::{AppInfo, Host};
use craft_keymap::{Chord, Key, Mods};
use craft_ui::fonts::{I18nScripts, SystemFonts, UiFonts};
use craft_ui::runtime::env::{RootEnv, Scale};
use craft_ui::runtime::focus::{self, EditSet, FocusTarget, KeepKeys, KeyUse};
use craft_ui::runtime::frame::{FrameInput, FrameOutput};
use craft_ui::runtime::keys::{Intent, with_window_intents};
use craft_ui::shell::embed::{self, CloseDecision};
use craft_window::system::WindowSystem;
use crate::SlideApp;
/// Each pass of the root window, first in `App::ui`: hands the runtime the native window it answers the hit test of
/// (Windows) and fits the window to its monitor once.
#[cfg(not(target_arch = "wasm32"))]
pub use craft_ui::shell::embed::before_ui;
/// The scripts of the interface languages, for the font stack.
static SCRIPTS: I18nScripts = I18nScripts;
/// The runtime's first font stack: egui's bundled faces and no installed system fonts. DeckCraft's own definitions
/// (`theme::install_fonts_with`, in the first UI pass) replace it before anything is drawn.
fn ui_fonts() -> UiFonts<'static> {
UiFonts::new(&SCRIPTS).system_fonts(SystemFonts::Off)
}
fn install_with(ctx: &egui::Context, shell: ShellInfo, windows: Arc<dyn WindowSystem>) -> Result<(), String> {
let spec = craft_ui::InstallSpec::new(shell, windows).app_id(crate::os_window::app_id());
embed::install(ctx, spec, &ui_fonts()).map(drop).map_err(|error| format!("the UI runtime could not be installed: {error}"))
}
/// Installs the runtime on the desktop window's context, once, before the first pass. `forced_x11` when the app
/// opens its window through XWayland. DeckCraft draws its own title bar row (`ribbon::title_bar`) and gives the
/// runtime no frame decision, so the runtime takes no part of the window's move area or hit test.
#[cfg(not(target_arch = "wasm32"))]
pub fn install(ctx: &egui::Context, forced_x11: bool) -> Result<(), String> {
use craft_host::target::Backend;
let backend = if forced_x11 { Backend::X11 } else { Backend::from_env() };
install_with(ctx, ShellInfo::default().backend(backend), Arc::new(craft_window::system::SystemWindows))
}
/// Installs the runtime on a context with no native window of its own: the browser build's canvas and test windows.
pub fn install_headless(ctx: &egui::Context) {
if let Err(error) = install_with(ctx, ShellInfo::default(), Arc::new(craft_window::system::NoWindows)) {
log::warn!("{error}");
}
}
/// Who DeckCraft is to the framework's dialogs (the update dialogs show its name and icon).
pub(crate) fn host() -> Arc<Host> {
Arc::new(
Host::builder(AppInfo { id: "deckcraft", name: "DeckCraft", version: env!("CARGO_PKG_VERSION") })
.icon_png(include_bytes!("../../../assets/app-icon/hicolor/128x128/apps/ai.storyteller.deckcraft.png"))
.build(),
)
}
impl SlideApp {
/// The framework's part of `App::raw_input_hook`, once per frame before the first pass: takes what the runtime
/// gathered since the last frame and gives the coming passes the root values (theme mode, interface scale).
pub fn before_input(&mut self, ctx: &egui::Context) {
embed::before_input(ctx, |output| self.frame_input(output));
}
/// The root values of this frame. DeckCraft registers no commands with the runtime and lets it toggle no chrome,
/// so the output carries nothing it acts on. The interface scale is DeckCraft's own (`UiState::ui_scale`, which
/// `ui_setup` applies), so the runtime's zoom and DeckCraft's agree.
fn frame_input(&mut self, _output: FrameOutput) -> FrameInput {
let mode = if self.ui.brightness == crate::theme::Brightness::Dark { craft_theme::Mode::Dark } else { craft_theme::Mode::Light };
// The slide show and the canvas read Ctrl/Cmd+wheel themselves, so a smooth Ctrl+wheel stays a wheel event.
let root = RootEnv::new().mode(mode).scale(Scale::new(self.ui.ui_scale.clamp(0.5, 3.0))).ctrl_wheel_pinch(false);
FrameInput::new(root).host(Arc::clone(&self.framework_host))
}
/// The framework's part of `App::logic`, after DeckCraft's own: the root window's close path. With unsaved
/// presentations the window stays open while the quit dialog asks; its answer closes the window again with
/// `quit_confirmed` set.
pub fn close_path(&mut self, ctx: &egui::Context) {
embed::logic(ctx, || {
if self.quit_confirmed || !self.session.documents().iter().any(|d| d.is_dirty()) {
return CloseDecision::Close;
}
self.show = None;
if self.dialog.as_ref().is_none_or(|d| d.id != "quit") {
self.dialog = Some(crate::dialogs::Dialog::new("quit"));
}
CloseDecision::Hold
});
}
}
/// Alt+1 to Alt+9, the Quick Access Toolbar's positions on Windows and Linux (`menus::ui_shortcut`). Claimed, so
/// the runtime's Alt+numpad code entry leaves them to DeckCraft's shortcuts.
const QUICK_ACCESS_KEYS: [Chord; 9] = [
Chord::new(Mods::ALT, Key::Num1),
Chord::new(Mods::ALT, Key::Num2),
Chord::new(Mods::ALT, Key::Num3),
Chord::new(Mods::ALT, Key::Num4),
Chord::new(Mods::ALT, Key::Num5),
Chord::new(Mods::ALT, Key::Num6),
Chord::new(Mods::ALT, Key::Num7),
Chord::new(Mods::ALT, Key::Num8),
Chord::new(Mods::ALT, Key::Num9),
];
/// The keys DeckCraft's document window keeps while it has the focus or is the window's key target: every clipboard
/// event and edit chord, and the Quick Access Toolbar's Alt+digits, which `SlideApp::keyboard` routes itself.
const DOCUMENT_KEYS: KeyUse = KeyUse::CANVAS.with_edits(EditSet::ALL).with_claims(&QUICK_ACCESS_KEYS);
/// The document window's widget: the slide canvas, the slide sorter or the notes page, whichever the view draws.
pub(crate) fn document_id() -> egui::Id {
egui::Id::unique("deckcraft_document")
}
/// Declares DeckCraft's document window, drawn in this pass, as the window's canvas. With nothing focused it is the
/// window's key target: the edit chords, the clipboard events and the claimed Alt+digits stay in egui's input for
/// DeckCraft. Tab and Shift+Tab stop at it; with `keeps_tab` the focused document keeps them in egui's input, else they
/// move on from it.
pub(crate) fn host_canvas(ctx: &egui::Context, keeps_tab: bool) {
let keys = if keeps_tab { DOCUMENT_KEYS.with_keep(KeepKeys::Tab) } else { DOCUMENT_KEYS };
focus::host_canvas(ctx, document_id(), keys);
}
/// Gives the document window the keyboard focus. It is the runtime's focus, which an Escape does not take away.
pub(crate) fn focus_document(ctx: &egui::Context) {
focus::request(ctx, FocusTarget::Id(document_id()));
}
/// The widget that has the keyboard, the document window left out: a focused document leaves the keyboard to
/// DeckCraft's own key routing, as with nothing focused.
pub(crate) fn focused_widget(ctx: &egui::Context) -> Option<egui::Id> {
ctx.memory(|m| m.focused()).filter(|id| *id != document_id())
}
/// Whether a widget other than the document window has the keyboard.
pub(crate) fn widget_has_keyboard(ctx: &egui::Context) -> bool {
focused_widget(ctx).is_some()
}
/// Whether Escape was pressed in this pass: from egui while one of DeckCraft's own widgets or popups has the keyboard,
/// otherwise the window's cancel, which the runtime routes to no component. Leaves it for later readers.
pub(crate) fn escape_pressed(ctx: &egui::Context) -> bool {
ctx.input(|i| i.key_pressed(egui::Key::Escape)) || window_escape(ctx)
}
/// Whether the window's cancel (an Escape while nothing has framework focus, which the runtime takes out of egui's
/// events) is there and untaken. Key loops that read egui's events add it as an Escape press.
pub(crate) fn window_escape(ctx: &egui::Context) -> bool {
window_cancel(ctx, false)
}
/// The Escape press [`window_escape`] stands for, for key loops over egui's events.
pub(crate) const ESCAPE_PRESS: egui::Event =
egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE };
/// Takes the window's cancel (an Escape while nothing has framework focus): whether there was one.
pub(crate) fn take_window_cancel(ctx: &egui::Context) -> bool {
window_cancel(ctx, true)
}
fn window_cancel(ctx: &egui::Context, take: bool) -> bool {
let mut pending = false;
with_window_intents(ctx, false, |intents| {
pending = intents.untaken(&Intent::Cancel);
take && pending && intents.take(Intent::Cancel)
});
pending
}
+1 -1
View File
@@ -13,7 +13,7 @@ fn harness(n: usize) -> egui_kittest::Harness<'static, SlideApp> {
for _ in 1..n {
s.execute("slide.new", &json!({})).unwrap();
}
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
egui_kittest::Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
+20 -22
View File
@@ -11,14 +11,13 @@ use deckcraft_engine::Session;
/// Build the standard 1280×800 UI harness around a supplied session and run three frames.
fn harness(session: Session) -> egui_kittest::Harness<'static, SlideApp> {
let mut h =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1280.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(session, Services::default()),
);
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1280.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(session, Services::default()),
);
crate::install_ime_pass_hooks(&h.ctx);
// The app keeps requesting repaints, so step frames instead of run().
h.run_steps(3);
@@ -192,20 +191,19 @@ fn a_discarded_pass_keeps_the_tombstone_until_a_settled_pass_publishes_the_inter
use std::sync::{Arc, Mutex};
let traces = Arc::new(Mutex::new(Vec::new()));
let seen = traces.clone();
let mut h =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1280.0, 800.0)).build_ui_state(
move |ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
seen.lock().unwrap().push((
app.ime_cancelled.is_some(),
app.ime_interrupt_pending,
app.ime_composition.is_none(),
ui.ctx().will_discard(),
));
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1280.0, 800.0)).build_ui_state(
move |ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
seen.lock().unwrap().push((
app.ime_cancelled.is_some(),
app.ime_interrupt_pending,
app.ime_composition.is_none(),
ui.ctx().will_discard(),
));
},
SlideApp::new(Session::with_new(), Services::default()),
);
h.run_steps(3);
let title = h.state().session.active().unwrap().doc.slides[0].shapes[0].id.0;
h.state_mut().run("text.edit", json!({"id": title})).unwrap();
+1 -1
View File
@@ -26,7 +26,7 @@ fn harness(tab: &str) -> (Harness<'static, SlideApp>, [ShapeId; 2]) {
s.execute("selection.select", &json!({"ids": [ids[0].0]})).unwrap();
let mut app = SlideApp::new(s, Services::default());
app.ui.tab = tab.into();
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1800.0, 900.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1800.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
+1 -12
View File
@@ -23,7 +23,6 @@ pub mod dialogs;
pub mod doc_window;
pub mod eyedropper;
pub mod flavor;
pub mod framework;
pub mod icons;
pub mod media;
pub mod menus;
@@ -268,11 +267,8 @@ pub struct SlideApp {
synthetic_generation: u64,
/// Document/slide/canvas identity the queued/injected batch belongs to.
synthetic_target: Option<InputTarget>,
/// Focus identity the pending batch was injected with (the document window counts as none); a focus change
/// retracts it.
/// Focus identity the pending batch was injected with; a focus change retracts it.
synthetic_focus: Option<egui::Id>,
/// The document window as a Tab stop, and when it takes the keyboard focus.
document_focus: app::DocumentFocus,
/// `RawInput::time` of the pass the batch was injected into. A logic-only callback leaves
/// `InputState` from the previous pass; comparing this value keeps retraction from draining
/// an unrelated batch out of that stale input.
@@ -304,11 +300,6 @@ pub struct SlideApp {
print_previews: app::files::PrintPreviews,
#[cfg(not(target_arch = "wasm32"))]
updates_rt: updates_ui::Runtime,
/// The framework dialogs (the update prompt and check result), run once per pass after the
/// app's own UI.
pub framework_dialogs: craft_ui::dialog::DialogHost,
/// Who DeckCraft is to the framework's dialogs.
framework_host: std::sync::Arc<craft_host::Host>,
/// Text for the system clipboard from a Copy or Cut command, handed over on the next frame.
pending_copy: Option<String>,
/// Bounded screenshot completion slots for the control channel (egui 0.37 callbacks).
@@ -463,8 +454,6 @@ mod browsetheme_tests;
#[cfg(test)]
mod compare_tests;
#[cfg(test)]
mod document_focus_tests;
#[cfg(test)]
mod eyedropper_tests;
#[cfg(test)]
mod field_frame_tests;
+14 -22
View File
@@ -42,17 +42,13 @@ fn play_on_the_editor_media_bar_plays_the_selected_clip() {
let r = s.execute("insert.audio", &json!({"name": "tone.wav", "data": deckcraft_engine::cmd::base64_encode(&wav(2.0))})).unwrap();
let id = ShapeId(r["id"].as_u64().unwrap() as u32);
let app = SlideApp::new(s, Services::default());
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(vec2(1400.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
let d = h.state().session.active().unwrap();
assert_eq!(d.selection.shapes, vec![id], "the inserted clip is selected");
@@ -92,17 +88,13 @@ fn the_media_bar_never_paints_or_clicks_into_the_notes_pane() {
let mut app = SlideApp::new(s, Services::default());
app.ui.notes = true;
app.ui.notes_height = 140.0;
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(vec2(1400.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
let notes = h.query_all_by_role(Role::MultilineTextInput).next().map(|n| n.rect()).expect("the notes field");
let canvas = h.state().canvas_rect.unwrap();
+8 -3
View File
@@ -128,9 +128,14 @@ pub fn palette(app: &mut SlideApp, ctx: &egui::Context) {
r.request_focus();
let q = query.to_lowercase();
let items = palette_items(&app.session, &q);
let (down, up, enter) =
ui.input(|i| (i.key_pressed(egui::Key::ArrowDown), i.key_pressed(egui::Key::ArrowUp), i.key_pressed(egui::Key::Enter)));
let esc = crate::framework::escape_pressed(ui.ctx());
let (down, up, enter, esc) = ui.input(|i| {
(
i.key_pressed(egui::Key::ArrowDown),
i.key_pressed(egui::Key::ArrowUp),
i.key_pressed(egui::Key::Enter),
i.key_pressed(egui::Key::Escape),
)
});
if down {
sel = (sel + 1).min(items.len().saturating_sub(1));
}
+15 -21
View File
@@ -116,7 +116,7 @@ impl SlideApp {
cancel = ui.button("Cancel").clicked();
});
});
if cancel || ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Escape)) || crate::framework::take_window_cancel(ctx) {
if cancel || ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Escape)) {
self.cancel_opening();
}
ctx.request_repaint_after(std::time::Duration::from_millis(100));
@@ -200,16 +200,13 @@ mod tests {
// A read that never answers: the window stays until Cancel.
let (_tx, rx) = std::sync::mpsc::channel();
app.opening = Some(Opening { path: "/decks/Big deck.pptx".into(), started_ms: crate::now_ms(), generation: 1, rx });
let mut harness = egui_kittest::Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1000.0, 700.0))
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1000.0, 700.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
harness.run_steps(3);
harness.get_by_label("Opening Big deck.pptx…");
harness.get_by_label("Cancel").click();
@@ -287,16 +284,13 @@ mod tests {
for leave in [egui::Key::Escape, egui::Key::ArrowRight] {
let mut app = SlideApp::new(Session::new(), crate::Services::default());
assert!(app.open_from_system(std::slice::from_ref(&path)).is_empty());
let mut harness = egui_kittest::Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1000.0, 700.0))
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1000.0, 700.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
harness.run_steps(3);
assert!(harness.state().show.is_some(), "the show is running");
if leave == egui::Key::ArrowRight {
+10 -11
View File
@@ -193,7 +193,7 @@ mod tests {
let mut app = SlideApp::new(s, Services::default());
app.ui.pane = Some("format".into());
app.ui.format_tab = "fill".into();
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
@@ -234,7 +234,7 @@ mod tests {
let mut app = SlideApp::new(s, Services::default());
app.ui.pane = Some("format".into());
app.ui.format_tab = "fill".into();
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
@@ -345,14 +345,13 @@ mod tests {
let mut app = SlideApp::new(s, Services::default());
app.ui.pane = Some("format".into());
app.ui.format_tab = "fill".into();
let mut h =
Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
h
};
@@ -400,7 +399,7 @@ mod tests {
let mut app = SlideApp::new(s, Services::default());
app.ui.pane = Some("format".into());
app.ui.format_tab = "fill".into();
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
+2 -2
View File
@@ -156,7 +156,7 @@ fn picture_background_options(app: &mut SlideApp, ui: &mut Ui, pf: &deckcraft_mo
};
ui.horizontal(|ui| {
let field = ui.add_sized(vec2(72.0, 20.0), egui::Label::new("Alignment"));
let combo = egui::ComboBox::from_id_salt("bg-align").selected_text(align_name).width(140.0).show_ui(ui, |ui| {
let combo = craft_ui::ComboBox::from_id_salt("bg-align").selected_text(align_name).width(140.0).show_ui(ui, |ui| {
for (k, l) in [
("tl", "Top Left"),
("t", "Top"),
@@ -183,7 +183,7 @@ fn picture_background_options(app: &mut SlideApp, ui: &mut Ui, pf: &deckcraft_mo
};
ui.horizontal(|ui| {
let field = ui.add_sized(vec2(72.0, 20.0), egui::Label::new("Mirror"));
let combo = egui::ComboBox::from_id_salt("bg-mirror").selected_text(mirror_name).width(140.0).show_ui(ui, |ui| {
let combo = craft_ui::ComboBox::from_id_salt("bg-mirror").selected_text(mirror_name).width(140.0).show_ui(ui, |ui| {
for (k, l) in [("none", "None"), ("x", "Horizontal"), ("y", "Vertical"), ("xy", "Both")] {
if ui.selectable_label(flip == k, l).clicked() {
run(app, "design.background", json!({"pictureProps": {"mirror": k}}));
@@ -15,7 +15,7 @@ const PNG: &str = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z
fn harness(mut app: SlideApp) -> Harness<'static, SlideApp> {
app.ui.tab = "Design".into();
app.ui.pane = Some("background".into());
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1800.0, 1100.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1800.0, 1100.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
@@ -17,7 +17,7 @@ fn harness() -> Harness<'static, SlideApp> {
let mut app = SlideApp::new(s, Services::default());
app.ui.pane = Some("format".into());
app.ui.format_tab = "effects".into();
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1800.0, 1100.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1800.0, 1100.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
+1 -1
View File
@@ -174,7 +174,7 @@ pub fn gradient_editor(ui: &mut Ui, id: &str, g: &Gradient, sc: &ColorScheme) ->
};
ui.horizontal(|ui| {
let field = ui.add_sized(vec2(70.0, 20.0), egui::Label::new("Type"));
let combo = egui::ComboBox::from_id_salt((id, "kind")).selected_text(kind).width(120.0).show_ui(ui, |ui| {
let combo = craft_ui::ComboBox::from_id_salt((id, "kind")).selected_text(kind).width(120.0).show_ui(ui, |ui| {
for k in ["Linear", "Radial", "Rectangular", "Path"] {
if ui.selectable_label(kind == k, k).clicked() && kind != k {
let focus = match &g.shape {
+4 -4
View File
@@ -218,7 +218,7 @@ fn size_tab(app: &mut SlideApp, ui: &mut Ui, sh: &deckcraft_model::Shape, x: dec
ui.horizontal(|ui| {
ui.add_sized(vec2(90.0, 20.0), egui::Label::new("From"));
let combo =
egui::ComboBox::from_id_salt("fmt-origin").selected_text(if center { "Center" } else { "Top Left Corner" }).show_ui(ui, |ui| {
craft_ui::ComboBox::from_id_salt("fmt-origin").selected_text(if center { "Center" } else { "Top Left Corner" }).show_ui(ui, |ui| {
ui.selectable_value(&mut center, false, "Top Left Corner");
ui.selectable_value(&mut center, true, "Center");
});
@@ -493,7 +493,7 @@ fn line_choice(app: &mut SlideApp, ui: &mut Ui, label: &str, key: &str, current:
ui.horizontal(|ui| {
let field = ui.add_sized(vec2(90.0, 20.0), egui::Label::new(label));
let shown = items.iter().find(|(_, v)| *v == current).map_or(current, |(l, _)| *l);
let combo = egui::ComboBox::from_id_salt(("fmt-line", key)).selected_text(shown).width(120.0).show_ui(ui, |ui| {
let combo = craft_ui::ComboBox::from_id_salt(("fmt-line", key)).selected_text(shown).width(120.0).show_ui(ui, |ui| {
for (l, v) in items {
if ui.selectable_label(*v == current, *l).clicked() {
run(app, "shape.line", json!({key: v}));
@@ -653,7 +653,7 @@ fn picture_fill_options(app: &mut SlideApp, ui: &mut Ui, id: u32, pf: &deckcraft
ui.horizontal(|ui| {
let field = ui.add_sized(vec2(90.0, 20.0), egui::Label::new(label));
let shown = opts.iter().find(|(k, _)| k == cur).map_or(opts[0].1, |(_, l)| *l);
let combo = egui::ComboBox::from_id_salt(("picfill", id, key)).selected_text(shown).show_ui(ui, |ui| {
let combo = craft_ui::ComboBox::from_id_salt(("picfill", id, key)).selected_text(shown).show_ui(ui, |ui| {
for (k, l) in opts {
if ui.selectable_label(*k == cur.as_str(), *l).clicked() {
run(app, "shape.fill", json!({"pictureProps": {key: k}}));
@@ -705,7 +705,7 @@ fn preset_label(name: &str) -> String {
fn three_d_combo(app: &mut SlideApp, ui: &mut Ui, id: u32, label: &str, key: &str, cur: &str, options: &[&str]) {
ui.horizontal(|ui| {
let field = ui.add_sized(vec2(90.0, 20.0), egui::Label::new(label));
let combo = egui::ComboBox::from_id_salt(("3d", id, key)).selected_text(preset_label(cur)).width(170.0).show_ui(ui, |ui| {
let combo = craft_ui::ComboBox::from_id_salt(("3d", id, key)).selected_text(preset_label(cur)).width(170.0).show_ui(ui, |ui| {
for o in options {
if ui.selectable_label(*o == cur, preset_label(o)).clicked() {
run(app, "shape.effects", json!({"threeD": {key: o}}));
@@ -15,7 +15,7 @@ use crate::{Services, SlideApp};
fn harness(mut app: SlideApp, pane: &str) -> Harness<'static, SlideApp> {
app.ui.pane = Some(pane.into());
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1800.0, 1100.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1800.0, 1100.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
+3 -3
View File
@@ -216,7 +216,7 @@ pub fn show(app: &mut SlideApp, ui: &mut Ui) {
}
app.selpane.rename_started = true;
}
let (enter, esc) = (ui.input(|i| i.key_pressed(egui::Key::Enter)), crate::framework::escape_pressed(ui.ctx()));
let (enter, esc) = ui.input(|i| (i.key_pressed(egui::Key::Enter), i.key_pressed(egui::Key::Escape)));
if out.lost_focus() || enter || esc {
app.selpane.renaming = None;
app.selpane.rename_started = false;
@@ -342,16 +342,16 @@ fn click(app: &mut SlideApp, rows: &[Row], k: usize, ctrl: bool, shift: bool) {
}
fn keys(app: &mut SlideApp, ui: &Ui, rows: &[Row], selected: &[u32], focused: u32) {
let (up, down, home, end, f2) = ui.input(|i| {
let (up, down, home, end, f2, esc) = ui.input(|i| {
(
i.key_pressed(egui::Key::ArrowUp),
i.key_pressed(egui::Key::ArrowDown),
i.key_pressed(egui::Key::Home),
i.key_pressed(egui::Key::End),
i.key_pressed(egui::Key::F2),
i.key_pressed(egui::Key::Escape),
)
});
let esc = crate::framework::escape_pressed(ui.ctx());
let cur = selected.last().and_then(|id| rows.iter().position(|r| r.id == *id));
let to = if up {
Some(cur.map(|c| c.saturating_sub(1)).unwrap_or(0))
+7 -11
View File
@@ -26,17 +26,13 @@ fn harness() -> (Harness<'static, SlideApp>, Vec<u32>) {
ids.push(g);
let mut app = SlideApp::new(s, Services::default());
app.ui.pane = Some("selection".into());
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1400.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
(h, ids)
}
+5 -8
View File
@@ -8,7 +8,7 @@ pub(super) fn smartart(app: &mut SlideApp, ui: &mut Ui) {
return;
};
let texts: Vec<String> = d.nodes.iter().map(|n| n.text.clone()).collect();
let focused_any = crate::framework::widget_has_keyboard(ui.ctx()) || app.ui.smartart_focus.is_some();
let focused_any = ui.ctx().memory(|m| m.focused().is_some()) || app.ui.smartart_focus.is_some();
if app.ui.smartart_drafts.0 != gid.0 || app.ui.smartart_drafts.1.len() != texts.len() || !focused_any {
app.ui.smartart_drafts = (gid.0, texts.clone());
}
@@ -24,8 +24,7 @@ pub(super) fn smartart(app: &mut SlideApp, ui: &mut Ui) {
ui.horizontal(|ui| {
ui.add_space(16.0 * node.level as f32);
ui.label("•");
// The line keeps Tab for its own command; Escape leaves it.
let te = egui::TextEdit::singleline(draft).id(id).hint_text("Diagram text").desired_width(f32::INFINITY).lock_focus(true);
let te = egui::TextEdit::singleline(draft).id(id).hint_text("Diagram text").desired_width(f32::INFINITY);
let r = ui.add(te);
if app.ui.smartart_focus == Some(i) {
r.request_focus();
@@ -40,15 +39,13 @@ pub(super) fn smartart(app: &mut SlideApp, ui: &mut Ui) {
action = Some(("smartArt.removeNode", json!({"index": i})));
focus_row = Some(i.saturating_sub(1));
}
}
if r.lost_focus() {
let (tab, shift) = ui.input(|inp| (inp.key_pressed(egui::Key::Tab), inp.modifiers.shift));
if tab {
action = Some((if shift { "smartArt.promote" } else { "smartArt.demote" }, json!({"index": i})));
focus_row = Some(i);
commit = Some(i);
}
}
if r.lost_focus() {
if ui.input(|inp| inp.key_pressed(egui::Key::Enter)) {
} else if ui.input(|inp| inp.key_pressed(egui::Key::Enter)) {
action = Some(("smartArt.addNode", json!({"index": i, "position": "after"})));
focus_row = Some(i + 1);
}
+21 -33
View File
@@ -25,17 +25,13 @@ fn text_pane_types_adds_and_demotes() {
s.execute("insert.smartArt", &json!({"kind": "list", "items": ["Plan", "Build"]})).unwrap();
let mut app = SlideApp::new(s, Services::default());
app.ui.pane = Some("smartart".into());
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1400.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
assert!(h.query_by_label("Text Pane").is_some());
@@ -62,17 +58,13 @@ fn home_convert_to_smartart_gallery_converts_the_text() {
s.execute("slide.new", &json!({"layout": "blank"})).unwrap();
s.execute("insert.textBox", &json!({"text": "Goals\nRevenue\nGrowth"})).unwrap();
let app = SlideApp::new(s, Services::default());
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1600.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
h.get_by_label("Convert to Diagram").click();
h.run_steps(3);
@@ -92,17 +84,13 @@ fn layout_gallery_shows_cached_pictures_and_previews_on_hover() {
s.execute("insert.smartArt", &json!({"kind": "process", "items": ["Plan", "Build", "Ship"]})).unwrap();
let mut app = SlideApp::new(s, Services::default());
app.ui.tab = "SmartArt Design".into();
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1600.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
h.get_by_label("Layouts").click();
h.run_steps(3);
+7 -11
View File
@@ -18,17 +18,13 @@ fn thesaurus_pane_swaps_the_word_at_the_caret() {
s.execute("text.edit", &json!({"id": id, "at": [0, 6]})).unwrap();
let mut app = SlideApp::new(s, Services::default());
app.ui.tab = "Review".into();
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1400.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
h.get_by_label("Thesaurus").click();
h.run_steps(3);
+8 -12
View File
@@ -437,7 +437,7 @@ mod tests {
use deckcraft_engine::Session;
fn harness() -> Harness<'static, SlideApp> {
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
@@ -506,17 +506,13 @@ mod tests {
while s.doc().unwrap().doc.slides.len() < slides {
s.execute("slide.new", &json!({})).unwrap();
}
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1200.0, 1600.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(s, Services::default()),
);
let mut h = Harness::builder().with_size(egui::vec2(1200.0, 1600.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(s, Services::default()),
);
h.run_steps(3);
let ids = order(&h);
(h, ids)
+2 -2
View File
@@ -23,7 +23,7 @@ fn reflection_none_clears_after_a_second_preset() {
let mut app = SlideApp::new(s, Services::default());
app.ui.pane = Some("format".into());
app.ui.format_tab = "effects".into();
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
@@ -51,7 +51,7 @@ fn reflection_none_stays_cleared_when_a_slider_only_had_focus() {
let mut app = SlideApp::new(s, Services::default());
app.ui.pane = Some("format".into());
app.ui.format_tab = "effects".into();
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
+7 -11
View File
@@ -19,17 +19,13 @@ fn harness() -> Harness<'static, SlideApp> {
// The product's default window. The Home ribbon overflows here with the bundled interface
// fonts; the ribbon's own edge chevron must make its Editing group reachable instead of the
// regression widening the fixture past the width the app actually opens at.
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1440.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
h
}
+7 -11
View File
@@ -32,17 +32,13 @@ fn harness(file: &Rc<RefCell<Vec<u8>>>) -> Harness<'static, SlideApp> {
..Services::default()
};
let app = SlideApp::new(s, services);
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1400.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
h
}
@@ -13,7 +13,7 @@ fn harness(size: egui::Vec2) -> Harness<'static, SlideApp> {
session.execute("edit.select", &json!({"ids": [id]})).unwrap();
let mut app = SlideApp::new(session, Services::default());
app.ui.tab = "Animations".into();
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(size).with_step_dt(1.0 / 60.0).build_ui_state(
let mut h = Harness::builder().with_size(size).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
+1 -1
View File
@@ -26,7 +26,7 @@ fn harness(select: &[usize]) -> (Harness<'static, SlideApp>, Vec<ShapeId>) {
s.execute("selection.select", &json!({"ids": picked})).unwrap();
let mut app = SlideApp::new(s, Services::default());
app.ui.tab = "Shape Format".into();
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1800.0, 900.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1800.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
+7 -11
View File
@@ -35,17 +35,13 @@ fn draw_a_table_split_it_and_erase_the_border() {
s.execute("slide.new", &json!({"layout": "blank"})).unwrap();
let mut app = SlideApp::new(s, Services::default());
app.ui.tab = "Insert".into();
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1400.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
h.get_by_label("Table").click();
h.run_steps(2);
+1 -1
View File
@@ -9,7 +9,7 @@ use crate::{Services, SlideApp};
fn harness() -> Harness<'static, SlideApp> {
let mut app = SlideApp::new(Session::with_new(), Services::default());
app.ui.tab = "Design".into();
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1800.0, 900.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1800.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
@@ -11,7 +11,7 @@ use crate::{Services, SlideApp};
fn clicking_inside_the_icons_popup_keeps_it_open() {
let mut app = SlideApp::new(Session::with_new(), Services::default());
app.ui.tab = "Insert".into();
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1800.0, 900.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1800.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
+7 -11
View File
@@ -16,17 +16,13 @@ fn pen_a_rectangle_then_ink_to_shape() {
s.execute("slide.new", &json!({"layout": "blank"})).unwrap();
let mut app = SlideApp::new(s, Services::default());
app.ui.tab = "Draw".into();
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1400.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
h.get_by_label("Black Pen").click();
h.run_steps(2);
@@ -11,7 +11,7 @@ use serde_json::json;
use crate::{Services, SlideApp};
fn harness(app: SlideApp) -> Harness<'static, SlideApp> {
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1800.0, 900.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1800.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
@@ -22,7 +22,7 @@ fn picture_format(width: f32) -> (Harness<'static, SlideApp>, ShapeId) {
s.execute("edit.select", &json!({"ids": [id]})).unwrap();
let mut app = SlideApp::new(s, Services::default());
app.ui.tab = "Picture Format".into();
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(width, 900.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(width, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
+1 -1
View File
@@ -82,7 +82,7 @@ pub(super) fn transitions(app: &mut SlideApp, ui: &mut Ui) {
.and_then(|t| t.sound)
.and_then(|m| app.session.active().and_then(|d| d.doc.media(m).map(|i| i.name.trim_end_matches(".wav").to_string())))
.unwrap_or_else(|| if stop { "[Stop Previous Sound]".into() } else { "[No Sound]".into() });
let combo = egui::ComboBox::from_id_salt("transition_sound").width(140.0).selected_text(name).show_ui(ui, |ui| {
let combo = craft_ui::ComboBox::from_id_salt("transition_sound").width(140.0).selected_text(name).show_ui(ui, |ui| {
let none = cur.as_ref().is_none_or(|t| t.sound.is_none() && !t.stop_sound);
if ui.selectable_label(none, "[No Sound]").clicked() {
run(app, "transition.sound", json!({"none": true}));
+7 -10
View File
@@ -157,16 +157,13 @@ mod tests {
let mut app = crate::SlideApp::new(deckcraft_engine::Session::with_new(), crate::Services::default());
// The second case is not sanitized: the canvas keeps a stray zoom in range itself.
app.ui = ui;
let mut h = egui_kittest::Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1200.0, 800.0))
.build_ui_state(
|ui, app: &mut crate::SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut crate::SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(4);
assert!(h.state().canvas_scale <= *crate::ZOOM_RANGE.end() + 1e-3, "{}", h.state().canvas_scale);
}
+1 -4
View File
@@ -6,15 +6,12 @@ use super::{Color32, Presentation, Show, ShowAction};
/// audience window and Presenter View use this path, including animation steps and end-of-show.
/// `presenter` is true for Presenter View, where G opens that window's own grid (#1130).
pub(super) fn keyboard(ctx: &egui::Context, show: &mut Show, doc: &Presentation, now: f64, presenter: bool) -> bool {
let mut keys: Vec<(egui::Key, egui::Modifiers)> = ctx.input(|i| {
let keys: Vec<(egui::Key, egui::Modifiers)> = ctx.input(|i| {
i.events
.iter()
.filter_map(|e| if let egui::Event::Key { key, pressed: true, modifiers, .. } = e { Some((*key, *modifiers)) } else { None })
.collect()
});
if crate::framework::window_escape(ctx) {
keys.push((egui::Key::Escape, egui::Modifiers::NONE));
}
let (keep, consumed) = handle_keys(show, doc, now, keys, presenter);
for (key, modifiers) in consumed {
ctx.input_mut(|i| i.consume_key(modifiers, key));
+71 -92
View File
@@ -35,17 +35,13 @@ fn a_still_cursor_hides_over_a_clickable_shape() {
let r = session.execute("shape.insert", &json!({"preset": "rect", "rect": [0.0, 0.0, size.width, size.height]})).unwrap();
session.execute("insert.hyperlink", &json!({"url": "https://example.org", "ids": [r["id"]]})).unwrap();
let app = SlideApp::new(session, crate::Services::default());
let mut harness = egui_kittest::Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(vec2(1000.0, 700.0))
.with_step_dt(0.25)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut harness = egui_kittest::Harness::builder().with_size(vec2(1000.0, 700.0)).with_step_dt(0.25).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
harness.run_steps(3);
harness.state_mut().start_show(0, false);
harness.run_steps(2);
@@ -69,17 +65,13 @@ fn keep_cursor_visible_leaves_a_still_cursor_over_a_link() {
let mut app = SlideApp::new(session, crate::Services::default());
app.ui.presenter_view = false;
app.run("show.keepCursor", json!({"on": true})).unwrap();
let mut harness = egui_kittest::Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(vec2(1000.0, 700.0))
.with_step_dt(0.25)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut harness = egui_kittest::Harness::builder().with_size(vec2(1000.0, 700.0)).with_step_dt(0.25).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
harness.run_steps(3);
harness.state_mut().start_show(0, false);
harness.run_steps(2);
@@ -98,14 +90,13 @@ fn set_up_slide_show_keeps_the_cursor_visible() {
use egui_kittest::kittest::Queryable;
let app = SlideApp::new(deckcraft_engine::Session::with_new(), crate::Services::default());
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut harness = egui_kittest::Harness::builder().with_size(vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
for on in [true, false] {
harness.state_mut().run("app.dialog", json!({"id": "setupShow"})).unwrap();
harness.run_steps(6);
@@ -213,19 +204,18 @@ fn show_with_clip() -> (egui_kittest::Harness<'static, SlideApp>, ShapeId, Pos2,
// Presenter view opens an embedded window over the whole screen here, which takes the clicks.
let mut app = SlideApp::new(session, crate::Services::default());
app.ui.presenter_view = false;
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(size).with_step_dt(0.25).build_ui_state(
move |ui, app: &mut SlideApp| {
app.logic(ui.ctx());
if let (Some(show), Some(d)) = (app.show.as_ref(), app.session.active()) {
let now = ui.input(|i| i.time);
seen.set(pointer_on_media_bar(ui.ctx(), ui, &d.doc, show, now));
slide_seen.set(shown_slide_rect(ui, show, &d.doc));
}
app.ui(ui);
},
app,
);
let mut harness = egui_kittest::Harness::builder().with_size(size).with_step_dt(0.25).build_ui_state(
move |ui, app: &mut SlideApp| {
app.logic(ui.ctx());
if let (Some(show), Some(d)) = (app.show.as_ref(), app.session.active()) {
let now = ui.input(|i| i.time);
seen.set(pointer_on_media_bar(ui.ctx(), ui, &d.doc, show, now));
slide_seen.set(shown_slide_rect(ui, show, &d.doc));
}
app.ui(ui);
},
app,
);
harness.run_steps(3);
harness.state_mut().start_show(0, false);
harness.run_steps(2);
@@ -314,20 +304,16 @@ fn show_with_gif() -> (egui_kittest::Harness<'static, SlideApp>, ShapeId, Pos2)
let slide_seen = slide.clone();
let mut app = SlideApp::new(session, crate::Services::default());
app.ui.presenter_view = false;
let mut harness = egui_kittest::Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(vec2(1000.0, 700.0))
.with_step_dt(0.25)
.build_ui_state(
move |ui, app: &mut SlideApp| {
app.logic(ui.ctx());
if let (Some(show), Some(d)) = (app.show.as_ref(), app.session.active()) {
slide_seen.set(shown_slide_rect(ui, show, &d.doc));
}
app.ui(ui);
},
app,
);
let mut harness = egui_kittest::Harness::builder().with_size(vec2(1000.0, 700.0)).with_step_dt(0.25).build_ui_state(
move |ui, app: &mut SlideApp| {
app.logic(ui.ctx());
if let (Some(show), Some(d)) = (app.show.as_ref(), app.session.active()) {
slide_seen.set(shown_slide_rect(ui, show, &d.doc));
}
app.ui(ui);
},
app,
);
harness.run_steps(3);
harness.state_mut().start_show(1, false);
harness.run_steps(2);
@@ -429,14 +415,13 @@ fn slideshow_navigation_advances_once_with_presenter_view() {
session.execute("slide.new", &json!({})).unwrap();
let mut app = SlideApp::new(session, crate::Services::default());
app.ui.presenter_view = true;
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(vec2(1000.0, 700.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut harness = egui_kittest::Harness::builder().with_size(vec2(1000.0, 700.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
harness.run_steps(3);
harness.state_mut().start_show(0, false);
harness.run_steps(2);
@@ -825,17 +810,13 @@ fn show_of_three() -> egui_kittest::Harness<'static, SlideApp> {
session.execute("slide.new", &json!({})).unwrap();
let mut app = SlideApp::new(session, crate::Services::default());
app.ui.presenter_view = false;
let mut harness = egui_kittest::Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(vec2(1000.0, 700.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut harness = egui_kittest::Harness::builder().with_size(vec2(1000.0, 700.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
harness.run_steps(3);
harness.state_mut().start_show(0, false);
harness.run_steps(2);
@@ -1108,14 +1089,13 @@ fn back_leaves_a_slide_whose_first_animation_is_with_previous() {
.execute("animation.add", &json!({"effect": "fade", "class": "entrance", "ids": [id.0], "start": "withPrevious", "duration": 500}))
.unwrap();
let app = SlideApp::new(session, crate::Services::default());
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(vec2(1000.0, 700.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut harness = egui_kittest::Harness::builder().with_size(vec2(1000.0, 700.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
harness.run_steps(3);
harness.state_mut().start_show(0, false);
harness.run_steps(2);
@@ -1216,14 +1196,13 @@ fn remote_presenter_uses_the_audience_state_and_closes_with_the_show() {
let services = crate::Services { presenter: Some(Box::new(Mock(bridge.clone()))), ..Default::default() };
let mut app = SlideApp::new(session, services);
app.ui.presenter_view = true;
let mut h =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(vec2(1000.0, 700.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = egui_kittest::Harness::builder().with_size(vec2(1000.0, 700.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
h.state_mut().start_show(0, false);
h.run_steps(2);
+1 -1
View File
@@ -18,7 +18,7 @@ fn open_with_size(w: f64, h: f64) -> egui_kittest::Harness<'static, SlideApp> {
let mut s = Session::new();
s.execute("file.open", &json!({"path": path.to_string_lossy()})).unwrap();
let _ = std::fs::remove_file(&path);
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1280.0, 800.0)).build_ui_state(
egui_kittest::Harness::builder().with_size(egui::vec2(1280.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
+1 -6
View File
@@ -110,7 +110,7 @@ fn section_header(app: &mut SlideApp, ui: &mut Ui, h: &Header<'_>) -> Rect {
}
app.sorter.rename_started = true;
}
let (enter, esc) = (ui.input(|i| i.key_pressed(egui::Key::Enter)), crate::framework::escape_pressed(ui.ctx()));
let (enter, esc) = ui.input(|i| (i.key_pressed(egui::Key::Enter), i.key_pressed(egui::Key::Escape)));
// The frame that asks for focus has not had it yet; committing then would cancel the rename.
if already && (out.lost_focus() || enter || esc) {
app.sorter.renaming = None;
@@ -278,8 +278,6 @@ pub fn show(app: &mut SlideApp, ui: &mut Ui) {
let multi = st.selection.slides.clone();
let zoom = app.ui.sorter_zoom.clamp(0.5, 3.0);
let grouped = groups(&doc);
// Behind the thumbnails, which take the presses: the document's Tab stop and key target.
app.document_behind(ui, ui.available_rect_before_wrap());
egui::ScrollArea::vertical().auto_shrink([false, false]).show(ui, |ui| {
ui.add_space(12.0);
ui.horizontal(|ui| {
@@ -365,9 +363,6 @@ pub fn notes_page(app: &mut SlideApp, ui: &mut Ui) {
let t = Tokens::get(ui.ctx());
let avail = ui.available_rect_before_wrap();
ui.painter().rect_filled(avail, CornerRadius::ZERO, t.canvas);
if app.session.active().is_some() {
app.document_widget(ui, avail, Sense::click());
}
let Some(st) = app.session.active() else { return };
let doc = st.doc.clone();
let idx = st.selection.slide;
+7 -11
View File
@@ -19,17 +19,13 @@ fn harness(with_sections: bool) -> Harness<'static, SlideApp> {
}
let mut app = SlideApp::new(s, Services::default());
app.ui.view = crate::ViewMode::Sorter;
let mut h = Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1400.0, 900.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
h
}
+1 -1
View File
@@ -23,7 +23,7 @@ fn harness(tab: &str) -> (Harness<'static, SlideApp>, [ShapeId; 2]) {
s.execute("selection.select", &json!({"ids": [ids[0].0, ids[1].0]})).unwrap();
let mut app = SlideApp::new(s, Services::default());
app.ui.tab = tab.into();
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1800.0, 900.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1800.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
+2 -2
View File
@@ -332,7 +332,7 @@ mod tests {
app.session.execute("format.language", &json!({"lang": "en-US-x-a-very-long-private-use-tag"})).unwrap();
app.ui.notes = false;
let size = egui::vec2(700.0, 800.0);
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(size).build_ui_state(
let mut h = Harness::builder().with_size(size).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
@@ -379,7 +379,7 @@ mod tests {
/// hear which view button is on, and read the slide counter and the status message.
#[test]
fn status_bar_controls_have_names() {
let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
let mut h = Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
+209 -274
View File
@@ -13,14 +13,13 @@ fn shape_rot(app: &SlideApp) -> f64 {
/// letting go is one undo step. Off the canvas it does nothing.
#[test]
fn a_trackpad_twist_rotates_the_shape_under_the_canvas() {
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
harness.run_steps(2);
let id = harness.state_mut().session.execute("shape.insert", &json!({"preset": "rect", "rect": [80.0, 80.0, 100.0, 60.0]})).unwrap();
let id = id.get("id").and_then(|v| v.as_u64()).unwrap();
@@ -118,14 +117,13 @@ fn title_text(app: &SlideApp) -> String {
#[test]
fn quick_access_toolbar_adds_removes_resets_and_persists() {
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
harness.run_steps(2);
let ids = |app: &SlideApp| app.ui.qat.iter().map(|q| q.id.clone()).collect::<Vec<_>>();
assert_eq!(ids(harness.state()), ["app.home", "file.save", "app.exportDialog", "edit.undo", "edit.redo", "show.fromStart"]);
@@ -181,14 +179,13 @@ fn opening_a_file_with_missing_fonts_shows_a_toast_once() {
body.paragraphs[0].runs[0].props.font = Some("Qqq Nonexistent Sans".into());
slide.shapes[0].text = Some(body);
let data = deckcraft_engine::cmd::base64_encode(&deckcraft_engine::cmd::file::save_bytes(&p, "pptx").unwrap());
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
harness.run_steps(2);
assert!(harness.state().toast.is_none(), "a new presentation has nothing to say");
harness.state_mut().session.execute("file.openBytes", &json!({"name": "a.pptx", "data": data})).unwrap();
@@ -257,14 +254,13 @@ fn change_picture_replaces_the_selected_picture() {
/// #17: Home created a new blank presentation instead of going to the start screen.
#[test]
fn home_shows_the_start_screen_over_the_open_presentation() {
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
// The app keeps requesting repaints, so step frames instead of run().
harness.run_steps(2);
let title = harness.state().session.active().unwrap().doc.slides[0].shapes[0].id.0;
@@ -306,14 +302,13 @@ fn ctrl_word_keys_edit_text() {
let mut session = Session::with_new();
session.mac_keys = false;
session.prefs.autocorrect = false;
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(session, Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(session, Services::default()),
);
harness.run_steps(2);
let title = harness.state().session.active().unwrap().doc.slides[0].shapes[0].id.0;
harness.state_mut().session.execute("text.edit", &json!({"id": title})).unwrap();
@@ -385,14 +380,13 @@ fn ctrl_word_keys_edit_text() {
/// Export… had no visible control: only the command palette reached it.
#[test]
fn title_bar_export_opens_the_export_dialog() {
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
harness.run_steps(2);
assert!(harness.state().dialog.is_none());
// Quick access: Home, Save, Export, each 24 points wide with 2 between, from x = 10.
@@ -430,16 +424,13 @@ fn ctrl_v_pastes_the_picture_a_browser_copied_not_its_link() {
clipboard_html: Some(Box::new(move || html.clone())),
..Default::default()
};
let mut harness = egui_kittest::Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1200.0, 800.0))
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(session, services),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(session, services),
);
harness.run_steps(2);
let shapes_before = harness.state().session.active().unwrap().doc.slides[0].shapes.len();
harness.event(egui::Event::Paste(text.clone()));
@@ -467,14 +458,13 @@ fn ctrl_v_pastes_an_image_when_no_paste_event_arrives() {
};
assert!(!png.is_empty());
let services = Services { clipboard_image: Some(Box::new(move || Some(png.clone()))), ..Default::default() };
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(session, services),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(session, services),
);
harness.run_steps(2);
let pictures = |app: &SlideApp| {
let d = app.session.active().unwrap();
@@ -500,18 +490,17 @@ fn ctrl_v_pastes_an_image_when_no_paste_event_arrives() {
/// #78: after Tab in a text box, typing and deleting no longer reached the text.
#[test]
fn typing_goes_on_after_tab_in_a_text_box() {
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
{
let mut session = Session::with_new();
session.prefs.autocorrect = false;
SlideApp::new(session, Services::default())
},
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
{
let mut session = Session::with_new();
session.prefs.autocorrect = false;
SlideApp::new(session, Services::default())
},
);
harness.run_steps(2);
let title = harness.state().session.active().unwrap().doc.slides[0].shapes[0].id.0;
harness.state_mut().session.execute("text.edit", &json!({"id": title})).unwrap();
@@ -544,14 +533,13 @@ fn typing_goes_on_after_tab_in_a_text_box() {
/// list could neither be typed into nor continued with Enter.
#[test]
fn tab_in_an_edited_list_keeps_the_keyboard() {
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
harness.run_steps(2);
let title = harness.state().session.active().unwrap().doc.slides[0].shapes[0].id.0;
harness.state_mut().session.execute("text.edit", &json!({"id": title})).unwrap();
@@ -649,14 +637,13 @@ fn grid_options_sets_spacing_and_display_or_opens_the_dialog() {
#[test]
fn grid_options_dialog_lists_spacing_and_display() {
use egui_kittest::kittest::Queryable;
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
harness.run_steps(2);
harness.state_mut().run("view.gridOptions", json!({})).unwrap();
harness.run_steps(2);
@@ -693,14 +680,13 @@ fn grid_options_dialog_lists_spacing_and_display() {
#[test]
fn preferences_cancel_restores_the_settings_done_keeps_them() {
use egui_kittest::kittest::Queryable;
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
harness.run_steps(2);
let before = harness.state().session.prefs.clone();
let dark_before = harness.state().ui.brightness;
@@ -754,14 +740,13 @@ fn preferences_cancel_restores_the_settings_done_keeps_them() {
#[test]
fn about_dialog_close_and_cancel_close_it() {
use egui_kittest::kittest::Queryable;
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
harness.run_steps(2);
harness.state_mut().run("app.about", json!({})).unwrap();
harness.run_steps(2);
@@ -787,14 +772,13 @@ fn about_dialog_close_and_cancel_close_it() {
}
fn canvas_harness() -> egui_kittest::Harness<'static, SlideApp> {
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
harness.run_steps(2);
let app = harness.state_mut();
// Zoomed out, the canvas shows plenty of pasteboard around the slide.
@@ -896,14 +880,13 @@ fn the_canvas_renders_only_the_slide_when_nothing_is_off_it() {
/// Ctrl+X do.
#[test]
fn copy_and_cut_commands_reach_the_system_clipboard() {
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
harness.run_steps(2);
let copied = |h: &egui_kittest::Harness<'_, SlideApp>| {
h.output().platform_output.commands.iter().find_map(|c| match c {
@@ -934,14 +917,13 @@ fn copy_and_cut_commands_reach_the_system_clipboard() {
/// egui-winit drops Ctrl+V when the system clipboard is empty; the context menu worked.
#[test]
fn copy_then_paste_shortcut_duplicates_an_object_without_text() {
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
harness.run_steps(2);
harness.state_mut().session.execute("shape.insert", &json!({"preset": "rect", "rect": [10, 10, 50, 50]})).unwrap();
let count = |h: &egui_kittest::Harness<'_, SlideApp>| h.state().session.doc().unwrap().current_slide().unwrap().shapes.len();
@@ -964,14 +946,13 @@ fn copy_then_paste_shortcut_duplicates_an_object_without_text() {
/// canvas focused it still selects shapes.
#[test]
fn select_all_follows_the_focused_pane() {
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
harness.run_steps(2);
for _ in 0..2 {
harness.state_mut().run("slide.new", json!({})).unwrap();
@@ -1004,7 +985,7 @@ fn select_all_follows_the_focused_pane() {
}
fn harness() -> egui_kittest::Harness<'static, SlideApp> {
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
@@ -1013,24 +994,6 @@ fn harness() -> egui_kittest::Harness<'static, SlideApp> {
)
}
/// With the framework runtime installed, the window's keys still reach DeckCraft's own routing: Alt+1 runs the
/// first Quick Access Toolbar item (Alt+numpad code entry leaves the claimed chord alone off macOS), and Escape with
/// nothing focused leaves the File tab.
#[test]
fn alt_digit_and_escape_reach_the_app_through_the_runtime() {
let mut h = harness();
h.state_mut().run("file.new", json!({})).unwrap();
h.state_mut().session.mac_keys = false;
h.run_steps(3);
assert!(!h.state().backstage_open());
h.key_press_modifiers(egui::Modifiers::ALT, egui::Key::Num1);
h.run_steps(2);
assert!(h.state().backstage_open(), "Alt+1 runs app.home, which opens the File tab");
h.key_press(egui::Key::Escape);
h.run_steps(2);
assert!(!h.state().backstage_open(), "Escape leaves the File tab");
}
/// #172: a recent file that no longer exists is marked on File › Home, and clicking it draws
/// the open error right there (the status bar is hidden while the backstage is open, so the
/// message used to vanish).
@@ -1090,14 +1053,13 @@ fn recent_exists_tells_missing_from_present() {
#[test]
fn the_language_dialog_marks_the_selected_text() {
use egui_kittest::kittest::Queryable;
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
harness.run_steps(2);
let title = harness.state().session.active().unwrap().doc.slides[0].shapes[0].id.0;
harness.state_mut().session.execute("text.edit", &json!({"id": title})).unwrap();
@@ -1121,14 +1083,13 @@ fn the_language_dialog_marks_the_selected_text() {
#[test]
fn the_language_dialog_marks_the_whole_presentation() {
use egui_kittest::kittest::Queryable;
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
harness.run_steps(2);
let s = &mut harness.state_mut().session;
let title = s.active().unwrap().doc.slides[0].shapes[0].id.0;
@@ -1158,14 +1119,13 @@ fn the_language_dialog_marks_the_whole_presentation() {
#[test]
fn the_language_dialog_marks_the_whole_presentation_with_nothing_selected() {
use egui_kittest::kittest::{NodeT, Queryable};
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
harness.run_steps(2);
let s = &mut harness.state_mut().session;
let title = s.active().unwrap().doc.slides[0].shapes[0].id.0;
@@ -1219,14 +1179,13 @@ fn editing_notes_in_the_pane_keeps_their_formatting() {
};
let mut session = Session::with_new();
session.execute("slide.notes", &json!({"index": 0, "body": notes})).unwrap();
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(session, Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(session, Services::default()),
);
harness.run_steps(2);
let id = egui::Id::unique("notes_edit");
let caret = |h: &mut egui_kittest::Harness<'_, SlideApp>, at: usize| {
@@ -1274,14 +1233,13 @@ fn editing_notes_in_the_pane_keeps_their_formatting() {
}
fn step_app(services: Services) -> egui_kittest::Harness<'static, SlideApp> {
let mut h =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), services),
);
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), services),
);
h.run_steps(2);
h
}
@@ -1436,17 +1394,13 @@ fn preview_hides_an_entrance_until_it_plays() {
#[test]
fn animation_preview_plays_on_the_canvas_then_stops() {
let mut harness = egui_kittest::Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1200.0, 800.0))
.with_step_dt(0.05)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).with_step_dt(0.05).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
harness.run_steps(2);
let none = harness.state_mut().run("animation.preview", json!({})).unwrap();
assert_eq!(none["playing"], false);
@@ -1507,17 +1461,13 @@ fn animation_preview_plays_on_the_canvas_then_stops() {
}
fn flick_harness() -> egui_kittest::Harness<'static, SlideApp> {
let mut harness = egui_kittest::Harness::builder()
.with_context_setup(crate::framework::install_headless)
.with_size(egui::vec2(1200.0, 800.0))
.with_step_dt(1.0 / 60.0)
.build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
harness.run_steps(2);
// Fitted: the slide is smaller than the window, so a flick turns the page instead of panning.
harness.state_mut().ui.zoom = Some(0.4);
@@ -1791,14 +1741,13 @@ fn the_pen_ignores_a_swipe_during_the_show() {
/// until the pointer lets go, so the slider doesn't grow under the pointer mid-drag.
#[test]
fn interface_size_applies_when_the_slider_is_let_go() {
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
harness.run_steps(2);
harness.state_mut().run("app.preferences", json!({})).unwrap();
harness.run_steps(4);
@@ -1826,7 +1775,7 @@ fn interface_size_applies_when_the_slider_is_let_go() {
#[test]
fn status_zoom_slider_is_named_without_growing_the_status_bar() {
for size in [egui::vec2(900.0, 560.0), egui::vec2(1440.0, 900.0)] {
let mut harness = egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(size).build_ui_state(
let mut harness = egui_kittest::Harness::builder().with_size(size).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
@@ -1854,14 +1803,13 @@ fn status_zoom_slider_is_named_without_growing_the_status_bar() {
/// than a visible label duplicated by `Slider::text`.
#[test]
fn preferences_and_format_pane_name_every_input() {
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
harness.run_steps(3);
harness.state_mut().run("app.preferences", json!({})).unwrap();
harness.run_steps(3);
@@ -1884,14 +1832,13 @@ fn preferences_and_format_pane_name_every_input() {
/// kittest's screenshot callback, and replied to exactly once after a logic drain.
#[test]
fn ui_screenshot_round_trips_through_the_callable_slot() {
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(900.0, 600.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(900.0, 600.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let (tx, rx) = std::sync::mpsc::channel();
harness.state_mut().control_rx = Some(rx);
let (req, reply) = ControlRequest::new("ui.screenshot", json!({}));
@@ -1913,7 +1860,6 @@ fn ui_screenshot_round_trips_through_the_callable_slot() {
fn logic_drains_control_without_a_ui_pass() {
let mut app = SlideApp::new(Session::with_new(), Services::default());
let ctx = egui::Context::default();
crate::framework::install_headless(&ctx);
let (tx, rx) = std::sync::mpsc::channel();
app.control_rx = Some(rx);
let (req, reply) = ControlRequest::new("ui.inspect", json!({}));
@@ -1930,7 +1876,6 @@ fn logic_drains_control_without_a_ui_pass() {
fn synthetic_input_is_one_pending_batch_and_never_replays() {
let mut app = SlideApp::new(Session::with_new(), Services::default());
let ctx = egui::Context::default();
crate::framework::install_headless(&ctx);
app.queue_input(egui::Event::PointerMoved(egui::pos2(10.0, 10.0)));
let mut raw = egui::RawInput::default();
app.raw_input_hook(&ctx, &mut raw);
@@ -1998,7 +1943,6 @@ fn a_control_click_on_the_first_font_discard_is_requeued_and_lands() {
app.fonts_ready = true;
app.styled = true;
let ctx = egui::Context::default();
crate::framework::install_headless(&ctx);
let pass = |app: &mut SlideApp, time: f64| {
let mut raw = egui::RawInput { time: Some(time), ..Default::default() };
raw.viewports.insert(
@@ -2049,7 +1993,6 @@ fn a_control_click_on_the_first_font_discard_is_requeued_and_lands() {
fn synthetic_batch_is_retracted_when_a_modal_opens_first() {
let mut app = SlideApp::new(Session::with_new(), Services::default());
let ctx = egui::Context::default();
crate::framework::install_headless(&ctx);
app.queue_input(egui::Event::PointerMoved(egui::pos2(10.0, 10.0)));
let mut raw = egui::RawInput::default();
app.raw_input_hook(&ctx, &mut raw);
@@ -2079,7 +2022,6 @@ fn synthetic_click_is_consumed_on_its_old_target_before_logic_changes_the_docume
app.fonts_ready = true;
app.styled = true;
let ctx = egui::Context::default();
crate::framework::install_headless(&ctx);
let pass = |app: &mut SlideApp, time: f64| {
let mut raw = egui::RawInput { time: Some(time), ..Default::default() };
raw.viewports.insert(
@@ -2241,7 +2183,6 @@ fn input_target_changes_retract_a_queued_click() {
fn hidden_logic_pass_carries_a_synthetic_batch_and_drops_it_when_the_document_changes() {
let mut app = SlideApp::new(Session::with_new(), Services::default());
let ctx = egui::Context::default();
crate::framework::install_headless(&ctx);
let (tx, rx) = std::sync::mpsc::channel();
app.control_rx = Some(rx);
app.queue_input(egui::Event::PointerMoved(egui::pos2(10.0, 10.0)));
@@ -2336,7 +2277,6 @@ fn carried_batch_is_consumed_before_the_full_pass_applies_a_control_change() {
app.fonts_ready = true;
app.styled = true;
let ctx = egui::Context::default();
crate::framework::install_headless(&ctx);
let (tx, rx) = std::sync::mpsc::channel();
app.control_rx = Some(rx);
app.queue_input(egui::Event::PointerMoved(egui::pos2(10.0, 10.0)));
@@ -2393,7 +2333,6 @@ fn hidden_full_pass_receives_synthetic_ui_input() {
app.dialog = Some(crate::dialogs::Dialog::new("replaceFonts"));
app.queue_input(egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE });
let ctx = egui::Context::default();
crate::framework::install_headless(&ctx);
let mut hidden = egui::RawInput { time: Some(4.0), ..Default::default() };
hidden.viewports.insert(
egui::ViewportId::ROOT,
@@ -2417,14 +2356,13 @@ fn hidden_full_pass_receives_synthetic_ui_input() {
/// asking the host clipboard service for the same image again.
#[test]
fn paste_image_event_inserts_one_picture() {
let mut harness =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(900.0, 600.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(900.0, 600.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
harness.run_steps(2);
let before = harness.state().session.active().unwrap().doc.slides[0].shapes.len();
let image = egui::ColorImage::filled([2, 2], egui::Color32::from_rgb(1, 2, 3));
@@ -2457,7 +2395,6 @@ fn hidden_viewport_advances_show_and_presenter_clocks_from_logic() {
app.session.execute("transition.timing", &json!({"index": 1, "after": null})).unwrap();
app.start_show(0, false);
let ctx = egui::Context::default();
crate::framework::install_headless(&ctx);
// A real visible UI pass starts the show and its clocks. There is no renderer here, so
// each frame's texture uploads are cleared explicitly (egui 0.37 panics on drop).
@@ -2522,7 +2459,6 @@ fn overdue_visible_logic_does_not_reanchor_a_later_hidden_show() {
app.session.execute("transition.timing", &json!({"index": 1, "after": null})).unwrap();
app.start_show(0, false);
let ctx = egui::Context::default();
crate::framework::install_headless(&ctx);
// The full visible pass is the only pass that anchors the show: egui time 10.
ctx.run_ui(raw_at(10.0, false, false), |ui| {
@@ -2549,14 +2485,13 @@ fn overdue_visible_logic_does_not_reanchor_a_later_hidden_show() {
/// frame until it stuck at its widest and dragging its edge did nothing.
#[test]
fn comments_pane_keeps_its_width_and_resizes() {
let mut h =
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
SlideApp::new(Session::with_new(), Services::default()),
);
h.run_steps(3);
h.state_mut().run("comment.add", json!({"text": "Check the figures on this slide"})).unwrap();
h.state_mut().run("comment.add", json!({"text": "Resolved one"})).unwrap();
+1 -1
View File
@@ -9,7 +9,7 @@ use crate::{Services, SlideApp};
use deckcraft_engine::Session;
fn harness(session: Session, size: egui::Vec2) -> egui_kittest::Harness<'static, SlideApp> {
egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(size).build_ui_state(
egui_kittest::Harness::builder().with_size(size).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
+1 -5
View File
@@ -179,7 +179,7 @@ pub fn install_fonts(ctx: &egui::Context) {
/// installed or embedded faces that draw text the interface faces lack (Hangul, Simplified
/// Chinese, Devanagari…, #101). See [`crate::uifonts`].
pub fn install_fonts_with(ctx: &egui::Context, extra: &[std::sync::Arc<deckcraft_fonts::FontFace>]) {
craft_ui::fonts::load(ctx, font_definitions(extra));
ctx.set_fonts(font_definitions(extra));
}
/// The interface font definitions; see [`install_fonts_with`].
@@ -213,10 +213,6 @@ pub fn font_definitions(extra: &[std::sync::Arc<deckcraft_fonts::FontFace>]) ->
// A bold family for headings and selected tabs.
let mut bold: Vec<String> = names.iter().filter(|(fam, st, _)| *fam == "Inter" && *st == "SemiBold").map(|(_, _, n)| n.clone()).collect();
bold.extend(defs.families.get(&FontFamily::Proportional).cloned().unwrap_or_default());
// The framework's dialogs draw their titles in the semibold family and signatures in the
// signature family; DeckCraft's SemiBold chain and its proportional chain are those.
defs.families.insert(FontFamily::Name(craft_ui::fonts::SEMIBOLD.into()), bold.clone());
defs.families.insert(craft_ui::fonts::FontRef::signature().family(), defs.families.get(&FontFamily::Proportional).cloned().unwrap_or_default());
defs.families.insert(FontFamily::Name("bold".into()), bold);
// Hack is already bundled for Monospace and covers the interface's arrows and triangles.
// Keep it after every proportional face so ordinary text metrics stay unchanged.
+7 -8
View File
@@ -72,14 +72,13 @@ fn harness() -> Harness<'static, SlideApp> {
let mut s = Session::new();
deckcraft_engine::sample::open_sample(&mut s).unwrap();
let app = SlideApp::new(s, Services::default());
let mut h =
Harness::builder().with_context_setup(crate::framework::install_headless).with_size(vec2(W, H)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
let mut h = Harness::builder().with_size(vec2(W, H)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
h
}
+1 -1
View File
@@ -12,7 +12,7 @@ use deckcraft_engine::Session;
use deckcraft_geom::Unit;
fn harness(app: SlideApp) -> Harness<'static, SlideApp> {
Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);

Some files were not shown because too many files have changed in this diff Show More