fix(tui/glitch_animation): compute render rect first and scale against it; early-bail on small effective area; cap height to scaled glyphs

This commit is contained in:
James Peter
2025-08-30 10:24:38 +10:00
parent 70bd689249
commit 8268dd18d0
+24 -34
View File
@@ -16,11 +16,17 @@ pub fn render_intro_animation_with_alpha(area: Rect, buf: &mut Buffer, t: f32, a
// Outline fill animation - inline, no borders
pub fn render_intro_outline_fill(area: Rect, buf: &mut Buffer, t: f32) {
if area.width < 40 || area.height < 10 {
tracing::warn!("!!! Area too small for animation: {}x{} (need 40x10)", area.width, area.height);
// Compute the final render rect first (including our 1‑col right shift)
let mut r = area;
if r.width > 0 {
r.x = r.x.saturating_add(1);
r.width = r.width.saturating_sub(1);
}
// Bail out early if the effective render rect is too small
if r.width < 40 || r.height < 10 {
tracing::warn!("!!! Area too small for animation: {}x{} (need 40x10)", r.width, r.height);
return;
}
// area is sufficient; proceed with render
let t = t.clamp(0.0, 1.0);
let outline_p = smoothstep(0.00, 0.60, t); // outline draws L->R
@@ -29,23 +35,12 @@ pub fn render_intro_outline_fill(area: Rect, buf: &mut Buffer, t: f32) {
let scan_p = smoothstep(0.55, 0.85, t); // scanline sweep
let frame = (t * 60.0) as u32;
// Build scaled mask + border map
// Don't reduce the area size - use full available space
let (scale, mask, w, h) = scaled_mask(
"CODE",
area.width,
area.height,
);
// Build scaled mask + border map using the actual render rect size
let (scale, mask, w, h) = scaled_mask("CODE", r.width, r.height);
let border = compute_border(&mask);
// Use full available width; align animation one column to the right
let mut r = area;
r.height = h.min(area.height as usize) as u16;
// Shift by one column to the right and shrink width accordingly
if r.width > 0 {
r.x = r.x.saturating_add(1);
r.width = r.width.saturating_sub(1);
}
// Restrict height to the scaled glyph height
r.height = h.min(r.height as usize) as u16;
// Ensure background matches theme for the animation area
let bg = crate::colors::background();
@@ -82,7 +77,13 @@ pub fn render_intro_outline_fill(area: Rect, buf: &mut Buffer, t: f32) {
// Outline fill animation with alpha blending - inline, no borders
pub fn render_intro_outline_fill_with_alpha(area: Rect, buf: &mut Buffer, t: f32, alpha: f32) {
if area.width < 40 || area.height < 10 {
// Compute the final render rect first (including our 1‑col right shift)
let mut r = area;
if r.width > 0 {
r.x = r.x.saturating_add(1);
r.width = r.width.saturating_sub(1);
}
if r.width < 40 || r.height < 10 {
return;
}
@@ -94,23 +95,12 @@ pub fn render_intro_outline_fill_with_alpha(area: Rect, buf: &mut Buffer, t: f32
let scan_p = smoothstep(0.55, 0.85, t); // scanline sweep
let frame = (t * 60.0) as u32;
// Build scaled mask + border map
// Don't reduce the area size - use full available space
let (scale, mask, w, h) = scaled_mask(
"CODE",
area.width,
area.height,
);
// Build scaled mask + border map using the actual render rect size
let (scale, mask, w, h) = scaled_mask("CODE", r.width, r.height);
let border = compute_border(&mask);
// Use full available width; align animation one column to the right
let mut r = area;
r.height = h.min(area.height as usize) as u16;
// Shift by one column to the right and shrink width accordingly
if r.width > 0 {
r.x = r.x.saturating_add(1);
r.width = r.width.saturating_sub(1);
}
// Restrict height to the scaled glyph height
r.height = h.min(r.height as usize) as u16;
// Ensure background matches theme for the animation area
let bg = crate::colors::background();