Encapsulate cell selection and simplify board rendering

This commit is contained in:
2026-04-07 17:48:05 +02:00
parent 2b96ec129f
commit 3f646de3bb
3 changed files with 29 additions and 21 deletions
+13 -5
View File
@@ -17,13 +17,21 @@ use ratatui::{
pub struct CellWidget {
pub row: usize,
pub col: usize,
pub selected: bool,
selected: bool,
// pub tags: Vec<CellTags>,
}
impl CellWidget {
pub fn new(row: usize, col: usize, selected: bool) -> Self {
Self { row, col, selected }
pub fn new(row: usize, col: usize) -> Self {
Self {
row,
col,
selected: false,
}
}
pub fn set_selected(&mut self, selected: bool) {
self.selected = selected;
}
fn col_to_letters(&self) -> String {
@@ -42,7 +50,7 @@ impl CellWidget {
format!("{}{}", self.col_to_letters(), self.row)
}
fn is_selected(&self) -> Color {
fn fg_color(&self) -> Color {
if self.selected {
Color::Red
} else {
@@ -58,7 +66,7 @@ impl Widget for CellWidget {
.block(
Block::default()
.borders(Borders::ALL)
.style(Style::default().fg(self.is_selected()))
.style(Style::default().fg(self.fg_color()))
.title(self.display_coords().green())
.padding(Padding {
left: 0,