Files
war-in-tunnels/src/app/states/skirmish_states/focused_cell.rs
T
GarandPLG 48483da1a4 Refactor skirmish focus handling and CellWidget API
Introduce a MoveFocusedCell enum and a BoardState.change_focused_cell
method to
centralize focus movement logic. Update skirmish keybindings to use this
new
method and simplify board rendering by directly using stored CellWidget
state.
Make CellWidget setters chainable and expose the new enum in the module
re‑exports. Remove duplicated max_offset logic and old move_* methods.
2026-04-07 23:20:11 +02:00

53 lines
1.2 KiB
Rust

pub enum MoveFocusedCell {
Up,
Down,
Left,
Right,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct FocusedCell {
row: usize,
col: usize,
max_row: usize,
max_col: usize,
}
impl FocusedCell {
pub fn new(row: usize, col: usize, max_row: usize, max_col: usize) -> Self {
Self {
row,
col,
max_row,
max_col,
}
}
pub fn get_row(&self) -> usize {
self.row
}
pub fn get_col(&self) -> usize {
self.col
}
pub fn move_focused_cell(&mut self, direction: MoveFocusedCell) -> (usize, usize) {
match direction {
MoveFocusedCell::Up => {
self.row = self.row.saturating_sub(1).max(0);
}
MoveFocusedCell::Down => {
self.row = self.row.saturating_add(1).min(self.max_row - 1);
}
MoveFocusedCell::Left => {
self.col = self.col.saturating_sub(1).max(0);
}
MoveFocusedCell::Right => {
self.col = self.col.saturating_add(1).min(self.max_col - 1);
}
}
(self.row, self.col)
}
}