Refactor CellWidget constructor to accept selected

Update `CellWidget::new` to take a `selected` flag and remove the
chaining return values from `set_selected` and `set_zoom_level`. The
board code now passes the selection state directly during construction.
This commit is contained in:
2026-04-08 23:43:16 +02:00
parent 247f5c143b
commit 56bef7c98e
2 changed files with 9 additions and 12 deletions
+5 -6
View File
@@ -48,12 +48,11 @@ impl BoardState {
let mut rows: Vec<CellWidget> = Vec::new(); let mut rows: Vec<CellWidget> = Vec::new();
for col in 0..map_width { for col in 0..map_width {
rows.push(*CellWidget::new(row, col, zoom_level).set_selected( rows.push(CellWidget::new(
if row == focused_cell.get_row() && col == focused_cell.get_col() { row,
true col,
} else { row == focused_cell.get_row() && col == focused_cell.get_col(),
false zoom_level,
},
)); ));
} }
+4 -6
View File
@@ -25,23 +25,21 @@ pub struct CellWidget {
} }
impl CellWidget { impl CellWidget {
pub fn new(row: usize, col: usize, zoom_level: ZoomLevel) -> Self { pub fn new(row: usize, col: usize, selected: bool, zoom_level: ZoomLevel) -> Self {
Self { Self {
row, row,
col, col,
selected: false, selected,
zoom_level, zoom_level,
} }
} }
pub fn set_selected(&mut self, selected: bool) -> &mut Self { pub fn set_selected(&mut self, selected: bool) {
self.selected = selected; self.selected = selected;
self
} }
pub fn set_zoom_level(&mut self, zoom_level: ZoomLevel) -> &mut Self { pub fn set_zoom_level(&mut self, zoom_level: ZoomLevel) {
self.zoom_level = zoom_level; self.zoom_level = zoom_level;
self
} }
fn col_to_letters(&self) -> String { fn col_to_letters(&self) -> String {