From ba504a88c792b39ee57ba59a83094a4c98f1a151 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Sat, 23 Nov 2024 20:52:43 -0500 Subject: [PATCH] feat: show the currently selected sheet in top of the table --- src/ui/mod.rs | 3 ++- src/ui/render.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ui/mod.rs b/src/ui/mod.rs index d9982c1..0c0f6a4 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -448,8 +448,9 @@ impl<'ws> Workspace<'ws> { let mut rs: Vec> = vec![ Box::new(|rect: Rect, buf: &mut Buffer, ws: &mut Self| ws.text_area.render(rect, buf)), Box::new(move |rect: Rect, buf: &mut Buffer, ws: &mut Self| { + let sheet_name = ws.book.get_sheet_name().unwrap_or("Unknown"); // Table widget display - let table_block = Block::bordered(); + let table_block = Block::bordered().title_top(sheet_name); let table_inner: Table = TryFrom::try_from(&ws.book).expect(""); let table = table_inner.block(table_block); // https://docs.rs/ratatui/latest/ratatui/widgets/struct.TableState.html diff --git a/src/ui/render.rs b/src/ui/render.rs index 81039ba..9062f34 100644 --- a/src/ui/render.rs +++ b/src/ui/render.rs @@ -60,6 +60,7 @@ impl<'t, 'book: 't> TryFrom<&'book Book> for Table<'t> { // TODO(zaphar): This is apparently expensive. Maybe we can cache it somehow? // We should do the correct thing here if this fails let (row_count, col_count) = value.get_size()?; + let sheet_name = value.get_sheet_name()?; let rows: Vec = (1..=row_count) .into_iter() .map(|ri| { @@ -99,7 +100,7 @@ impl<'t, 'book: 't> TryFrom<&'book Book> for Table<'t> { Cell::new(COLNAMES[i % 26].repeat(count)) })); Ok(Table::new(rows, constraints) - .block(Block::bordered()) + .block(Block::bordered().title_top(sheet_name)) .header(Row::new(header).underlined()) .column_spacing(1) .flex(Flex::SpaceAround))