generated from GarandPLG/rust-flake-template
Refactor board cells to 2D vector and auto‑scroll
Store cells as a nested vector instead of a flat list, simplifying indexing and rendering. Add `is_focused_cell_visible` to detect when the focused cell is outside the viewport and adjust vertical/horizontal offsets accordingly in the skirmish keybindings. Update related methods and widget rendering to use the new 2‑D structure.
This commit is contained in:
1 parent
4917068fb1
commit
e4682f1c52
3 files changed
+45
-13
No files matched your search
@@ -34,16 +34,11 @@ impl Widget for BoardWidget<'_> {
|
||||
.split(*col_area);
|
||||
|
||||
for (row_idx, cell_area) in vertical.iter().enumerate() {
|
||||
let map_row: usize = row_idx + self.state.vertical_offset.get_value();
|
||||
let map_col: usize = col_idx + self.state.horizontal_offset.get_value();
|
||||
|
||||
if let Some(cell) = self
|
||||
.state
|
||||
self.state
|
||||
.cells
|
||||
.get(map_row * self.state.map_width + map_col)
|
||||
{
|
||||
cell.render(*cell_area, buf);
|
||||
}
|
||||
.get(row_idx + self.state.vertical_offset.get_value())
|
||||
.and_then(|rows| rows.get(col_idx + self.state.horizontal_offset.get_value()))
|
||||
.map(|cell| cell.render(*cell_area, buf));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user