generated from GarandPLG/rust-flake-template
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.
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
pub enum MoveFocusedCell {
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct FocusedCell {
|
||||
row: usize,
|
||||
@@ -24,19 +31,22 @@ impl FocusedCell {
|
||||
self.col
|
||||
}
|
||||
|
||||
pub fn move_up(&mut self) {
|
||||
self.row = self.row.saturating_sub(1).max(0);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn move_down(&mut self) {
|
||||
self.row = self.row.saturating_add(1).min(self.max_row - 1);
|
||||
}
|
||||
|
||||
pub fn move_left(&mut self) {
|
||||
self.col = self.col.saturating_sub(1).max(0);
|
||||
}
|
||||
|
||||
pub fn move_right(&mut self) {
|
||||
self.col = self.col.saturating_add(1).min(self.max_col - 1);
|
||||
(self.row, self.col)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user