Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(rendering): morph the display card aside for text takeover layouts

Richie McIlroy6606be1acb3f
diff --git a/crates/rendering/src/layers/captions.rs b/crates/rendering/src/layers/captions.rs
index 549b78a94..6a259c96d 100644
--- a/crates/rendering/src/layers/captions.rs
+++ b/crates/rendering/src/layers/captions.rs
@@ -534,7 +534,7 @@ impl CaptionsLayer {
active.segment.start,
effective_end,
segment_fade,
- );
+ ) * uniforms.takeover_overlay_fade();
if fade_opacity <= 0.0 {
self.current_text = None;
return;
diff --git a/crates/rendering/src/layers/cursor.rs b/crates/rendering/src/layers/cursor.rs
index db479d057..4b265d810 100644
--- a/crates/rendering/src/layers/cursor.rs
+++ b/crates/rendering/src/layers/cursor.rs
@@ -594,6 +594,34 @@ impl CursorLayer {
],
};
+ // A text takeover relocates the display card by a uniform scale +
+ // translate (the takeover target preserves the card's aspect), so the
+ // cursor follows with the same affine map — and fades with the card
+ // when a Fullscreen takeover hides it.
+ let (position_size, cursor_opacity) = match &uniforms.takeover {
+ Some(takeover) if takeover.t > 0.001 => {
+ let from_w = (takeover.from[2] - takeover.from[0]).max(f32::EPSILON);
+ let scale = (takeover.to[2] - takeover.to[0]) / from_w;
+ let mapped = [
+ takeover.to[0] + (position_size[0] - takeover.from[0]) * scale,
+ takeover.to[1] + (position_size[1] - takeover.from[1]) * scale,
+ position_size[2] * scale,
+ position_size[3] * scale,
+ ];
+ let t = takeover.t;
+ (
+ [
+ crate::lerp_f32(position_size[0], mapped[0], t),
+ crate::lerp_f32(position_size[1], mapped[1], t),
+ crate::lerp_f32(position_size[2], mapped[2], t),
+ crate::lerp_f32(position_size[3], mapped[3], t),
+ ],
+ cursor_opacity * takeover.cursor_fade,
+ )
+ }
+ _ => (position_size, cursor_opacity),
+ };
+
let cursor_grade = if uniforms.project.color_correction.grade_cursor {
uniforms.screen_color_grade
} else {
diff --git a/crates/rendering/src/layers/keyboard.rs b/crates/rendering/src/layers/keyboard.rs
index 97cf42063..74f26a279 100644
--- a/crates/rendering/src/layers/keyboard.rs
+++ b/crates/rendering/src/layers/keyboard.rs
@@ -343,7 +343,7 @@ impl KeyboardLayer {
active.segment.start,
active.segment.end,
segment_fade,
- );
+ ) * uniforms.takeover_overlay_fade();
if fade_opacity <= 0.0 {
return;
diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rs
index dfca86300..9ad3f5ea4 100644
--- a/crates/rendering/src/lib.rs
+++ b/crates/rendering/src/lib.rs
@@ -48,6 +48,7 @@ pub mod notch_shape;
mod project_recordings;
mod scene;
pub mod spring_mass_damper;
+mod takeover;
mod text;
mod transition;
pub mod yuv_converter;
@@ -74,6 +75,8 @@ use camera3d::{Camera3DFrame, interpolate_camera3d};
pub use cursor_interpolation::PrecomputedCursorTimeline;
use mask::interpolate_masks;
use scene::*;
+use takeover::InterpolatedTakeover;
+pub use takeover::TakeoverDisplayMorph;
use text::{PreparedText, prepare_texts};
use zoom::*;
pub use zoom_spring::{CursorCropMap, ZoomTransformTimeline};
@@ -2263,6 +2266,10 @@ pub struct ProjectUniforms {
pub zoom: InterpolatedZoom,
pub scene: InterpolatedScene,
pub split: Option<SplitLayoutComputed>,
+ /// Display-card morph driven by a non-Overlay text segment; `None` when
+ /// no takeover is active. The cursor layer follows it the same way it
+ /// follows `split`.
+ pub takeover: Option<TakeoverDisplayMorph>,
pub resolution_base: XY<u32>,
pub display_parent_motion_px: XY<f32>,
pub motion_blur_amount: f32,
@@ -2745,6 +2752,15 @@ pub(crate) struct DisplayLayout {
}
impl ProjectUniforms {
+ /// 0..1 multiplier for recording-anchored overlays (captions, keyboard)
+ /// while a text takeover hides the recording — they would otherwise hang
+ /// frozen over the title card while the recording clock is paused.
+ pub fn takeover_overlay_fade(&self) -> f32 {
+ self.takeover
+ .as_ref()
+ .map_or(1.0, |takeover| 1.0 - takeover.t)
+ }
+
pub fn frame_layout(&self) -> FrameLayout {
FrameLayout {
display: self.display_outer_bounds,
@@ -3519,8 +3535,23 @@ impl ProjectUniforms {
None
};
+ // Text-takeover morph: a non-Overlay text segment pushes the display
+ // aside (Fullscreen) or into a padded half (Split*). None on every
+ // frame without such a segment, which leaves all the math below
+ // exactly as it was.
+ let takeover = project.timeline.as_ref().and_then(|timeline| {
+ InterpolatedTakeover::sample(frame_time as f64, &timeline.text_segments)
+ });
+
let mut camera3d_zoom: Option<camera3d::Camera3DScreenZoom> = None;
- let (display, display_motion_parent, frame_chrome, display_outer_bounds, notch) = {
+ let (
+ display,
+ display_motion_parent,
+ frame_chrome,
+ display_outer_bounds,
+ notch,
+ takeover_morph,
+ ) = {
let output_size = XY::new(output_size.0 as f64, output_size.1 as f64);
let size = [options.screen_size.x as f32, options.screen_size.y as f32];
@@ -3615,6 +3646,28 @@ impl ProjectUniforms {
let final_crop_bounds = split_layout.as_ref().map_or(base_crop_bounds, |s| {
s.screen.crop_for(final_target_bounds, split_t)
});
+
+ // Text takeover composes after the split morph at the same seam:
+ // lerp the (possibly split) rect toward the takeover target. The
+ // target preserves the current rect's aspect, so the crop derived
+ // above stays valid and content never distorts.
+ let takeover_t = takeover.map_or(0.0, |tk| tk.t);
+ let takeover_display_fade = takeover.map_or(1.0, |tk| tk.display_fade());
+ let takeover_accessory_fade = takeover.map_or(1.0, |tk| tk.accessory_fade());
+ let takeover_card_t = takeover.map_or(0.0, |tk| tk.card_style_t());
+ let takeover_padding = output_size.x.min(output_size.y) as f32 * FLOATING_PADDING_FRAC;
+ let pre_takeover_bounds = final_target_bounds;
+ let takeover_target = takeover.map(|tk| {
+ tk.display_target(
+ pre_takeover_bounds,
+ (output_size.x as f32, output_size.y as f32),
+ takeover_padding,
+ )
+ });
+ let final_target_bounds = takeover_target.map_or(final_target_bounds, |target| {
+ lerp_bounds(pre_takeover_bounds, target, takeover_t)
+ });
+
let final_target_size = [
final_target_bounds[2] - final_target_bounds[0],
final_target_bounds[3] - final_target_bounds[1],
@@ -3624,6 +3677,9 @@ impl ProjectUniforms {
let display_rounding_px =
(project.background.rounding / 100.0 * 0.5 * final_min_axis) as f32 * split_fade
+ floating_rounding_px * floating_t;
+ // A split takeover styles the display as a floating card.
+ let display_rounding_px =
+ lerp_f32(display_rounding_px, floating_rounding_px, takeover_card_t);
let frame_active = frame_config.is_some();
// With a frame active the card decoration (shadow/border) moves to
// the chrome pass; the video keeps only the floating-card shadow
@@ -3640,16 +3696,23 @@ impl ProjectUniforms {
// fades out, so the multipliers relax back to uniform rounding.
let display_corner_radii = match frame_config.as_ref().map(|f| f.style) {
Some(FrameStyle::MacOS | FrameStyle::Windows | FrameStyle::Browser) => {
- [split_t, split_t, 1.0, 1.0]
+ // The chrome bar also fades out under a takeover, so the
+ // top corners regain their rounding the same way they do
+ // in a split.
+ let top = split_t.max(takeover_t);
+ [top, top, 1.0, 1.0]
}
_ => [1.0; 4],
};
+ // The shader draws border and shadow outside the card shape,
+ // unscaled by the opacity uniform — fade them explicitly or they
+ // outlive a Fullscreen takeover's fade.
let border_color = if let Some(b) = project.background.border.as_ref() {
[
b.color[0] as f32 / 255.0,
b.color[1] as f32 / 255.0,
b.color[2] as f32 / 255.0,
- (b.opacity / 100.0).clamp(0.0, 1.0),
+ (b.opacity / 100.0).clamp(0.0, 1.0) * takeover_display_fade,
]
} else {
[0.0, 0.0, 0.0, 0.0]
@@ -3678,6 +3741,9 @@ impl ProjectUniforms {
let chrome_bounds = split_layout.as_ref().map_or(base_outer_bounds, |s| {
lerp_bounds(base_outer_bounds, s.screen.target, split_t)
});
+ let chrome_bounds = takeover_target.map_or(chrome_bounds, |target| {
+ lerp_bounds(chrome_bounds, target, takeover_t)
+ });
let chrome_size = [
chrome_bounds[2] - chrome_bounds[0],
chrome_bounds[3] - chrome_bounds[1],
@@ -3705,7 +3771,10 @@ impl ProjectUniforms {
0.0,
],
shadow: if decorated {
- project.background.shadow * split_fade * camera3d_shadow_fade
+ project.background.shadow
+ * split_fade
+ * camera3d_shadow_fade
+ * takeover_accessory_fade
} else {
0.0
},
@@ -3720,13 +3789,14 @@ impl ProjectUniforms {
.as_ref()
.map_or(18.0, |s| s.opacity)
* split_fade
- * camera3d_shadow_fade,
+ * camera3d_shadow_fade
+ * takeover_accessory_fade,
shadow_blur: project
.background
.advanced_shadow
.as_ref()
.map_or(50.0, |s| s.blur),
- opacity: scene.screen_opacity as f32 * split_fade,
+ opacity: scene.screen_opacity as f32 * split_fade * takeover_accessory_fade,
border_enabled: if decorated && border_on { 1.0 } else { 0.0 },
border_width: project.background.border.as_ref().map_or(5.0, |b| b.width),
preserve_source_alpha: 1.0,
@@ -3790,9 +3860,12 @@ impl ProjectUniforms {
shadow_size: 0.0,
shadow_opacity: 0.0,
shadow_blur: 0.0,
- // Fades out as a split-screen scene morphs in, where
- // the geometry above stops describing the pane.
- opacity: scene.screen_opacity as f32 * split_fade,
+ // Fades out as a split-screen scene or a text
+ // takeover morphs in, where the geometry above
+ // stops describing the pane.
+ opacity: scene.screen_opacity as f32
+ * split_fade
+ * takeover_accessory_fade,
border_enabled: 0.0,
border_width: 0.0,
_padding1: [0.0; 3],
@@ -3829,7 +3902,8 @@ impl ProjectUniforms {
],
shadow: project.background.shadow
* display_decoration_fade
- * camera3d_shadow_fade,
+ * camera3d_shadow_fade
+ * takeover_display_fade,
shadow_size: project
.background
.advanced_shadow
@@ -3841,13 +3915,14 @@ impl ProjectUniforms {
.as_ref()
.map_or(18.0, |s| s.opacity)
* display_decoration_fade
- * camera3d_shadow_fade,
+ * camera3d_shadow_fade
+ * takeover_display_fade,
shadow_blur: project
.background
.advanced_shadow
.as_ref()
.map_or(50.0, |s| s.blur),
- opacity: scene.screen_opacity as f32,
+ opacity: scene.screen_opacity as f32 * takeover_display_fade,
border_enabled: if border_on && !frame_active { 1.0 } else { 0.0 },
border_width: project.background.border.as_ref().map_or(5.0, |b| b.width),
preserve_source_alpha: if options.preserve_screen_alpha {
@@ -3866,6 +3941,14 @@ impl ProjectUniforms {
frame_chrome,
display_outer_bounds,
notch,
+ takeover
+ .zip(takeover_target)
+ .map(|(tk, target)| TakeoverDisplayMorph {
+ t: tk.t,
+ from: pre_takeover_bounds,
+ to: target,
+ cursor_fade: tk.display_fade(),
+ }),
)
};
@@ -3999,6 +4082,10 @@ impl ProjectUniforms {
// Same chrome rule as the display layer: classic split strips
// rounding/shadow, the floating card keeps them.
let chrome_fade = (1.0 - split_t + floating_t).clamp(0.0, 1.0);
+ // The shader draws the drop shadow outside the card without the
+ // opacity uniform, so a takeover must fade the shadow uniforms
+ // explicitly or it outlives the hidden bubble.
+ let takeover_fade = takeover.map_or(1.0, |tk| tk.accessory_fade());
let final_target_bounds = snap_bounds_to_output_pixels(
split_layout.as_ref().map_or(target_bounds, |s| {
lerp_bounds(target_bounds, s.camera.target, split_t)
@@ -4038,7 +4125,10 @@ impl ProjectUniforms {
camera_descriptor.zoom_amount,
0.0,
],
- shadow: project.camera.shadow * chrome_fade * camera3d_shadow_fade,
+ shadow: project.camera.shadow
+ * chrome_fade
+ * camera3d_shadow_fade
+ * takeover_fade,
shadow_size: project
.camera
.advanced_shadow
@@ -4050,13 +4140,16 @@ impl ProjectUniforms {
.as_ref()
.map_or(18.0, |s| s.opacity)
* chrome_fade
- * camera3d_shadow_fade,
+ * camera3d_shadow_fade
+ * takeover_fade,
shadow_blur: project
.camera
.advanced_shadow
.as_ref()
.map_or(50.0, |s| s.blur),
- opacity: scene.regular_camera_transition_opacity() as f32,
+ // The bubble yields to a text takeover so it can never
+ // collide with the text's half of the frame.
+ opacity: scene.regular_camera_transition_opacity() as f32 * takeover_fade,
border_enabled: 0.0,
border_width: 0.0,
preserve_source_alpha: 0.0,
@@ -4156,7 +4249,8 @@ impl ProjectUniforms {
shadow_size: 0.0,
shadow_opacity: 0.0,
shadow_blur: 0.0,
- opacity: scene.camera_only_transition_opacity() as f32,
+ opacity: scene.camera_only_transition_opacity() as f32
+ * takeover.map_or(1.0, |tk| tk.accessory_fade()),
border_enabled: 0.0,
border_width: 0.0,
preserve_source_alpha: 0.0,
@@ -4209,6 +4303,7 @@ impl ProjectUniforms {
zoom,
scene,
split: split_layout,
+ takeover: takeover_morph,
interpolated_cursor,
frame_rate: fps,
frame_number,
@@ -5822,6 +5917,9 @@ impl RendererLayers {
let should_render_screen = render_display
&& uniforms.scene.should_render_screen()
+ // A fully-faded card (e.g. a held Fullscreen text takeover) draws
+ // nothing visible; skip the pass entirely.
+ && uniforms.display.opacity > 0.001
&& self.display.has_valid_frame();
let should_render_cursor = if render_display {
uniforms.scene.should_render_screen()
diff --git a/crates/rendering/src/takeover.rs b/crates/rendering/src/takeover.rs
new file mode 100644
index 000000000..62dd38d7e
--- /dev/null
+++ b/crates/rendering/src/takeover.rs
@@ -0,0 +1,285 @@
+use cap_project::{TextLayout, TextSegment};
+
+/// At full takeover a Fullscreen text leaves the display card at this scale
+/// (about its center) as it fades, so the hand-off reads as a push-back
+/// rather than a bare crossfade.
+pub const TAKEOVER_FULLSCREEN_SHRINK: f32 = 0.92;
+const MIN_TRANSITION: f64 = 0.05;
+
+/// Per-frame state of the text-takeover morph: how far (`t`, eased 0..1) the
+/// display has yielded the frame to a non-Overlay text segment, and which
+/// layout it is yielding to. `None` when every active text segment is a plain
+/// overlay — the pipeline then computes exactly what it did before this
+/// feature existed.
+#[derive(Clone, Copy, Debug)]
+pub struct InterpolatedTakeover {
+ pub t: f32,
+ pub layout: TextLayout,
+}
+
+/// Cursor-side view of the display morph: the display card's pre-takeover
+/// rect, its rect at full takeover, and the morph amount. The takeover
+/// target preserves the card's aspect, so the cursor remap is a uniform
+/// scale + translate.
+#[derive(Clone, Copy, Debug)]
+pub struct TakeoverDisplayMorph {
+ pub t: f32,
+ pub from: [f32; 4],
+ pub to: [f32; 4],
+ /// Multiplier for the cursor sprite's opacity (fades with the display in
+ /// Fullscreen, stays 1 for splits where the card remains visible).
+ pub cursor_fade: f32,
+}
+
+impl InterpolatedTakeover {
+ pub fn sample(frame_time: f64, segments: &[TextSegment]) -> Option<Self> {
+ let mut best: Option<(f32, f64, TextLayout)> = None;
+ for segment in segments {
+ if !segment.enabled || segment.layout == TextLayout::Overlay {
+ continue;
+ }
+ if frame_time < segment.start || frame_time > segment.end {
+ continue;
+ }
+ let half = ((segment.end - segment.start) / 2.0).max(MIN_TRANSITION);
+ let duration = segment.layout_transition.clamp(MIN_TRANSITION, half);
+ let progress = ((frame_time - segment.start) / duration)
+ .min((segment.end - frame_time) / duration)
+ .clamp(0.0, 1.0) as f32;
+ if progress <= 0.0 {
+ continue;
+ }
+ let replace = match best {
+ None => true,
+ Some((t, start, _)) => progress > t || (progress == t && segment.start > start),
+ };
+ if replace {
+ best = Some((progress, segment.start, segment.layout));
+ }
+ }
+ best.map(|(progress, _, layout)| {
+ // Same cubic-bezier(0.42, 0, 0.58, 1) the scene transitions use,
+ // so display morphs feel identical across features.
+ let ease_in_out = bezier_easing::bezier_easing(0.42, 0.0, 0.58, 1.0).unwrap();
+ Self {
+ t: ease_in_out(progress),
+ layout,
+ }
+ })
+ }
+
+ /// The display card's rect at FULL takeover (`t == 1`); callers lerp from
+ /// the pre-takeover rect toward it by `t`. Splits contain-fit the card's
+ /// current aspect into the padded opposite half, so the crop — and with
+ /// it the visible content — never distorts mid-morph.
+ pub fn display_target(
+ &self,
+ base: [f32; 4],
+ output_size: (f32, f32),
+ padding: f32,
+ ) -> [f32; 4] {
+ match self.layout {
+ TextLayout::Overlay => base,
+ TextLayout::Fullscreen => shrink_about_center(base, TAKEOVER_FULLSCREEN_SHRINK),
+ TextLayout::SplitLeft | TextLayout::SplitRight => {
+ let (out_w, out_h) = output_size;
+ let mid = out_w * 0.5;
+ let half_box = if self.layout == TextLayout::SplitLeft {
+ [mid + padding, padding, out_w - padding, out_h - padding]
+ } else {
+ [padding, padding, mid - padding, out_h - padding]
+ };
+ contain_aspect(base, half_box)
+ }
+ }
+ }
+
+ /// Multiplier for the display card's own opacity, and for the decoration
+ /// (shadow/border) the shader draws OUTSIDE the card shape — the fragment
+ /// returns those unscaled by the opacity uniform, so they must fade here
+ /// or a ghost shadow outlives a Fullscreen takeover.
+ pub fn display_fade(&self) -> f32 {
+ match self.layout {
+ TextLayout::Fullscreen => 1.0 - self.t,
+ _ => 1.0,
+ }
+ }
+
+ /// Multiplier for layers whose geometry stops describing the morphed
+ /// card (notch, frame chrome) or that would collide with the text
+ /// (camera bubble, camera-only plane).
+ pub fn accessory_fade(&self) -> f32 {
+ 1.0 - self.t
+ }
+
+ /// 0..1 amount of floating-card styling (rounding) the display picks up;
+ /// only splits become cards — a Fullscreen card keeps its look while it
+ /// fades.
+ pub fn card_style_t(&self) -> f32 {
+ match self.layout {
+ TextLayout::SplitLeft | TextLayout::SplitRight => self.t,
+ _ => 0.0,
+ }
+ }
+}
+
+fn shrink_about_center(bounds: [f32; 4], scale: f32) -> [f32; 4] {
+ let cx = (bounds[0] + bounds[2]) * 0.5;
+ let cy = (bounds[1] + bounds[3]) * 0.5;
+ let hw = (bounds[2] - bounds[0]) * 0.5 * scale;
+ let hh = (bounds[3] - bounds[1]) * 0.5 * scale;
+ [cx - hw, cy - hh, cx + hw, cy + hh]
+}
+
+fn contain_aspect(base: [f32; 4], container: [f32; 4]) -> [f32; 4] {
+ let base_w = (base[2] - base[0]).max(f32::EPSILON);
+ let base_h = (base[3] - base[1]).max(f32::EPSILON);
+ let aspect = base_w / base_h;
+ let box_w = (container[2] - container[0]).max(f32::EPSILON);
+ let box_h = (container[3] - container[1]).max(f32::EPSILON);
+ let (w, h) = if box_w / box_h > aspect {
+ (box_h * aspect, box_h)
+ } else {
+ (box_w, box_w / aspect)
+ };
+ let cx = (container[0] + container[2]) * 0.5;
+ let cy = (container[1] + container[3]) * 0.5;
+ [cx - w * 0.5, cy - h * 0.5, cx + w * 0.5, cy + h * 0.5]
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use cap_project::{TextAlign, TextAnimation, XY};
+
+ fn segment(layout: TextLayout, start: f64, end: f64) -> TextSegment {
+ TextSegment {
+ start,
+ end,
+ track: 0,
+ enabled: true,
+ content: "Text".to_string(),
+ center: XY::new(0.5, 0.5),
+ size: XY::new(0.35, 0.2),
+ font_family: "sans-serif".to_string(),
+ font_size: 48.0,
+ font_weight: 700.0,
+ italic: false,
+ color: "#ffffff".to_string(),
+ fade_duration: 0.15,
+ align: TextAlign::Center,
+ letter_spacing: 0.0,
+ line_height: 1.2,
+ opacity: 1.0,
+ shadow: 0.0,
+ animation_in: TextAnimation::Fade,
+ animation_out: TextAnimation::Fade,
+ animation_in_duration: 0.15,
+ animation_out_duration: 0.15,
+ layout,
+ layout_transition: 0.5,
+ }
+ }
+
+ #[test]
+ fn overlay_segments_never_produce_a_takeover() {
+ let segments = [segment(TextLayout::Overlay, 0.0, 10.0)];
+ assert!(InterpolatedTakeover::sample(5.0, &segments).is_none());
+ }
+
+ #[test]
+ fn takeover_is_none_outside_the_segment() {
+ let segments = [segment(TextLayout::Fullscreen, 2.0, 4.0)];
+ assert!(InterpolatedTakeover::sample(1.0, &segments).is_none());
+ assert!(InterpolatedTakeover::sample(5.0, &segments).is_none());
+ assert!(InterpolatedTakeover::sample(2.0, &segments).is_none());
+ }
+
+ #[test]
+ fn takeover_ramps_in_and_out() {
+ let segments = [segment(TextLayout::Fullscreen, 0.0, 10.0)];
+ let entering = InterpolatedTakeover::sample(0.25, &segments).unwrap();
+ assert!(entering.t > 0.0 && entering.t < 1.0);
+ let held = InterpolatedTakeover::sample(5.0, &segments).unwrap();
+ assert_eq!(held.t, 1.0);
+ let exiting = InterpolatedTakeover::sample(9.75, &segments).unwrap();
+ assert!(exiting.t > 0.0 && exiting.t < 1.0);
+ }
+
+ #[test]
+ fn disabled_segments_are_ignored() {
+ let mut seg = segment(TextLayout::Fullscreen, 0.0, 10.0);
+ seg.enabled = false;
+ assert!(InterpolatedTakeover::sample(5.0, &[seg]).is_none());
+ }
+
+ #[test]
+ fn dominant_segment_wins() {
+ let fading = segment(TextLayout::Fullscreen, 0.0, 5.1);
+ let entering = segment(TextLayout::SplitLeft, 5.0, 10.0);
+ let sampled = InterpolatedTakeover::sample(5.05, &[fading, entering]).unwrap();
+ // Both are near-zero activity at the crossover; the later start wins
+ // ties, and by 5.4 the entering split clearly dominates.
+ let later = InterpolatedTakeover::sample(
+ 5.4,
+ &[
+ segment(TextLayout::Fullscreen, 0.0, 5.1),
+ segment(TextLayout::SplitLeft, 5.0, 10.0),
+ ],
+ )
+ .unwrap();
+ assert_eq!(later.layout, TextLayout::SplitLeft);
+ assert!(sampled.t <= later.t);
+ }
+
+ #[test]
+ fn split_target_preserves_aspect_in_opposite_half() {
+ let takeover = InterpolatedTakeover {
+ t: 1.0,
+ layout: TextLayout::SplitLeft,
+ };
+ let base = [100.0, 100.0, 1820.0, 980.0];
+ let target = takeover.display_target(base, (1920.0, 1080.0), 54.0);
+ let base_aspect = (base[2] - base[0]) / (base[3] - base[1]);
+ let target_aspect = (target[2] - target[0]) / (target[3] - target[1]);
+ assert!((base_aspect - target_aspect).abs() < 1e-3);
+ // Text-left means the card lives entirely in the right half.
+ assert!(target[0] >= 960.0);
+ assert!(target[2] <= 1920.0);
+ }
+
+ #[test]
+ fn fullscreen_target_shrinks_about_center() {
+ let takeover = InterpolatedTakeover {
+ t: 1.0,
+ layout: TextLayout::Fullscreen,
+ };
+ let base = [0.0, 0.0, 1920.0, 1080.0];
+ let target = takeover.display_target(base, (1920.0, 1080.0), 54.0);
+ assert!((target[0] + target[2] - 1920.0).abs() < 1e-3);
+ assert!((target[1] + target[3] - 1080.0).abs() < 1e-3);
+ assert!((target[2] - target[0]) < 1920.0);
+ assert_eq!(takeover.display_fade(), 0.0);
+ }
+
+ #[test]
+ fn split_keeps_display_visible() {
+ let takeover = InterpolatedTakeover {
+ t: 1.0,
+ layout: TextLayout::SplitRight,
+ };
+ assert_eq!(takeover.display_fade(), 1.0);
+ assert_eq!(takeover.accessory_fade(), 0.0);
+ assert_eq!(takeover.card_style_t(), 1.0);
+ }
+
+ #[test]
+ fn transition_clamps_to_half_segment_length() {
+ let mut seg = segment(TextLayout::Fullscreen, 0.0, 0.4);
+ seg.layout_transition = 5.0;
+ // With the transition clamped to 0.2s, the midpoint reaches full
+ // takeover instead of being stuck near zero.
+ let mid = InterpolatedTakeover::sample(0.2, &[seg]).unwrap();
+ assert_eq!(mid.t, 1.0);
+ }
+}