feat: show the currently selected sheet in top of the table

This commit is contained in:
Jeremy Wall 2024-11-23 20:52:43 -05:00
parent a70a1451c1
commit ba504a88c7
2 changed files with 4 additions and 2 deletions

View File

@ -448,8 +448,9 @@ impl<'ws> Workspace<'ws> {
let mut rs: Vec<Box<dyn Fn(Rect, &mut Buffer, &mut Self)>> = 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

View File

@ -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<Row> = (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))