Add bounded focus and padding to skirmish UI

- Initialize FocusedCell with map dimensions and start near the map
  centre.
- Store max rows/cols in FocusedCell and clamp moves to these bounds.
- Scroll actions now adjust the corresponding offset and also move the
  focused cell, keeping navigation consistent.
- Zoom actions modify the vertical offset to keep the view centered
  after
  changing zoom levels.
- Cell widget now uses a Padding widget with dynamic top padding based
  on
  the area height.
This commit is contained in:
2026-03-30 16:32:28 +02:00
parent 363baa1c1a
commit 07e941eba1
4 changed files with 50 additions and 20 deletions
+13 -6
View File
@@ -54,27 +54,34 @@ impl Offset {
pub struct FocusedCell {
pub row: usize,
pub col: usize,
pub max_row: usize,
pub max_col: usize,
}
impl FocusedCell {
pub fn new(row: usize, col: usize) -> Self {
Self { row, col }
pub fn new(row: usize, col: usize, max_row: usize, max_col: usize) -> Self {
Self {
row,
col,
max_row,
max_col,
}
}
pub fn move_up(&mut self) {
self.row = self.row.saturating_sub(1);
self.row = self.row.saturating_sub(1).max(0);
}
pub fn move_down(&mut self) {
self.row = self.row.saturating_add(1);
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);
self.col = self.col.saturating_sub(1).max(0);
}
pub fn move_right(&mut self) {
self.col = self.col.saturating_add(1);
self.col = self.col.saturating_add(1).min(self.max_col - 1);
}
}