mirror of
https://github.com/itsjunetime/tdf.git
synced 2026-06-02 08:01:47 -04:00
mmmm maybe it's finally ready to merge...
This commit is contained in:
+47
-54
@@ -203,31 +203,35 @@ impl Tui {
|
|||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
log::debug!("zoom is now {zoom:#?}");
|
||||||
|
log::debug!("img_area is {img_area:#?}");
|
||||||
|
|
||||||
if zoom.level < 0 {
|
if zoom.level < 0 {
|
||||||
img_area = Rect {
|
img_area = Rect {
|
||||||
width: img_area.width.saturating_sub((zoom.level * 2).unsigned_abs()).max(1),
|
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)),
|
x: img_area.x + (zoom.level.unsigned_abs().min(img_area.width / 2)),
|
||||||
..img_area
|
..img_area
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ugh I don't like this logic. I wish we could simplify it.
|
log::debug!("after adjustment, img_area is {img_area:#?}");
|
||||||
let (new_cell_width, new_cell_height) =
|
|
||||||
if cell_w >= img_area.width && cell_h >= img_area.height {
|
|
||||||
(f32::from(img_area.width), f32::from(img_area.height))
|
|
||||||
} else {
|
|
||||||
let img_width = f32::from(cell_w);
|
|
||||||
let img_height = f32::from(cell_h);
|
|
||||||
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;
|
|
||||||
let available_to_real_height_ratio = img_area_height / img_height;
|
|
||||||
|
|
||||||
if available_to_real_width_ratio > available_to_real_height_ratio {
|
// Ugh I don't like this logic. I wish we could simplify it.
|
||||||
(img_width, img_area_height / available_to_real_width_ratio)
|
let img_width = f32::from(cell_w);
|
||||||
} else {
|
let img_height = f32::from(cell_h);
|
||||||
(img_area_width / available_to_real_height_ratio, img_height)
|
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;
|
||||||
|
let available_to_real_height_ratio = img_area_height / img_height;
|
||||||
|
|
||||||
|
let (new_cell_width, new_cell_height) =
|
||||||
|
if available_to_real_width_ratio > available_to_real_height_ratio {
|
||||||
|
(img_width, img_area_height / available_to_real_width_ratio)
|
||||||
|
} else {
|
||||||
|
(img_area_width / available_to_real_height_ratio, img_height)
|
||||||
};
|
};
|
||||||
|
|
||||||
log::debug!("new_cell stuff is {new_cell_width}x{new_cell_height}");
|
log::debug!("new_cell stuff is {new_cell_width}x{new_cell_height}");
|
||||||
@@ -649,48 +653,27 @@ impl Tui {
|
|||||||
self.last_render.rect = Rect::default();
|
self.last_render.rect = Rect::default();
|
||||||
Some(InputAction::SwitchRenderZoom(f_or_f))
|
Some(InputAction::SwitchRenderZoom(f_or_f))
|
||||||
}
|
}
|
||||||
'o' if self.is_kitty => {
|
/*'o' if self.is_kitty => {
|
||||||
if let Some(z) = &mut self.zoom {
|
if let Some(z) = &mut self.zoom {
|
||||||
z.level = z.level.saturating_add(1);
|
z.level = z.level.saturating_add(1);
|
||||||
}
|
}
|
||||||
self.last_render.rect = Rect::default();
|
self.last_render.rect = Rect::default();
|
||||||
Some(InputAction::Redraw)
|
Some(InputAction::Redraw)
|
||||||
}
|
}*/
|
||||||
'O' if self.is_kitty => {
|
'O' if self.is_kitty =>
|
||||||
if let Some(z) = &mut self.zoom {
|
self.update_zoom(|z| z.level = z.level.saturating_sub(1)),
|
||||||
z.level = z.level.saturating_sub(1);
|
'L' if self.is_kitty => self.update_zoom(|z| {
|
||||||
}
|
z.cell_pan_from_left = z.cell_pan_from_left.saturating_add(1)
|
||||||
self.last_render.rect = Rect::default();
|
}),
|
||||||
Some(InputAction::Redraw)
|
'H' if self.is_kitty => self.update_zoom(|z| {
|
||||||
}
|
z.cell_pan_from_left = z.cell_pan_from_left.saturating_sub(1)
|
||||||
'L' if self.is_kitty => {
|
}),
|
||||||
if let Some(z) = &mut self.zoom {
|
'J' if self.is_kitty => self.update_zoom(|z| {
|
||||||
z.cell_pan_from_left = z.cell_pan_from_left.saturating_add(1);
|
z.cell_pan_from_top = z.cell_pan_from_top.saturating_add(1)
|
||||||
}
|
}),
|
||||||
self.last_render.rect = Rect::default();
|
'K' if self.is_kitty => self.update_zoom(|z| {
|
||||||
Some(InputAction::Redraw)
|
z.cell_pan_from_top = z.cell_pan_from_top.saturating_sub(1)
|
||||||
}
|
}),
|
||||||
'H' if self.is_kitty => {
|
|
||||||
if let Some(z) = &mut self.zoom {
|
|
||||||
z.cell_pan_from_left = z.cell_pan_from_left.saturating_sub(1);
|
|
||||||
}
|
|
||||||
self.last_render.rect = Rect::default();
|
|
||||||
Some(InputAction::Redraw)
|
|
||||||
}
|
|
||||||
'J' if self.is_kitty => {
|
|
||||||
if let Some(z) = &mut self.zoom {
|
|
||||||
z.cell_pan_from_top = z.cell_pan_from_top.saturating_add(1);
|
|
||||||
}
|
|
||||||
self.last_render.rect = Rect::default();
|
|
||||||
Some(InputAction::Redraw)
|
|
||||||
}
|
|
||||||
'K' if self.is_kitty => {
|
|
||||||
if let Some(z) = &mut self.zoom {
|
|
||||||
z.cell_pan_from_top = z.cell_pan_from_top.saturating_sub(1);
|
|
||||||
}
|
|
||||||
self.last_render.rect = Rect::default();
|
|
||||||
Some(InputAction::Redraw)
|
|
||||||
}
|
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -790,6 +773,16 @@ impl Tui {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// I want this to always return 0 'cause I just use it to return from `Self::handle_event`]
|
||||||
|
#[expect(clippy::unnecessary_wraps)]
|
||||||
|
fn update_zoom(&mut self, f: impl FnOnce(&mut Zoom)) -> Option<InputAction> {
|
||||||
|
if let Some(z) = &mut self.zoom {
|
||||||
|
f(z)
|
||||||
|
}
|
||||||
|
self.last_render.rect = Rect::default();
|
||||||
|
Some(InputAction::Redraw)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn show_error(&mut self, err: RenderError) {
|
pub fn show_error(&mut self, err: RenderError) {
|
||||||
self.set_msg(MessageSetting::Some(BottomMessage::Error(match err {
|
self.set_msg(MessageSetting::Some(BottomMessage::Error(match err {
|
||||||
RenderError::Notify(e) => format!("Auto-reload failed: {e}"),
|
RenderError::Notify(e) => format!("Auto-reload failed: {e}"),
|
||||||
|
|||||||
Reference in New Issue
Block a user