From 5a492599da88d3c46c436dbea7148a1994fdb2a1 Mon Sep 17 00:00:00 2001 From: June <61218022+itsjunetime@users.noreply.github.com> Date: Thu, 6 Nov 2025 20:02:31 -0600 Subject: [PATCH] Fix weird cropping when zooming out too much with kitty (#111) * Fix weird cropping when zooming out too much with kitty * Add changelog entry --- CHANGELOG.md | 1 + src/tui.rs | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89162bb..b340683 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Switched simd base64 crate for one that works on stable (from `vb64` to `base64_simd`) - Allow boolean arguments to function as flags, without a `true` or `false` argument following the flag itself +- Fix cropping issues when zooming out too much while using kitty protocol # v0.4.3 diff --git a/src/tui.rs b/src/tui.rs index e3ee62d..1b38bda 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -205,23 +205,28 @@ impl Tui { log::debug!("zoom is now {zoom:#?}"); log::debug!("img_area is {img_area:#?}"); + log::debug!("img dimensions are {cell_w}x{cell_h}"); - if zoom.level < 0 { - img_area = Rect { - width: img_area - .width - .saturating_sub((zoom.level * 2).unsigned_abs()) - .max(1), - x: img_area.x + (zoom.level.unsigned_abs().min(img_area.width / 2)), - ..img_area - } - } - - log::debug!("after adjustment, img_area is {img_area:#?}"); - - // Ugh I don't like this logic. I wish we could simplify it. let img_width = f32::from(cell_w); let img_height = f32::from(cell_h); + + let img_aspect_ratio = img_width / img_height; + + if zoom.level < 0 { + let old_width = img_area.width; + img_area.width = img_area + .width + .saturating_sub((zoom.level * 2).unsigned_abs()) + .max((f32::from(img_area.height) * img_aspect_ratio) as u16); + img_area.x += (old_width - img_area.width) / 2; + + log::debug!("after adjustment, img_area is {img_area:#?}"); + + // TODO: Find a way to detect when we've hit the maximum zoom-out and stop + // more zooming out + } + + // Ugh I don't like this logic. I wish we could simplify it. let img_area_width = f32::from(img_area.width); let img_area_height = f32::from(img_area.height); let available_to_real_width_ratio = img_area_width / img_width;