generated from GarandPLG/rust-flake-template
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:
@@ -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,
|
||||||
},
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user