generated from GarandPLG/rust-flake-template
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:
@@ -1,3 +1,5 @@
|
|||||||
pub mod block_title;
|
pub mod block_title;
|
||||||
|
pub mod zoom_level;
|
||||||
|
|
||||||
pub use block_title::{block_single_title_helper, block_title_helper};
|
pub use block_title::{block_single_title_helper, block_title_helper};
|
||||||
|
pub use zoom_level::{CellSizes, cell_size_helper};
|
||||||
|
|||||||
@@ -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,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
use crate::app::{
|
use crate::app::{
|
||||||
App,
|
App,
|
||||||
states::{FocusedCell, ZoomLevel},
|
helpers::{CellSizes, cell_size_helper},
|
||||||
|
states::FocusedCell,
|
||||||
widgets::CellWidget,
|
widgets::CellWidget,
|
||||||
};
|
};
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
@@ -32,17 +33,8 @@ impl<'a> BoardWidget<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(app: &'a mut App, area_width: u16, area_height: u16) -> Self {
|
pub fn new(app: &'a mut App, area_width: u16, area_height: u16) -> Self {
|
||||||
let cell_height: u16 = match app.states.skirmish.zoom_level {
|
let cell_height: u16 = cell_size_helper(CellSizes::Height, app.states.skirmish.zoom_level);
|
||||||
ZoomLevel::ZoomedIn => 7,
|
let cell_width: u16 = cell_size_helper(CellSizes::Width, app.states.skirmish.zoom_level);
|
||||||
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 rows: u16 = area_height / cell_height;
|
let rows: u16 = area_height / cell_height;
|
||||||
let cols: u16 = area_width / cell_width;
|
let cols: u16 = area_width / cell_width;
|
||||||
|
|||||||
Reference in New Issue
Block a user