//! //! Render a table with neither iter() nor data() being called. //! More a test than an actual example. //! use crate::mini_salsa::theme::THEME; use crate::mini_salsa::{run_ui, setup_logging, MiniSalsaState}; use rat_ftable::event::Outcome; use rat_ftable::selection::{noselection, NoSelection}; use rat_ftable::textdata::{Cell, Row}; use rat_ftable::{Table, TableState}; use rat_scrolled::Scroll; use ratatui::layout::{Constraint, Flex, Layout, Rect}; use ratatui::prelude::StatefulWidget; use ratatui::widgets::{block, Block}; use ratatui::Frame; mod mini_salsa; fn main() -> Result<(), anyhow::Error> { setup_logging()?; let mut data = Data {}; let mut state = State { table: Default::default(), }; run_ui("empty", handle_table, repaint_table, &mut data, &mut state) } struct Data {} struct State { pub(crate) table: TableState, } fn repaint_table( frame: &mut Frame<'_>, area: Rect, _data: &mut Data, _istate: &mut MiniSalsaState, state: &mut State, ) -> Result<(), anyhow::Error> { let l0 = Layout::horizontal([Constraint::Percentage(61)]) .flex(Flex::Center) .split(area); Table::default() .widths([ Constraint::Length(6), Constraint::Length(20), Constraint::Length(15), Constraint::Length(15), Constraint::Length(3), ]) .column_spacing(1) .header( Row::new([ Cell::from("Nr"), Cell::from("Text"), Cell::from("Val1"), Cell::from("Val2"), Cell::from("State"), ]) .style(Some(THEME.table_header())), ) .footer(Row::new(["a", "b", "c", "d", "e"]).style(Some(THEME.table_footer()))) .block( Block::bordered() .border_type(block::BorderType::Rounded) .border_style(THEME.block()) .title("empty"), ) .vscroll(Scroll::new().style(THEME.block())) .flex(Flex::End) .style(THEME.table()) .select_row_style(Some(THEME.gray(3))) .render(l0[0], frame.buffer_mut(), &mut state.table); Ok(()) } fn handle_table( event: &crossterm::event::Event, _data: &mut Data, _istate: &mut MiniSalsaState, state: &mut State, ) -> Result { let r = noselection::handle_events(&mut state.table, true, event); Ok(r) }