From d35d803a78943d0a032e802f507eb54a6cf5e102 Mon Sep 17 00:00:00 2001 From: GarandPLG Date: Sun, 29 Mar 2026 21:07:05 +0200 Subject: [PATCH] Show cell coordinates with column letters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce `col_to_letters` to convert a zero‑based column index into Excel‑style letters. Add `display_coords` that returns the column letters followed by the row number. Update `render` to use this formatted coordinate as the block title instead of the previous row/col placeholder. --- src/app/widgets/cell.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/app/widgets/cell.rs b/src/app/widgets/cell.rs index c8ac0ad..b24a37f 100644 --- a/src/app/widgets/cell.rs +++ b/src/app/widgets/cell.rs @@ -24,13 +24,34 @@ impl CellWidget { pub fn new(row: usize, col: usize) -> Self { Self { row, col } } + + fn col_to_letters(&self) -> String { + let mut col: usize = self.col + 1; + let mut letters: Vec = Vec::new(); + + while col > 0 { + letters.push((b'A' + ((col - 1) % 26) as u8) as char); + col = (col - 1) / 26; + } + + letters.iter().rev().collect() + } + + pub fn display_coords(&self) -> String { + format!("{}{}", self.col_to_letters(), self.row) + } } impl Widget for CellWidget { fn render(self, area: Rect, buf: &mut Buffer) { - Paragraph::new(format!("{}/{}", self.row, self.col)) + Paragraph::new("") .alignment(Alignment::Center) - .block(Block::default().borders(Borders::ALL).white()) + .block( + Block::default() + .borders(Borders::ALL) + .white() + .title(self.display_coords().green()), + ) .render(area, buf); } }