diff --git a/crates/ui-egui/src/presenter.rs b/crates/ui-egui/src/presenter.rs index e33615c92..6336f9ec9 100644 --- a/crates/ui-egui/src/presenter.rs +++ b/crates/ui-egui/src/presenter.rs @@ -380,11 +380,11 @@ mod tests { let original_slide = data.slide; let mut h = popup_harness(data); h.run_steps(2); - h.get_by_role_and_label(egui::accesskit::Role::Button, "Next").click(); + h.get_by_role_and_label(egui::accesskit::Role::Button, "Next ▶").click(); h.run_steps(2); let next = Command::Run { command: ShowCommands::Next.id().into() }; assert_eq!(h.state().sent, vec![next.clone()]); - h.get_by_role_and_label(egui::accesskit::Role::Button, "Next").focus(); + h.get_by_role_and_label(egui::accesskit::Role::Button, "Next ▶").focus(); h.run_steps(2); h.key_press(egui::Key::Space); h.run_steps(2); diff --git a/crates/ui-egui/src/presenter_view.rs b/crates/ui-egui/src/presenter_view.rs index ee76d13d5..cc0ef75e2 100644 --- a/crates/ui-egui/src/presenter_view.rs +++ b/crates/ui-egui/src/presenter_view.rs @@ -13,6 +13,7 @@ use craft::ui::layout_components::{Grid, Row, Stack}; use craft::ui::list::ThumbAspect; use craft::ui::primitives::{CachedTexture, PaintShape, StrokeWidth, TextRun}; use craft::ui::runtime::commands::{CommandScope, CommandSet as _, CommandState, Commands as _}; +use craft::ui::runtime::keys::{Intent, with_window_intents}; use craft::ui::style::{DataColor, SurfaceKind, TypeRole}; use deckcraft_model::text::TextBody; @@ -137,6 +138,11 @@ pub fn presenter_body(ui: &mut egui::Ui, _cx: &mut BodyCx<'_>, model: &Presenter while let Some((command, _)) = cx.take_command::() { out.push(Command::Run { command: command.id().to_owned() }); } + // Plain Escape is a scope escape, not a shortcut: the window's leftover one is this window's Cancel. A + // presenter shown as a layer over the audience is the window in front, so it reads first. + if !craft::ui::runtime::measure::active(ui.ctx()) && with_window_intents(ui.ctx(), false, |intents| intents.take(Intent::Cancel)) { + out.push(Command::Run { command: ShowCommands::Cancel.id().to_owned() }); + } }); } diff --git a/crates/ui-egui/src/show/grid.rs b/crates/ui-egui/src/show/grid.rs index 8afe3b663..f54ab5b86 100644 --- a/crates/ui-egui/src/show/grid.rs +++ b/crates/ui-egui/src/show/grid.rs @@ -106,13 +106,12 @@ pub(crate) fn sheet(ui: &mut Ui, slides: GridSource<'_>, current: usize, aspect: let hidden = matches!(&slides, GridSource::Deck { doc, .. } if doc.slides.get(index).is_some_and(|slide| slide.hidden)); let template = if hidden { "{n} Hidden" } else { "{n}" }; let label = env.words.get(Word::plain(template)).replace("{n}", &(index + 1).to_string()); + // The tile carries the slide's name; its picture is decoration. let picture = match &slides { - GridSource::Deck { doc, thumbs, source } => { - thumb_source::picture(label.clone(), ThumbKey::Slide(doc.slides[index].id), thumbs, source) - } + GridSource::Deck { doc, thumbs, source } => thumb_source::picture("", ThumbKey::Slide(doc.slides[index].id), thumbs, source), GridSource::Pictures(pictures) => { let texture = pictures[index]; - Picture::painter(label.clone(), thumb_aspect, move |cx, rect| { + Picture::painter("", thumb_aspect, move |cx, rect| { cx.painter.image(texture.id, rect, texture.uv(), egui::Color32::WHITE); }) } diff --git a/crates/ui-egui/src/show/tests.rs b/crates/ui-egui/src/show/tests.rs index 353ec9e4c..aabd48999 100644 --- a/crates/ui-egui/src/show/tests.rs +++ b/crates/ui-egui/src/show/tests.rs @@ -423,9 +423,9 @@ fn the_prefetched_frame_is_the_frame_shown_on_entry() { let enter = show.state.goto(&doc, 1); assert!(show.apply(enter, &doc, 1.0)); let _ = prepare(&mut show, &doc, &media, ctx, 1.0, &[], room); - let texture = show.frames.current_texture().expect("the prefetched slide is shown"); assert_eq!(show.frames.shown_slide(), Some(1)); - let got = uploaded_picture(ctx, texture.id); + let got = show.frames.current_source(ctx).expect("the prefetched slide is shown"); + let got = &got.image; let want = render_frame(&doc, 1, ShowState::timeline(&doc, 1), 0, 0.0, size, vec![], &[], 0, &[], &[], None); assert_eq!(got.size, want.size); assert_eq!(got.pixels, want.pixels); @@ -445,13 +445,6 @@ fn initialize_inline_frames(show: &mut Show, ctx: &egui::Context, host: &craft:: ); } -fn uploaded_picture(ctx: &egui::Context, id: egui::TextureId) -> Arc { - let delta = ctx.tex_manager().write().take_delta(); - let image = delta.set.get(&id).and_then(|deltas| deltas.last()).expect("the shown picture was uploaded").image.clone(); - let egui::ImageData::Color(image) = image; - image -} - /// A glowing layout is expensive to render; reusing its backdrop must preserve the animation's pixels. #[test] fn an_animation_frame_over_the_kept_backdrop_matches_a_full_render() { @@ -515,14 +508,19 @@ 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"); - assert!(show.apply(ShowAction::Slide(1), &doc, 0.0)); + 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_texture(), Some(&old), "the transition keeps the frame left on screen"); + assert_eq!(show.frames.current_key(), old_key, "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!(new.id, old.id, "the new slide cannot overwrite the transition's old picture"); + 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"); } /// #2089: a slide's With Previous entrance waits for the slide's transition to finish, as in diff --git a/crates/ui-egui/src/show/ui.rs b/crates/ui-egui/src/show/ui.rs index 3142fffc4..33b5720b8 100644 --- a/crates/ui-egui/src/show/ui.rs +++ b/crates/ui-egui/src/show/ui.rs @@ -19,6 +19,7 @@ use craft::ui::contract::{Bind, BodyCx, Props as _, Show as _, ShowContainer as use craft::ui::primitives::texture_side; use craft::ui::runtime::commands::{CommandState, Commands as _}; use craft::ui::runtime::env::{Word, with_env}; +use craft::ui::runtime::keys::{Intent, with_window_intents}; use craft::ui::runtime::{frame, measure, pointer}; use deckcraft_model::Presentation; use egui::{Rect, Ui, UiBuilder}; @@ -88,6 +89,14 @@ pub(crate) fn ui(app: &mut SlideApp, ui: &mut Ui, bcx: &mut BodyCx<'_>) { if out.keep && show.presenter && !show.reading { out.keep &= presenter_pass(ui, app, &mut show, &doc, now); } + // A plain Enter or Escape is the window's, never a shortcut: the page reads the ones nothing else took, last in its + // pass. + if out.keep && with_window_intents(&ctx, false, |intents| intents.take(Intent::Submit)) { + out.keep &= run_command(&mut show, &doc, now, ShowCommands::GoToTyped, ShowWindow::Audience, &pass.zoom); + } + if out.keep && with_window_intents(&ctx, false, |intents| intents.take(Intent::Cancel)) { + out.keep &= run_command(&mut show, &doc, now, ShowCommands::Cancel, ShowWindow::Audience, &pass.zoom); + } let wake = match (show.next_wake(&doc, now), media_wake) { (Some(a), Some(b)) => Some(a.min(b)), (a, b) => a.or(b),