index : nmrs-tui
A fast, Vim-friendly NetworkManager TUI built in Rust.
about summary refs log tree commit diff

Diffstat (limited to 'src/ui/table.rs')

-rw-r--r-- src/ui/table.rs 40
 1 file changed, 30 insertions(+), 10 deletions(-)

diff --git a/src/ui/table.rs b/src/ui/table.rs
index 731c786..562d7ad 100644
--- a/src/ui/table.rs
+++ b/src/ui/table.rs
@@ -1,13 +1,33 @@
use ratatui::{Frame, layout::{Constraint, Rect}, style::Style, widgets::{Block, Table, Row}};
use ratatui::{
    Frame, 
    layout::{Constraint, Rect}, 
    style::{Style, Stylize}, 
    widgets::{Block, Row, Table}
};
use crate::{ui::list::StatefulList};

use crate::app::App;
pub struct TableData<'a, T> {
    pub title: &'a str,
    pub header_cols: Vec<&'a str>,
    pub constraint: Vec<Constraint>,
    pub cells: Vec<Row<'a>>,
    pub list: &'a mut StatefulList<T>
}

pub fn draw(f: &mut Frame, area: Rect, app: &mut App) {
    let rows = vec![
        Row::new(vec!["Enter", "blabla"])
    ];
    let table = Table::new(rows, &[Constraint::Percentage(100)])
        .block(Block::bordered().title_top("Networks"))
        .row_highlight_style(Style::new().on_blue().black());
    f.render_widget(table, area);
pub fn draw<Any>(f: &mut Frame, area: Rect, table_data: &mut TableData<Any>, is_active: bool) {
    let border_style = if is_active { Style::new().bold().green() } else { Style::new() };
    let row_style = if is_active { Style::new().on_blue().black() } else { Style::new() };
    let table = Table::new(
        table_data.cells.clone(),
        table_data.constraint.clone(),
    )
    .header(Row::new(table_data.header_cols.clone()).bold())
    .block(
        Block::bordered()
        .title(table_data.title)
        .border_style(border_style)
        )
    .row_highlight_style(row_style);

    f.render_stateful_widget(table, area, &mut table_data.list.state);
}