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
110 changed files with 879 additions and 3326 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) {
+2 -9
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) {
@@ -373,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"))))]
@@ -405,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.
+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]
-10
View File
@@ -254,16 +254,6 @@ pub struct MediaClip {
pub height: u32,
}
impl MediaClip {
/// Whether the clip's frame (an audio icon, or a video's poster) stays out of the
/// show picture. `playing` is true while the voice exists and has not ended.
/// Audio with "Hide During Show" set stays hidden even while it plays; video with
/// "Hide While Not Playing" set shows its frame while it plays.
pub fn hidden_during_show(&self, playing: bool) -> bool {
self.hide_while_not_playing && (!self.video || !playing)
}
}
/// One ink stroke (Draw tab): points in slide coordinates with pressure (`0..=1`,
/// where `1` is [`InkStroke::width`]).
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
+3 -19
View File
@@ -1,7 +1,7 @@
use super::{
ColorRef, Fill, LayoutType, MediaClip, Paragraph, PhType, Placeholder, Presentation, Run, RunProps, SchemeSlot, Shape, ShapeId, ShapeKind,
ShapeStyle, Slide, Table, TextBody, Theme, Xfrm, defaults, ink_pressure_is_legacy, ink_sample_width, parent_of, resolve, sibling_list_mut, style,
text, theme, walk,
ColorRef, Fill, LayoutType, Paragraph, PhType, Placeholder, Presentation, Run, RunProps, SchemeSlot, Shape, ShapeId, ShapeKind, ShapeStyle,
Slide, Table, TextBody, Theme, Xfrm, defaults, ink_pressure_is_legacy, ink_sample_width, parent_of, resolve, sibling_list_mut, style, text,
theme, walk,
};
use crate::resolve::Ctx;
@@ -339,19 +339,3 @@ fn colour_alpha_follows_alpha_mod_and_off() {
let both = base().with(ColorTransform::Alpha(40000)).with(ColorTransform::AlphaMod(50000));
assert!((both.alpha() - 0.2).abs() < 1e-9, "{}", both.alpha());
}
#[test]
fn hide_during_show_keeps_audio_hidden_while_playing() {
let clip = |video: bool, hide_while_not_playing: bool| MediaClip { video, hide_while_not_playing, ..Default::default() };
// Audio with the flag set stays hidden both idle and playing (#1659).
assert!(clip(false, true).hidden_during_show(false), "audio, flagged, idle");
assert!(clip(false, true).hidden_during_show(true), "audio, flagged, playing");
// Video with the flag set hides only while not playing.
assert!(clip(true, true).hidden_during_show(false), "video, flagged, idle");
assert!(!clip(true, true).hidden_during_show(true), "video, flagged, playing");
// Without the flag nothing is hidden.
assert!(!clip(false, false).hidden_during_show(false), "audio, unflagged, idle");
assert!(!clip(false, false).hidden_during_show(true), "audio, unflagged, playing");
assert!(!clip(true, false).hidden_during_show(false), "video, unflagged, idle");
assert!(!clip(true, false).hidden_during_show(true), "video, unflagged, playing");
}
-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),
+8 -33
View File
@@ -49,8 +49,6 @@ enum Paint {
Pattern(String, Rgba, Rgba),
/// `a:noFill`: only the outline, if any, shows.
Nothing,
/// A line series' legend key: its colour and width, and whether it carries a marker.
Line(Rgba, f64, bool),
}
/// The paint of fill `f` as a bar or legend key draws it; the palette's `fallback` when the file
@@ -74,20 +72,6 @@ fn fill_with(ctx: &mut RenderContext, p: &Paint, r: Rect, m: Affine) {
}
Paint::Pattern(name, fg, bg) => crate::pattern::fill(ctx, name, *fg, *bg, 1.0, &r.to_path(0.1), m),
Paint::Nothing => {}
Paint::Line(c, width, marker) => {
// A short stretch of the series' line through the key's middle, with the marker on it.
let mid = (r.y0 + r.y1) / 2.0;
let mut p = BezPath::new();
p.move_to((r.x0, mid));
p.line_to((r.x1, mid));
ctx.set_transform(m);
ctx.set_paint(color(*c, 1.0));
ctx.set_stroke(kurbo::Stroke::new(width.min(r.height() * 0.4)));
ctx.stroke_path(&p);
if *marker {
ctx.fill_path(&kurbo::Circle::new(((r.x0 + r.x1) / 2.0, mid), r.height() * 0.3).to_path(0.1));
}
}
}
}
@@ -113,13 +97,6 @@ fn bar_paint(ctx: &Ctx, c: &Chart, si: usize, pi: usize, s: &deckcraft_model::ch
paint_of(ctx, s.fill.as_ref(), series_color(ctx, c, si))
}
/// Colour of pie slice `i`: its `<c:dPt>` solid fill, else the palette's. Slices and legend keys share it.
fn pie_slice_color(ctx: &Ctx, c: &Chart, s: Option<&deckcraft_model::chart::Series>, i: usize) -> Rgba {
s.and_then(|s| s.point_fills.iter().find(|(k, _)| *k == i))
.and_then(|(_, f)| if let Fill::Solid { color: cc } = f { Some(ctx.color(cc, None)) } else { None })
.unwrap_or_else(|| series_color(ctx, c, i))
}
fn polyline(pts: &[Point]) -> BezPath {
let mut p = BezPath::new();
for (k, q) in pts.iter().enumerate() {
@@ -636,7 +613,7 @@ fn build_legend_items(rctx: &Ctx, c: &Chart, pie: bool, waterfall: bool) -> Vec<
// A map draws its own colour scale.
vec![]
} else if pie {
c.categories.iter().enumerate().map(|(i, n)| (n.clone(), Paint::Color(pie_slice_color(rctx, c, c.series.first(), i)), None)).collect()
c.categories.iter().enumerate().map(|(i, n)| (n.clone(), Paint::Color(series_color(rctx, c, i)), None)).collect()
} else {
c.series
.iter()
@@ -644,14 +621,7 @@ fn build_legend_items(rctx: &Ctx, c: &Chart, pie: bool, waterfall: bool) -> Vec<
.map(|(i, s)| {
let k = c.series_kind(s);
let line = !k.is_bar_like() && !matches!(k, ChartType::Area | ChartType::StackedArea | ChartType::FilledRadar);
if matches!(k, ChartType::Line | ChartType::LineMarkers | ChartType::StackedLine | ChartType::Radar) {
let lw = s.line.as_ref().and_then(|l| l.width).filter(|w| w.is_finite() && *w > 0.0).unwrap_or(2.25).clamp(0.25, 20.0);
(
s.name.clone(),
Paint::Line(series_line(rctx, c, i, s), lw, k == ChartType::LineMarkers || (k == ChartType::Radar && s.marker.is_some())),
None,
)
} else if line {
if line {
(s.name.clone(), Paint::Color(series_line(rctx, c, i, s)), None)
} else if k.is_bar_like() {
let paint = if c.vary_colors && c.series.len() == 1 && s.fill.is_none() {
@@ -1209,7 +1179,12 @@ fn draw_pie(ctx: &mut RenderContext, rctx: &Ctx, c: &Chart, m: Affine, area: Rec
p.extend(arc.append_iter(0.1));
p.close_path();
ctx.set_transform(m);
let col = pie_slice_color(rctx, c, Some(s), i);
let col = s
.point_fills
.iter()
.find(|(k, _)| *k == i)
.and_then(|(_, f)| if let Fill::Solid { color: cc } = f { Some(rctx.color(cc, None)) } else { None })
.unwrap_or_else(|| series_color(rctx, c, i));
ctx.set_paint(color(col, 1.0));
ctx.fill_path(&p);
ctx.set_paint(color(Rgba::WHITE, 1.0));
@@ -1,20 +0,0 @@
use deckcraft_color::Rgba;
use deckcraft_model::chart::ChartType;
use deckcraft_model::style::{ColorRef, Fill};
use deckcraft_model::{Chart, Presentation, Shape, ShapeId, ShapeKind, Xfrm};
use deckcraft_render::{RenderOpts, render_slide};
#[test]
fn pie_legend_keys_take_the_point_colours() {
let mut c = Chart::sample(ChartType::Pie);
c.title = None;
c.legend = Some("r".into());
c.series[0].point_fills = vec![(0, Fill::solid(ColorRef::rgb(Rgba::rgb(255, 0, 255))))];
let sh = Shape { id: ShapeId(2028), xfrm: Some(Xfrm::new(0.0, 0.0, 960.0, 540.0)), kind: ShapeKind::Chart(Box::new(c)), ..Default::default() };
let mut p = Presentation::default();
std::sync::Arc::make_mut(&mut p.slides[0]).shapes = vec![sh];
let img = render_slide(&p, 0, &RenderOpts { scale: 1.0, ..Default::default() });
// The pie stays well left of x = 850; only the legend column lies beyond it.
let key = (850..img.width).flat_map(|x| (0..img.height).map(move |y| (x, y))).filter(|(x, y)| img.pixel(*x, *y)[..3] == [255, 0, 255]).count();
assert!(key > 20, "the legend key of the overridden slice is drawn in its colour: {key} px");
}
@@ -1,53 +0,0 @@
use deckcraft_model::chart::ChartType;
use deckcraft_model::style::Line;
use deckcraft_model::{Chart, ColorRef, Presentation, Rgba, Shape, ShapeId, ShapeKind, Xfrm};
use deckcraft_render::{RenderOpts, render_slide};
/// Rows and columns of the pixels matching `want` in the legend's key column, right of the plot.
fn key_extent(kind: ChartType, want: &dyn Fn([u8; 4]) -> bool) -> (usize, usize) {
let mut c = Chart::sample(kind);
c.title = None;
c.legend = Some("r".into());
c.series.truncate(2);
for (s, (name, rgb)) in c.series.iter_mut().zip([("A", Rgba::rgb(255, 0, 0)), ("B", Rgba::rgb(0, 0, 255))]) {
s.name = name.into();
s.line = Some(Line::solid(ColorRef::rgb(rgb), 3.0));
}
let sh = Shape { id: ShapeId(1), xfrm: Some(Xfrm::new(0.0, 0.0, 960.0, 540.0)), kind: ShapeKind::Chart(Box::new(c)), ..Default::default() };
let mut p = Presentation::default();
std::sync::Arc::make_mut(&mut p.slides[0]).shapes = vec![sh];
let img = render_slide(&p, 0, &RenderOpts { scale: 1.0, ..Default::default() });
let hits: Vec<(u32, u32)> =
(870..img.width).flat_map(|x| (0..img.height).map(move |y| (x, y))).filter(|(x, y)| want(img.pixel(*x, *y))).collect();
let rows = hits.iter().map(|h| h.1).collect::<std::collections::BTreeSet<_>>().len();
let cols = hits.iter().map(|h| h.0).collect::<std::collections::BTreeSet<_>>().len();
(rows, cols)
}
fn red(p: [u8; 4]) -> bool {
p[0] > 200 && p[1] < 60 && p[2] < 60
}
fn blue(p: [u8; 4]) -> bool {
p[0] < 60 && p[1] < 60 && p[2] > 200
}
#[test]
fn line_chart_legend_key_is_a_stretch_of_the_line() {
// A 3 pt line key is a few pixels tall; a filled square key is over ten.
for want in [&red as &dyn Fn([u8; 4]) -> bool, &blue] {
let (rows, cols) = key_extent(ChartType::Line, want);
assert!((2..=5).contains(&rows), "line key is {rows} rows tall");
assert!(cols >= 8, "line key is {cols} columns wide");
}
}
#[test]
fn line_with_markers_legend_key_has_a_marker_on_the_line() {
// The marker is wider than the line but smaller than a filled square.
for want in [&red as &dyn Fn([u8; 4]) -> bool, &blue] {
let (rows, cols) = key_extent(ChartType::LineMarkers, want);
assert!((6..=10).contains(&rows), "marker key is {rows} rows tall");
assert!(cols >= 8, "marker key is {cols} columns wide");
}
}
+6 -66
View File
@@ -150,13 +150,10 @@ pub(crate) struct BreakParams<'a> {
pub(crate) default_tab: f64,
pub(crate) x0_first: f64,
pub(crate) x0_rest: f64,
/// Absolute position of the hanging-indent implicit stop (`marL`), when the first
/// line starts left of the margin. [`tab_advance`] treats it as a left stop.
pub(crate) hang: Option<f64>,
}
pub(crate) fn break_lines(p: &ParaShaped, params: &BreakParams) -> Vec<RawLine> {
let BreakParams { first_w, rest_w, wrap, tab_stops, default_tab, x0_first, x0_rest, hang: hang_stop } = *params;
let BreakParams { first_w, rest_w, wrap, tab_stops, default_tab, x0_first, x0_rest } = *params;
let text: String = p.cells.iter().map(|c| c.ch).collect();
let (allowed, _) = break_opportunities(&text, p.props.latin_line_break.unwrap_or(false));
let hang = p.props.hanging_punct.unwrap_or(false);
@@ -182,8 +179,7 @@ pub(crate) fn break_lines(p: &ParaShaped, params: &BreakParams) -> Vec<RawLine>
break;
}
let adv = if c == '\t' {
// The implicit stop is for the first line only: later lines start at the margin.
tab_advance(x0 + x, tab_stops, default_tab, tab_segment(&p.cells, i), if lines.is_empty() { hang_stop } else { None }, x0 + avail)
tab_advance(x0 + x, tab_stops, default_tab, tab_segment(&p.cells, i))
} else {
p.cells.get(i).map(|c| c.adv).unwrap_or(0.0)
};
@@ -309,40 +305,11 @@ pub(crate) fn tab_segment(cells: &[Cell], i: usize) -> (f64, f64) {
/// Advance of a tab at `x` (from the start edge) to the next stop, placing the text after it
/// (`seg`: its width, and its width before the decimal point) as the stop aligns it but never
/// moving back, as PowerPoint does; past the last stop, to the next default stop.
/// `hang` is the hanging-indent implicit stop (`marL`): the first tab on a first line that
/// starts left of the margin goes there instead, as PowerPoint does. The nearer of the
/// implicit and the regular stops wins; an explicit stop within 0.5 pt of it keeps its
/// own alignment.
///
/// `right` is the line's right edge in the same coordinate space as `x` (the text area's left
/// edge plus the line's start offset and width): a stop set past that edge acts as one at the
/// edge, as PowerPoint treats it (a right-aligned stop there ends the text at the margin).
pub(crate) fn tab_advance(x: f64, stops: &[Tab], default_tab: f64, seg: (f64, f64), hang: Option<f64>, right: f64) -> f64 {
pub(crate) fn tab_advance(x: f64, stops: &[Tab], default_tab: f64, seg: (f64, f64)) -> f64 {
// `stops` is in position order (`tabs_of`): the next stop is the first past x.
// A NaN `x` (a NaN spacing upstream) skips the lookup and takes the finite default-stop path.
if !x.is_nan()
&& let Some(h) = hang
&& h.is_finite()
&& x < h - 0.5
{
let explicit = stops.get(stops.partition_point(|s| s.pos <= x + 0.5));
let d = if default_tab > 1.0 { default_tab } else { 72.0 };
let default_next = ((x / d).floor() + 1.0) * d;
let explicit_wins = match explicit {
// Compared where the stop takes effect: one past the line's edge ends there (below).
Some(s) => {
let pos = if right.is_finite() && right > 0.0 { s.pos.min(right) } else { s.pos };
pos < h - 0.5 || (pos - h).abs() <= 0.5
}
None => h >= default_next - 0.5,
};
if !explicit_wins {
return (h - x).max(1.0);
}
}
if let Some(s) = stops.get(stops.partition_point(|s| s.pos <= x + 0.5)).filter(|_| !x.is_nan()) {
let pos = if right.is_finite() && right > 0.0 { s.pos.min(right) } else { s.pos };
let to = (pos - x).max(0.0);
let to = s.pos - x;
return match s.align {
TabAlign::Left => to,
TabAlign::Right => (to - seg.0).max(0.0),
@@ -362,34 +329,7 @@ mod tab_tests {
#[test]
fn a_nan_position_takes_the_finite_default_stop() {
let stops = [Tab { pos: 100.0, align: TabAlign::Left }];
assert!(tab_advance(f64::NAN, &stops, 72.0, (0.0, 0.0), None, 600.0).is_finite());
assert_eq!(tab_advance(10.0, &stops, 72.0, (0.0, 0.0), None, 600.0), 90.0);
}
#[test]
fn a_stop_past_the_edge_is_compared_with_the_hang_at_the_edge() {
// The 700 pt stop takes effect at the 60 pt edge, which comes before the 80 pt hang: it
// wins, and right-aligned text after it ends at the edge (60 - 20), not at the hang.
let stops = [Tab { pos: 700.0, align: TabAlign::Right }];
assert_eq!(tab_advance(0.0, &stops, 72.0, (20.0, 20.0), Some(80.0), 60.0), 40.0);
}
#[test]
fn a_stop_past_the_line_ends_at_its_edge() {
let stops = [Tab { pos: 700.0, align: TabAlign::Right }];
// Right-aligned text after the tab ends at the line's right edge, not 700.
assert_eq!(tab_advance(0.0, &stops, 72.0, (100.0, 100.0), None, 600.0), 500.0);
// A stop inside the line keeps its own position.
assert_eq!(tab_advance(0.0, &stops, 72.0, (100.0, 100.0), None, 800.0), 600.0);
}
#[test]
fn an_offset_line_clamps_to_its_absolute_right_edge() {
// The stop and the edge are absolute coordinates: a 100 pt start offset does not move the
// edge in to 500 pt, so an inside stop at 550 stays there and one past 600 ends at 600.
let inside = [Tab { pos: 550.0, align: TabAlign::Right }];
assert_eq!(tab_advance(100.0, &inside, 72.0, (100.0, 100.0), None, 600.0), 350.0);
let past = [Tab { pos: 700.0, align: TabAlign::Right }];
assert_eq!(tab_advance(100.0, &past, 72.0, (100.0, 100.0), None, 600.0), 400.0);
assert!(tab_advance(f64::NAN, &stops, 72.0, (0.0, 0.0)).is_finite());
assert_eq!(tab_advance(10.0, &stops, 72.0, (0.0, 0.0)), 90.0);
}
}
+4 -15
View File
@@ -233,7 +233,6 @@ struct ParaEnv<'a> {
first_x: f64,
rest_x: f64,
tabs: &'a [Tab],
hang: Option<f64>,
}
impl ParaEnv<'_> {
@@ -313,12 +312,6 @@ fn place_paragraph(p: &ParaShaped, pi: usize, g: &BoxGeom, spacing: (f64, bool),
let first_x = first_line_start(p.bullet.is_some(), margin, indent, bullet_w);
let rest_x = margin;
let tabs = tabs_of(props);
// A hanging first line (marL > 0, indent < 0) treats the indent position (marL) as an
// implicit tab stop for its first tab; later lines already start there, so the stop
// only ever applies ahead of the first line's start.
// LTR only: the implicit stop is measured from the left margin, and RTL tab handling is
// out of this change's scope (its stops are not mirrored here yet).
let hang = (!p.rtl && margin - first_x > 0.5 && margin.is_finite()).then_some(margin);
let first_w = (g.col_w - first_x - mr).max(1.0);
let rest_w = (g.col_w - rest_x - mr).max(1.0);
let raw = break_lines(
@@ -331,14 +324,13 @@ fn place_paragraph(p: &ParaShaped, pi: usize, g: &BoxGeom, spacing: (f64, bool),
default_tab: props.default_tab.unwrap_or(72.0),
x0_first: first_x,
x0_rest: rest_x,
hang,
},
);
// The first paragraph's space before counts only when the body says so.
let before = if pi == 0 && !first_last { 0.0 } else { spacing_pts(props.space_before, p.lead_size) };
flow.y += before.max(0.0) + flow.prev_after;
let first_line_idx = flow.lines.len();
let env = ParaEnv { p, g, reduce, margin, indent, mr, bullet_w, first_x, rest_x, tabs: &tabs, hang };
let env = ParaEnv { p, g, reduce, margin, indent, mr, bullet_w, first_x, rest_x, tabs: &tabs };
for (li, rl) in raw.iter().enumerate() {
let is_last = li + 1 == raw.len();
let placed = place_line(&env, pi, rl, li, is_last, flow);
@@ -384,10 +376,7 @@ fn line_extent(p: &ParaShaped, rl: &RawLine) -> (f64, f64, f64) {
}
/// Logical advance of each cell on the line (tabs measure from the start edge) and their sum.
/// `hang` is the implicit first-line stop, or `None` on later lines: they already start at the
/// margin, and negative character spacing can dip `x` below it, which would wrongly re-trigger
/// the stop.
fn line_advances(env: &ParaEnv, rl: &RawLine, is_last: bool, x0: f64, hang: Option<f64>, avail: f64) -> (Vec<f64>, f64) {
fn line_advances(env: &ParaEnv, rl: &RawLine, is_last: bool, x0: f64) -> (Vec<f64>, f64) {
let p = env.p;
let line_cells = p.cells.get(rl.start..rl.end).unwrap_or(&[]);
let n = rl.end.saturating_sub(rl.start);
@@ -399,7 +388,7 @@ fn line_advances(env: &ParaEnv, rl: &RawLine, is_last: bool, x0: f64, hang: Opti
let a = if shy_end && k + 1 == n {
p.faces.get(c.face).zip(p.styles.get(c.style)).map(|(f, st)| measure_str(f, st.size, "-").0).unwrap_or(0.0)
} else if c.ch == '\t' {
tab_advance(x0 + x, env.tabs, p.props.default_tab.unwrap_or(72.0), tab_segment(&p.cells, rl.start + k), hang, x0 + avail)
tab_advance(x0 + x, env.tabs, p.props.default_tab.unwrap_or(72.0), tab_segment(&p.cells, rl.start + k))
} else {
c.adv
};
@@ -531,7 +520,7 @@ fn place_line(env: &ParaEnv, pi: usize, rl: &RawLine, li: usize, is_last: bool,
let avail = (g.col_w - x0 - env.mr).max(0.0);
let n = rl.end.saturating_sub(rl.start);
let line_cells = p.cells.get(rl.start..rl.end).unwrap_or(&[]);
let (mut adv, width) = line_advances(env, rl, is_last, x0, if li == 0 { env.hang } else { None }, avail);
let (mut adv, width) = line_advances(env, rl, is_last, x0);
let align = props.align.unwrap_or(Align::Left);
let slack = (avail - width).max(0.0);
let stretch = !is_last && g.wrap && slack > 0.0;
-112
View File
@@ -1419,54 +1419,6 @@ fn tab_stops_align_the_text_after_them() {
assert!((l.lines[0].edges[4].0 - x0(&l) - 72.0).abs() < 0.01);
}
#[test]
fn a_right_tab_stop_past_the_margin_ends_the_text_at_the_margin() {
// #1663: a layout may set a right tab stop a little past the text area's right edge.
// PowerPoint treats it as one at the margin: the text after it stays on one line and ends
// at the right edge. DeckCraft started it too far right and wrapped the rest.
let l = tabbed("x\tCorrie Ten Boom", &[(700.0, "r")], 600.0);
assert_eq!(l.lines.len(), 1, "{:?}", l.lines.iter().map(|x| (x.start, x.end, x.extent)).collect::<Vec<_>>());
let right = l.inner.x0 + l.inner.width();
assert!((l.lines[0].extent.1 - right).abs() < 0.01, "ends at {:?}, margin {right}", l.lines[0].extent);
}
#[test]
fn an_indented_paragraph_clamps_a_tab_stop_to_its_absolute_right_edge() {
// #1663: the stop and the edge are measured from the text area's left edge, so an indented
// first line does not pull the edge in by its margin. A stop inside it keeps its position;
// one past it ends the text at the margin.
let (p, mut sh) = setup("x\tCorrie Ten Boom", 600.0, 300.0);
let para = &mut sh.text.as_mut().unwrap().paragraphs[0];
for r in &mut para.runs {
r.props.size = Some(18.0);
}
let pp = &mut para.props;
pp.bullet = Some(Bullet::None);
pp.margin_left = Some(100.0);
pp.indent = Some(0.0);
pp.default_tab = Some(72.0);
pp.tabs = Some(vec![deckcraft_model::text::TabStop { pos: 550.0, align: "r".to_string() }]);
let l = lay(&p, &sh, 600.0, 300.0);
assert_eq!(l.lines.len(), 1, "{:?}", l.lines.iter().map(|x| (x.start, x.end, x.extent)).collect::<Vec<_>>());
assert!((l.lines[0].extent.1 - l.inner.x0 - 550.0).abs() < 0.01, "inside stop at {:?}", l.lines[0].extent);
let (p, mut sh) = setup("x\tCorrie Ten Boom", 600.0, 300.0);
let para = &mut sh.text.as_mut().unwrap().paragraphs[0];
for r in &mut para.runs {
r.props.size = Some(18.0);
}
let pp = &mut para.props;
pp.bullet = Some(Bullet::None);
pp.margin_left = Some(100.0);
pp.indent = Some(0.0);
pp.default_tab = Some(72.0);
pp.tabs = Some(vec![deckcraft_model::text::TabStop { pos: 700.0, align: "r".to_string() }]);
let l = lay(&p, &sh, 600.0, 300.0);
assert_eq!(l.lines.len(), 1, "{:?}", l.lines.iter().map(|x| (x.start, x.end, x.extent)).collect::<Vec<_>>());
let right = l.inner.x0 + l.inner.width();
assert!((l.lines[0].extent.1 - right).abs() < 0.01, "ends at {:?}, margin {right}", l.lines[0].extent);
}
#[test]
fn many_tabs_over_many_stops_lay_out_by_position() {
// 20,000 stops given out of order, and 2,000 tabs: each tab finds the next stop by position.
@@ -1487,70 +1439,6 @@ fn a_tab_past_the_end_moves_to_the_next_line() {
assert!((l.lines[1].edges[1].0 - l.inner.x0 - 72.0).abs() < 0.01);
}
/// One paragraph `text` with a hanging indent (`marL`/`indent`), no bullet or explicit stops.
fn hanging_tabbed(text: &str, margin: f64, indent: f64, w: f64) -> TextLayout {
let (p, mut sh) = setup(text, w, 300.0);
let para = &mut sh.text.as_mut().unwrap().paragraphs[0];
for r in &mut para.runs {
r.props.size = Some(18.0);
}
let pp = &mut para.props;
pp.bullet = Some(Bullet::None);
pp.margin_left = Some(margin);
pp.indent = Some(indent);
pp.default_tab = Some(72.0);
pp.tabs = None;
lay(&p, &sh, w, 300.0)
}
#[test]
fn hanging_indent_is_the_first_tab_stop() {
// PowerPoint: with a 0.375 in (27 pt) hanging indent, the first tab on the first line goes
// to marL; later tabs go to the normal default stops.
let l = hanging_tabbed("a\tb\tc", 27.0, -27.0, 600.0);
assert_eq!(l.lines.len(), 1);
let x0 = l.inner.x0;
assert!((l.lines[0].edges[2].0 - x0 - 27.0).abs() < 0.5, "the char after the first tab starts at marL: {:?}", l.lines[0].edges);
assert!((l.lines[0].edges[4].0 - x0 - 72.0).abs() < 0.5, "the char after the second tab starts at the default stop: {:?}", l.lines[0].edges);
// A third tab lands on the next default stop.
let l = hanging_tabbed("a\tb\tc\td", 27.0, -27.0, 600.0);
assert!((l.lines[0].edges[6].0 - l.inner.x0 - 144.0).abs() < 0.5, "{:?}", l.lines[0].edges);
}
#[test]
fn a_tab_on_a_wrapped_line_keeps_the_default_stop() {
// The implicit stop only applies ahead of the first line's start: a tab on the second
// line uses the normal default stop from the box grid (72 pt here), not marL + 27.
let l = hanging_tabbed("AAAA\u{b}\tB", 27.0, -27.0, 600.0);
assert_eq!(l.lines.len(), 2, "{:?}", l.lines.iter().map(|x| (x.start, x.end)).collect::<Vec<_>>());
let x = l.lines[1].edges[1].0 - l.inner.x0;
assert!((x - 72.0).abs() < 0.5, "the wrapped line's tab uses the default stop, got {x}");
assert!((x - 54.0).abs() > 5.0, "and not marL + 27");
}
#[test]
fn a_tab_after_negative_spacing_on_a_later_line_keeps_the_default_stop() {
// #1683 follow-up: the implicit stop is a first-line stop only. Negative character spacing
// can put a later line's cursor left of the margin; its tab must still take the default stop.
let (p, mut sh) = setup("A\u{b}X\tY", 600.0, 300.0);
let para = &mut sh.text.as_mut().unwrap().paragraphs[0];
for r in &mut para.runs {
r.props.size = Some(18.0);
r.props.spacing = Some(-20.0);
}
let pp = &mut para.props;
pp.bullet = Some(Bullet::None);
pp.margin_left = Some(27.0);
pp.indent = Some(-27.0);
pp.default_tab = Some(72.0);
pp.tabs = None;
let l = lay(&p, &sh, 600.0, 300.0);
assert_eq!(l.lines.len(), 2, "{:?}", l.lines.iter().map(|x| (x.start, x.end)).collect::<Vec<_>>());
let x = l.lines[1].edges[2].0 - l.inner.x0;
assert!((x - 72.0).abs() < 0.5, "the later line's tab uses the default stop, got {x}");
assert!((x - 27.0).abs() > 5.0, "and not the first line's margin stop");
}
/// Underline decorations of "ab cd" underlined `u` at 40 pt.
fn underline_decos(u: &str) -> (TextLayout, Vec<Deco>) {
let (p, mut sh) = setup("ab cd", 2000.0, 300.0);
-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
@@ -369,7 +369,7 @@ fn begin_slide(app: &mut SlideApp, show: &Show, f: &Fr, size: (u32, u32)) -> Sl
let media = crate::media::slide_media(doc, idx);
let hidden: Vec<ShapeId> = media
.iter()
.filter(|(id, _, clip)| clip.hidden_during_show(app.media.status(*id).is_some_and(|s| s.state != deckcraft_media::PlayState::Ended)))
.filter(|(id, _, clip)| clip.hide_while_not_playing && !app.media.status(*id).is_some_and(|s| s.state != deckcraft_media::PlayState::Ended))
.map(|m| m.0)
.collect();
let gifs = app.media.gifs(doc_uid, doc, idx, now, &app.session.gif_paused);
+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);

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