ui-egui: remove what the port left unread

Unused imports in show.rs (the cfg(test) re-exports the tests import from
the submodules directly), lib.rs, app.rs, closing and chart_data. Dead items:
Show::hidden_time_driven (replaced by next_wake), the Show backdrop wrappers
(tests call the frame store), ShowFrames::current_key (the test checks the
texture left on screen instead), GridPick (sheet returns the picked slide;
the control channel recomputes cells), SlideApp::frame (only
integrated_titlebar read it, at construction) and catalog_generation (the
harness reads AppCatalog::generation). canvas_menu is crate-visible like its
type. The show keys test's typed-digit run is its own helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. Taylor
2026-11-29 02:22:16 +00:00
co-authored by Claude Opus 5.5
parent fddc733e8d
commit 72db063166
13 changed files with 77 additions and 135 deletions
+3 -6
View File
@@ -6,8 +6,8 @@ use super::state::{FilePlace, FilePurpose, LocatedPlace, RECENT_MAX, ViewMode};
#[cfg(not(target_arch = "wasm32"))]
use super::updates_ui;
use super::{
AnimPreview, FileTarget, HashMap, InputTarget, PendingFile, Perf, Platform, Session, SlideApp, Target, UiRequest, Value, backstage, dialogs,
doc_window, json, media, menus, preview, qat, ribbon, show, sorter, status, toast,
AnimPreview, FileTarget, HashMap, InputTarget, Perf, Platform, Session, SlideApp, Target, UiRequest, Value, backstage, dialogs, doc_window, json,
media, menus, preview, qat, ribbon, show, sorter, status, toast,
};
use craft::ui::contract::{Bind, CommandSet as _, Tracked};
use craft::ui::runtime::commands::{CommandGate, CommandInput};
@@ -128,8 +128,7 @@ impl SlideApp {
let saved = store.get().clone().sanitized();
let mut session = Session::default();
session.prefs = saved.prefs;
let catalog_generation = 1;
let catalog = catalog::build(&session, catalog_generation).map_err(AppError::Catalog)?;
let catalog = catalog::build(&session, 1).map_err(AppError::Catalog)?;
let wake_ctx = ctx.clone();
let wake = craft::host::Wake::new(move || wake_ctx.request_repaint());
let intake = intake.or_else(|| Some(craft::platform::open::FileIntake::new(wake.clone()).0));
@@ -148,7 +147,6 @@ impl SlideApp {
palette_state: Default::default(),
guide_selection: Default::default(),
catalog,
catalog_generation,
injected_target: None,
twist_frame: None,
clock: Default::default(),
@@ -206,7 +204,6 @@ impl SlideApp {
host_start: None,
store,
intake,
frame,
at_exit,
left: false,
};
-1
View File
@@ -18,7 +18,6 @@ fn drag_with_modifiers(h: &mut Harness<'_, SlideApp>, a: Pos2, b: Pos2, modifier
h.event(egui::Event::ModifiersChanged(modifiers));
h.hover_at(a);
h.run_steps(1);
let editing = |h: &Harness<'_, SlideApp>| h.state().session.active().unwrap().selection.text.is_some();
h.event(egui::Event::PointerButton { pos: a, button: PointerButton::Primary, pressed: true, modifiers });
h.run_steps(1);
for i in 1..=8 {
+1 -1
View File
@@ -3,7 +3,7 @@ use std::sync::{Arc, Mutex};
use craft::i18n::Word;
use craft::table::ui::grid::{CellAt, CellGrid, GridModel, GridState, LineIndex};
use craft::ui::buttons::Button;
use craft::ui::contract::{Bind, PaintUi, Props as _, Show as _, ShowContainer as _, clicked};
use craft::ui::contract::{Bind, PaintUi, Show as _, ShowContainer as _, clicked};
use craft::ui::dialog::DialogHost;
use craft::ui::layout_components::{Row, Stack};
use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, HostedParamDialog, Param, ParamDialog, ParamKind, ParamLayout, ParamResult};
+1 -1
View File
@@ -4,7 +4,7 @@ use craft::quit::{CloseAnswer, CloseGuard, CloseScope, GuardStep};
use craft::ui::dialog::{DialogHost, DialogId, StackDialog, UnsavedChangesDialog};
use craft::ui::runtime::windows::{WindowAction, WindowHost};
use egui::{Context, ViewportId};
use serde_json::{Value, json};
use serde_json::json;
use crate::SlideApp;
use crate::app::files::SaveOutcome;
+2 -4
View File
@@ -49,7 +49,7 @@ mod state;
use std::collections::HashMap;
use deckcraft_engine::{Mods, Session, Target, UiRequest};
use deckcraft_engine::{Session, Target, UiRequest};
use deckcraft_model::{LayoutId, MasterId, SlideId};
use serde::{Deserialize, Serialize};
use serde_json::{Value, json};
@@ -138,7 +138,6 @@ pub struct SlideApp {
/// Guide selection scoped to the active document and its guide list.
pub(crate) guide_selection: canvas::guides::GuideSelection,
catalog: craft::ui::runtime::commands::AppCatalog,
catalog_generation: u64,
injected_target: Option<InputTarget>,
/// The frame a trackpad twist last turned the selection in; a repeat pass of that frame carries no
/// twist and must not end the gesture.
@@ -178,7 +177,7 @@ pub struct SlideApp {
/// Alignment of the next tab stop inserted with the ruler.
pub ruler_tab_kind: craft::text::ui::ruler::TabAlign,
/// The open canvas context menu.
pub canvas_menu: Option<canvas::context_menu::CanvasMenu>,
pub(crate) canvas_menu: Option<canvas::context_menu::CanvasMenu>,
/// Optional motion-mode request for the text editor host: `Some(false)` turns the caret blink off.
pub(crate) caret_blink: Option<bool>,
/// The input method context of the selected shape the canvas composes for (`text_host::show_selection_ime`).
@@ -235,7 +234,6 @@ pub struct SlideApp {
host_start: Option<u64>,
store: craft::settings::SettingsStore<settings::DeckSettings>,
intake: Option<craft::platform::open::FileIntake>,
frame: craft::window::policy::Frame,
at_exit: Option<Box<dyn FnOnce()>>,
left: bool,
}
+1 -1
View File
@@ -129,7 +129,7 @@ pub fn presenter_body(ui: &mut egui::Ui, _cx: &mut BodyCx<'_>, model: &Presenter
GridSource::Deck { doc, thumbs, source } => GridSource::Deck { doc, thumbs, source },
GridSource::Pictures(pictures) => GridSource::Pictures(pictures),
};
if let Some(slide) = crate::show::grid::sheet(ui, slides, model.slide, aspect).picked {
if let Some(slide) = crate::show::grid::sheet(ui, slides, model.slide, aspect) {
out.push(Command::Goto { slide });
}
} else {
+1 -36
View File
@@ -8,33 +8,20 @@ use deckcraft_anim::{Click, HitShape, Layer, LinkJump, ShowAction, ShowState, So
use deckcraft_model::text::Hyperlink;
use deckcraft_model::{Presentation, ShapeId};
use deckcraft_render::{ParaState, PlacedLink, PlacedShape, RenderOpts, ShapeState};
use egui::{Align2, Color32, CornerRadius, Mesh, Pos2, Rect, Sense, Stroke, TextureHandle, Ui, pos2, vec2};
use egui::{Color32, Mesh, Rect, Ui, pos2, vec2};
use serde_json::json;
use crate::SlideApp;
use crate::theme;
mod media;
mod presenter;
mod render;
mod ui;
mod zoom;
pub(crate) use zoom::GRID_CAP;
#[cfg(test)]
// PLAN: assumed fn transition_layers(kind: &str, option: &str, reverse: bool, p: f64, aspect: f64) -> Vec<Layer> (show-w6)
use frames::transition_layers;
#[cfg(test)]
use media::slide_media_bars;
pub(crate) use presenter::format_elapsed;
use presenter::{NOTES_DEFAULT, PresenterTimer};
#[cfg(test)]
use presenter::{NOTES_MAX, NOTES_MIN, NOTES_STEP, presenter_pass};
#[cfg(test)]
use render::{below_playing_video, render_frame};
pub(crate) use ui::ui;
#[cfg(test)]
use zoom::{GOTO_DIGITS, toggle_blank};
/// Playback state shared by the audience and presenter windows.
pub struct Show {
@@ -298,18 +285,6 @@ impl Show {
self.started
}
/// Whether hidden logic still has time-driven work, so it must keep requesting wake-ups.
pub(crate) fn hidden_time_driven(&self, doc: &Presentation) -> bool {
self.hold.is_none()
&& self.started
&& !self.ended
&& (self.state.playing
|| self.state.trigger_playing()
|| self.trans.is_some()
|| self.autoplay
|| self.state.advance_after(doc).is_some())
}
/// Advance the show's own clocks and automatic steps on a hidden logic pass. Drawing is a
/// separate concern, so a minimized show keeps playing instead of inventing a pause policy.
/// Returns false when the show should close (preview ended).
@@ -413,16 +388,6 @@ impl Show {
self.laser = false;
}
/// Obtain the backdrop through the frame store's retained source.
fn backdrop(&mut self, ctx: &egui::Context, doc: &std::sync::Arc<Presentation>, key: BackKey) -> std::sync::Arc<deckcraft_render::Image> {
self.frames.backdrop(ctx, doc, key)
}
/// Queue a backdrop through the frame resource owner.
fn prefetch_backdrop(&mut self, ctx: &egui::Context, doc: &std::sync::Arc<Presentation>, key: BackKey) {
self.frames.prefetch_backdrop(ctx, doc, key);
}
fn timeline(&mut self, doc: &Presentation) -> &Timeline {
let i = self.state.slide;
if self.timeline.as_ref().is_none_or(|(k, _)| *k != i) {
-5
View File
@@ -309,11 +309,6 @@ impl ShowFrames {
self.next.as_ref().map(|(_, texture)| texture)
}
/// The current store key, retained by a transition when leaving the slide.
pub(super) fn current_key(&self) -> Option<FrameKey> {
self.current.as_ref().map(|(key, _)| key.clone())
}
/// Retained current pixels, if their texture has not been evicted.
pub(crate) fn current_source(&self, ctx: &Context) -> Option<Arc<FrameSource>> {
let key = &self.current.as_ref()?.0;
+6 -16
View File
@@ -27,14 +27,6 @@ pub enum GridSource<'a> {
Pictures(&'a [craft::ui::primitives::CachedTexture]),
}
/// The selected slide and grid cell bounds.
pub(crate) struct GridPick {
/// The slide activated by this pass's input.
pub picked: Option<usize>,
/// Tile bounds computed for this pass's room.
pub cells: Vec<egui::Rect>,
}
fn grid<'a>(aspect: f32) -> TileGrid<'a, usize> {
TileGrid::new(Word::plain("All slides"))
.column_rule(ColumnRule::FitToView { most_columns: 8 })
@@ -88,15 +80,16 @@ fn grid_cells(ctx: &egui::Context, env: &Env, room: Rect, indices: &[usize], asp
.collect()
}
/// Shows the same slide grid in the audience page, presenter page and popup.
pub(crate) fn sheet(ui: &mut Ui, slides: GridSource<'_>, current: usize, aspect: f32) -> GridPick {
/// Shows the same slide grid in the audience page, presenter page and popup, and returns the slide
/// activated by this pass's input.
pub(crate) fn sheet(ui: &mut Ui, slides: GridSource<'_>, current: usize, aspect: f32) -> Option<usize> {
let (count, note) = match &slides {
GridSource::Deck { doc, .. } => (doc.slides.len(), doc.slides.len() > GRID_CAP),
GridSource::Pictures(pictures) => (pictures.len(), false),
};
let indices = grid_indices(count);
let room = ui.available_rect_before_wrap();
let mut result = GridPick { picked: None, cells: vec![] };
let mut picked = None;
Stack::new()
.fill()
.surface(SurfaceKind::Canvas)
@@ -106,9 +99,7 @@ pub(crate) fn sheet(ui: &mut Ui, slides: GridSource<'_>, current: usize, aspect:
header().show(ui, |ui, _| heading(ui, note));
})
.show_at(ui, room, |ui, _| {
let body = ui.available_rect_before_wrap();
let env = Env::of(ui);
let cells = grid_cells(ui.ctx(), &env, body, &indices, aspect);
let source = craft::behavior::keyed(&indices, |key: &usize| *key);
let mut selection = Selection::single(current);
let thumb_aspect = ThumbAspect::from_ratio(aspect);
@@ -129,13 +120,12 @@ pub(crate) fn sheet(ui: &mut Ui, slides: GridSource<'_>, current: usize, aspect:
Tile::new(label).picture(thumb_aspect, picture)
});
let picked = output.response.events.iter().find_map(|event| match event {
picked = output.response.events.iter().find_map(|event| match event {
CollectionEvent::Activate(index) => Some(*index),
_ => None,
});
result = GridPick { picked, cells };
});
result
picked
}
/// Recomputes grid bounds with the heading, note and inherited style used by the sheet.
+53 -50
View File
@@ -521,11 +521,9 @@ fn an_animation_frame_over_the_kept_backdrop_matches_a_full_render() {
let h = harness(s, Services::default());
let ctx = &h.ctx;
initialize_inline_frames(&mut show, ctx, &h.state().host);
// PLAN: assumed fn prefetch_backdrop(&mut self, ctx: &egui::Context, doc: &Arc<Presentation>, key: BackKey) (show-w4)
show.prefetch_backdrop(ctx, &doc, key);
show.frames.prefetch_backdrop(ctx, &doc, key);
show.frames.run_inline(16);
// PLAN: assumed fn backdrop(&mut self, ctx: &egui::Context, doc: &Arc<Presentation>, key: BackKey) -> Arc<deckcraft_render::Image> (show-w4)
let back = show.backdrop(ctx, &doc, key);
let back = show.frames.backdrop(ctx, &doc, key);
let tl = ShowState::timeline(&doc, 0);
assert!(!tl.is_empty());
// Half-way through the fade, the star half see-through over the glow.
@@ -536,11 +534,11 @@ fn an_animation_frame_over_the_kept_backdrop_matches_a_full_render() {
fast.pixels.iter().zip(&full.pixels).map(|(a, b)| a.to_array().iter().zip(b.to_array()).map(|(x, y)| x.abs_diff(y)).max().unwrap_or(0)).max();
assert!(worst.is_some_and(|d| d <= 2), "frames differ by up to {worst:?}");
// The backdrop is kept, not rendered again.
assert!(std::sync::Arc::ptr_eq(&back, &show.backdrop(ctx, &doc, key)));
assert!(std::sync::Arc::ptr_eq(&back, &show.frames.backdrop(ctx, &doc, key)));
// Another document under the same key (an edit whose copy reused the old address) gets
// its own backdrop.
let edited = std::sync::Arc::new((*doc).clone());
assert!(!std::sync::Arc::ptr_eq(&back, &show.backdrop(ctx, &edited, key)));
assert!(!std::sync::Arc::ptr_eq(&back, &show.frames.backdrop(ctx, &edited, key)));
}
#[test]
@@ -558,17 +556,15 @@ fn a_transition_keeps_the_old_slide_in_its_own_texture() {
let room = vec2(96.0, 54.0) / ctx.pixels_per_point();
let _ = prepare(&mut show, &doc, &media, ctx, 0.0, &[], room);
let old = *show.frames.current_texture().expect("the slide left is shown");
let old_key = show.frames.current_key();
let enter = show.state.goto(&doc, 1);
assert_eq!(enter, ShowAction::Slide(1));
assert!(show.apply(enter, &doc, 0.0));
let tr = show.trans.as_ref().expect("the fade plays");
assert_eq!(tr.from, Some(0));
assert_eq!(show.frames.current_key(), old_key, "the transition keeps the frame left on screen");
assert_eq!(show.frames.current_texture(), Some(&old), "the transition keeps the frame left on screen");
assert_eq!(show.frames.shown_slide(), Some(0));
let _ = prepare(&mut show, &doc, &media, ctx, 0.1, &[], room);
let new = show.frames.current_texture().expect("the new slide has a frame");
assert_ne!(show.frames.current_key(), old_key, "the new slide is stored under its own key");
// Store pages share texture ids; a picture is its page and its place on it.
assert_ne!(*new, old, "the new slide cannot overwrite the transition's old picture");
}
@@ -788,12 +784,58 @@ fn ctrl_wheel_zooms_the_show_and_the_plain_wheel_turns_the_page() {
}
}
/// Number keys pressed in the audience window, or in the presenter window when `presenter`, type a slide number
/// that Escape clears and Enter goes to.
fn typed_digits_go_to_a_slide(presenter: bool) {
use egui_kittest::kittest::Queryable;
let mut h = show_of_three();
if presenter {
let doc = h.state().session.active().unwrap().doc.clone();
h.state_mut().show = Some(Show::new(&doc, 0, false, true));
h.run_steps(2);
h.get_by_label("Next ▶").click();
} else {
click_at(&mut h, pos2(500.0, 350.0));
}
h.key_press(egui::Key::Home);
h.run_steps(2);
for (number, key) in [
egui::Key::Num0,
egui::Key::Num1,
egui::Key::Num2,
egui::Key::Num3,
egui::Key::Num4,
egui::Key::Num5,
egui::Key::Num6,
egui::Key::Num7,
egui::Key::Num8,
egui::Key::Num9,
]
.into_iter()
.enumerate()
{
h.key_press(key);
h.run_steps(2);
assert_eq!(h.state().show.as_ref().unwrap().goto.parse::<usize>().unwrap(), number, "{key:?}, presenter={presenter}");
h.key_press(egui::Key::Escape);
h.run_steps(2);
assert!(h.state().show.as_ref().unwrap().goto.is_empty());
}
h.key_press(egui::Key::Num3);
h.run_steps(2);
h.key_press(egui::Key::Enter);
h.run_steps(2);
let show = h.state().show.as_ref().unwrap();
assert_eq!(show.state.slide, 2, "typed slide 3 is zero-based slide 2");
assert!(show.goto.is_empty());
}
/// A window backs out of its own modes; typed navigation has one command owner.
#[test]
fn show_keys_move_the_show_state_in_order() {
use ShowCommands::*;
use craft::ui::canvas::{CanvasTool, ToolContext, ToolKey};
use egui_kittest::kittest::Queryable;
#[derive(Clone, Debug, Default, PartialEq)]
struct State {
@@ -910,46 +952,7 @@ fn show_keys_move_the_show_state_in_order() {
assert!(run_command(&mut show, &doc, 1.0, command, if presenter { ShowWindow::Presenter } else { ShowWindow::Audience }, &zoom));
assert_eq!(show.goto.parse::<usize>().unwrap(), number, "digit command in either window");
}
let mut h = show_of_three();
if presenter {
let doc = h.state().session.active().unwrap().doc.clone();
h.state_mut().show = Some(Show::new(&doc, 0, false, true));
h.run_steps(2);
h.get_by_label("Next ▶").click();
} else {
click_at(&mut h, pos2(500.0, 350.0));
}
h.key_press(egui::Key::Home);
h.run_steps(2);
for (number, key) in [
egui::Key::Num0,
egui::Key::Num1,
egui::Key::Num2,
egui::Key::Num3,
egui::Key::Num4,
egui::Key::Num5,
egui::Key::Num6,
egui::Key::Num7,
egui::Key::Num8,
egui::Key::Num9,
]
.into_iter()
.enumerate()
{
h.key_press(key);
h.run_steps(2);
assert_eq!(h.state().show.as_ref().unwrap().goto.parse::<usize>().unwrap(), number, "{key:?}, presenter={presenter}");
h.key_press(egui::Key::Escape);
h.run_steps(2);
assert!(h.state().show.as_ref().unwrap().goto.is_empty());
}
h.key_press(egui::Key::Num3);
h.run_steps(2);
h.key_press(egui::Key::Enter);
h.run_steps(2);
let show = h.state().show.as_ref().unwrap();
assert_eq!(show.state.slide, 2, "typed slide 3 is zero-based slide 2");
assert!(show.goto.is_empty());
typed_digits_go_to_a_slide(presenter);
}
for key in [egui::Key::B, egui::Key::W] {
let mut h = show_of_three();
+1 -1
View File
@@ -288,7 +288,7 @@ impl CanvasTool for ShowTool<'_> {
false
}
fn cursor(&self, cx: &ToolContext<'_>) -> Cursor {
fn cursor(&self, _: &ToolContext<'_>) -> Cursor {
let icon = if self.show.pen || self.show.zoom_arm || self.show.grid {
CursorIcon::Crosshair
} else if self.show.laser {
+2 -2
View File
@@ -112,9 +112,9 @@ fn grid_pass(app: &mut SlideApp, ui: &mut Ui, bcx: &mut BodyCx<'_>, show: &mut S
bars::show(ui, show, p.doc, p.room);
let thumbs = crate::thumb_source::thumbnails(&ctx);
let source = crate::thumb_source::DeckThumbs::new(p.doc.clone(), app.ui.grayscale);
let pick =
let picked =
grid::sheet(ui, grid::GridSource::Deck { doc: p.doc, thumbs: &thumbs, source: &source }, show.state.slide, super::zoom::slide_aspect(p.doc));
if let Some(index) = pick.picked {
if let Some(index) = picked {
show.grid = false;
show.blank = None;
show.dismiss_zoom(&p.zoom);
+6 -11
View File
@@ -59,13 +59,10 @@ pub(crate) fn harness_with(
fn window(cc: &mut eframe::CreationContext<'_>, session: Session, services: Services, adjust: impl FnOnce(&mut Platform)) -> SlideApp {
{
let host = craft::host::Host::builder(craft::host::AppInfo {
id: "deckcraft",
name: crate::flavor::app_name().into(),
version: crate::flavor::version().into(),
})
.files(Arc::new(craft::host::ScriptedFiles::new()))
.build();
let host =
craft::host::Host::builder(craft::host::AppInfo { id: "deckcraft", name: crate::flavor::app_name(), version: crate::flavor::version() })
.files(Arc::new(craft::host::ScriptedFiles::new()))
.build();
let clipboard = craft::platform::clipboard::Clipboard::new(craft::platform::clipboard::MemoryClipboard::default());
let mut platform = Platform {
install: craft::ui::runtime::InstallSpec::new(Default::default(), Arc::new(craft::window::system::SystemWindows))
@@ -83,10 +80,8 @@ fn window(cc: &mut eframe::CreationContext<'_>, session: Session, services: Serv
let mut app = SlideApp::new(&cc.egui_ctx, platform).unwrap_or_else(|error| panic!("test window installation failed: {error}"));
app.session = session;
app.services = services;
let generation = app.catalog_generation.wrapping_add(1);
let catalog = super::app::catalog::build(&app.session, generation).unwrap_or_else(|error| panic!("test command catalogue failed: {error}"));
app.catalog = catalog;
app.catalog_generation = generation;
let generation = app.catalog.generation().wrapping_add(1);
app.catalog = super::app::catalog::build(&app.session, generation).unwrap_or_else(|error| panic!("test command catalogue failed: {error}"));
app
}
}