diff --git a/crates/model/src/lib.rs b/crates/model/src/lib.rs index 735672ef6..713cc7b62 100644 --- a/crates/model/src/lib.rs +++ b/crates/model/src/lib.rs @@ -254,6 +254,16 @@ 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)] diff --git a/crates/model/src/tests.rs b/crates/model/src/tests.rs index 4ae6fc0fd..32e061804 100644 --- a/crates/model/src/tests.rs +++ b/crates/model/src/tests.rs @@ -1,7 +1,7 @@ use super::{ - 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, + 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, }; use crate::resolve::Ctx; @@ -339,3 +339,19 @@ 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"); +} diff --git a/crates/ui-egui/src/show/ui.rs b/crates/ui-egui/src/show/ui.rs index d048fb93c..df2e8b460 100644 --- a/crates/ui-egui/src/show/ui.rs +++ b/crates/ui-egui/src/show/ui.rs @@ -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 = media .iter() - .filter(|(id, _, clip)| clip.hide_while_not_playing && !app.media.status(*id).is_some_and(|s| s.state != deckcraft_media::PlayState::Ended)) + .filter(|(id, _, clip)| clip.hidden_during_show(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);