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
+2
View File
@@ -1,3 +1,5 @@
pub mod block_title;
pub mod zoom_level;
pub use block_title::{block_single_title_helper, block_title_helper};
pub use zoom_level::{CellSizes, cell_size_helper};
+17
View File
@@ -0,0 +1,17 @@
use crate::app::states::ZoomLevel;
pub enum CellSizes {
Width,
Height,
}
pub fn cell_size_helper(cell_size: CellSizes, zoom_level: ZoomLevel) -> u16 {
match (cell_size, zoom_level) {
(CellSizes::Width, ZoomLevel::ZoomedIn) => 13,
(CellSizes::Width, ZoomLevel::Default) => 9,
(CellSizes::Width, ZoomLevel::ZoomedOut) => 5,
(CellSizes::Height, ZoomLevel::ZoomedIn) => 7,
(CellSizes::Height, ZoomLevel::Default) => 5,
(CellSizes::Height, ZoomLevel::ZoomedOut) => 3,
}
}
+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;