Add zoom level helper and use it for cell sizing

Introduce a new `zoom_level` module containing the `CellSizes` enum and
`cell_size_helper` function to map `ZoomLevel` values to width and
height
dimensions. Export the helper from `mod.rs` and refactor `BoardWidget`
to
import and use `cell_size_helper`, eliminating duplicated match
statements.
This commit is contained in:
2026-04-01 19:57:44 +02:00
parent 07e941eba1
commit bf8883934d
3 changed files with 23 additions and 12 deletions
+4 -12
View File
@@ -1,6 +1,7 @@
use crate::app::{
App,
states::{FocusedCell, ZoomLevel},
helpers::{CellSizes, cell_size_helper},
states::FocusedCell,
widgets::CellWidget,
};
use ratatui::{
@@ -32,17 +33,8 @@ impl<'a> BoardWidget<'a> {
}
pub fn new(app: &'a mut App, area_width: u16, area_height: u16) -> Self {
let cell_height: u16 = match app.states.skirmish.zoom_level {
ZoomLevel::ZoomedIn => 7,
ZoomLevel::Default => 5,
ZoomLevel::ZoomedOut => 3,
};
let cell_width: u16 = match app.states.skirmish.zoom_level {
ZoomLevel::ZoomedIn => 13,
ZoomLevel::Default => 9,
ZoomLevel::ZoomedOut => 5,
};
let cell_height: u16 = cell_size_helper(CellSizes::Height, app.states.skirmish.zoom_level);
let cell_width: u16 = cell_size_helper(CellSizes::Width, app.states.skirmish.zoom_level);
let rows: u16 = area_height / cell_height;
let cols: u16 = area_width / cell_width;