Encapsulate FocusedCell fields and add getters

This commit is contained in:
2026-04-07 01:14:36 +02:00
parent 8e01c8c33a
commit 2b96ec129f
2 changed files with 14 additions and 6 deletions
+2 -2
View File
@@ -83,8 +83,8 @@ impl BoardState {
Offset::new(Some(self.horizontal_offset.get_value()), Some(h_max_offset)); Offset::new(Some(self.horizontal_offset.get_value()), Some(h_max_offset));
self.focused_cell = FocusedCell::new( self.focused_cell = FocusedCell::new(
self.focused_cell.row, self.focused_cell.get_row(),
self.focused_cell.col, self.focused_cell.get_col(),
self.map_height, self.map_height,
self.map_width, self.map_width,
); );
+12 -4
View File
@@ -1,9 +1,9 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct FocusedCell { pub struct FocusedCell {
pub row: usize, row: usize,
pub col: usize, col: usize,
pub max_row: usize, max_row: usize,
pub max_col: usize, max_col: usize,
} }
impl FocusedCell { impl FocusedCell {
@@ -16,6 +16,14 @@ impl FocusedCell {
} }
} }
pub fn get_row(&self) -> usize {
self.row
}
pub fn get_col(&self) -> usize {
self.col
}
pub fn move_up(&mut self) { pub fn move_up(&mut self) {
self.row = self.row.saturating_sub(1).max(0); self.row = self.row.saturating_sub(1).max(0);
} }