Radish alpha
r
rad:z39mP9rQAaGmERfUMPULfPUi473tY
Radicle terminal user interface
Radicle
Git
lib: Remove widget for table with header
Erik Kundt committed 4 months ago
commit a541323f1e49070efc44c83348f25a57e875734d
parent 1481d48
5 files changed +76 -124
modified bin/commands/inbox/list.rs
@@ -359,28 +359,36 @@ impl App {
            Column::new(Span::raw("Updated").bold(), Constraint::Length(16)),
        ];

-
        let table = ui.headered_table(
-
            frame,
-
            &mut selected,
-
            &notifs,
-
            header.clone(),
-
            header,
-
            Some("No notifications found".into()),
-
        );
-
        if table.changed {
-
            ui.send_message(Message::Changed(Change::Patches {
-
                state: TableState::new(selected),
-
            }));
-
        }
+
        ui.layout(
+
            Layout::vertical([Constraint::Length(3), Constraint::Min(1)]),
+
            Some(1),
+
            |ui| {
+
                ui.column_bar(frame, header.to_vec(), Some(Borders::Top));
+

+
                let table = ui.table(
+
                    frame,
+
                    &mut selected,
+
                    &notifs,
+
                    header.to_vec(),
+
                    Some("No notifications found".into()),
+
                    Some(Borders::BottomSides),
+
                );
+
                if table.changed {
+
                    ui.send_message(Message::Changed(Change::Patches {
+
                        state: TableState::new(selected),
+
                    }));
+
                }

-
        if self.state.loading {
-
            self.show_loading_popup(frame, ui);
-
        }
+
                if self.state.loading {
+
                    self.show_loading_popup(frame, ui);
+
                }

-
        // TODO(erikli): Should only work if table has focus
-
        if ui.input_global(|key| key == Key::Char('/')) {
-
            ui.send_message(Message::ShowSearch);
-
        }
+
                // TODO(erikli): Should only work if table has focus
+
                if ui.input_global(|key| key == Key::Char('/')) {
+
                    ui.send_message(Message::ShowSearch);
+
                }
+
            },
+
        );
    }

    fn show_browser_footer(&self, frame: &mut Frame, ui: &mut im::Ui<Message>) {
modified bin/commands/patch/list.rs
@@ -342,24 +342,32 @@ impl App {
            Column::new(Span::raw("Updated").bold(), Constraint::Length(16)).hide_small(),
        ];

-
        let table = ui.headered_table(
-
            frame,
-
            &mut selected,
-
            &patches,
-
            header.clone(),
-
            header,
-
            Some("No patches found".into()),
-
        );
-
        if table.changed {
-
            ui.send_message(Message::Changed(Change::Patches {
-
                state: TableState::new(selected),
-
            }));
-
        }
+
        ui.layout(
+
            Layout::vertical([Constraint::Length(3), Constraint::Min(1)]),
+
            Some(1),
+
            |ui| {
+
                ui.column_bar(frame, header.to_vec(), Some(Borders::Top));
+

+
                let table = ui.table(
+
                    frame,
+
                    &mut selected,
+
                    &patches,
+
                    header.to_vec(),
+
                    Some("No patches found".into()),
+
                    Some(Borders::BottomSides),
+
                );
+
                if table.changed {
+
                    ui.send_message(Message::Changed(Change::Patches {
+
                        state: TableState::new(selected),
+
                    }));
+
                }

-
        // TODO(erikli): Should only work if table has focus
-
        if ui.input_global(|key| key == Key::Char('/')) {
-
            ui.send_message(Message::ShowSearch);
-
        }
+
                // TODO(erikli): Should only work if table has focus
+
                if ui.input_global(|key| key == Key::Char('/')) {
+
                    ui.send_message(Message::ShowSearch);
+
                }
+
            },
+
        );
    }

    fn show_browser_footer(&self, frame: &mut Frame, ui: &mut im::Ui<Message>) {
modified bin/commands/patch/review.rs
@@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};

use termion::event::Key;

-
use ratatui::layout::{Constraint, Position};
+
use ratatui::layout::{Constraint, Layout, Position};
use ratatui::style::{Style, Stylize};
use ratatui::text::Text;
use ratatui::{Frame, Viewport};
@@ -338,12 +338,27 @@ impl App<'_> {

        let mut selected = state.selected_hunk();

-
        let table = ui.headered_table(frame, &mut selected, &hunks, header, columns, None);
-
        if table.changed {
-
            ui.send_message(Message::HunkChanged {
-
                state: TableState::new(selected),
-
            })
-
        }
+
        ui.layout(
+
            Layout::vertical([Constraint::Length(3), Constraint::Min(1)]),
+
            Some(1),
+
            |ui| {
+
                ui.column_bar(frame, header.to_vec(), Some(Borders::Top));
+

+
                let table = ui.table(
+
                    frame,
+
                    &mut selected,
+
                    &hunks,
+
                    columns,
+
                    None,
+
                    Some(Borders::BottomSides),
+
                );
+
                if table.changed {
+
                    ui.send_message(Message::HunkChanged {
+
                        state: TableState::new(selected),
+
                    })
+
                }
+
            },
+
        );
    }

    fn show_hunk(&self, ui: &mut Ui<Message>, frame: &mut Frame) {
modified src/ui/im.rs
@@ -24,7 +24,7 @@ use crate::ui::theme::Theme;
use crate::ui::{Column, ToRow};
use crate::Interrupted;

-
use crate::ui::im::widget::{HeaderedTable, Widget};
+
use crate::ui::im::widget::Widget;

use self::widget::AddContentFn;

@@ -561,21 +561,6 @@ where
        widget::Table::new(selected, items, columns, empty_message, borders).ui(self, frame)
    }

-
    pub fn headered_table<'a, R, const W: usize>(
-
        &mut self,
-
        frame: &mut Frame,
-
        selected: &'a mut Option<usize>,
-
        items: &'a Vec<R>,
-
        header: impl IntoIterator<Item = Column<'a>>,
-
        columns: impl IntoIterator<Item = Column<'a>>,
-
        empty_message: Option<String>,
-
    ) -> Response
-
    where
-
        R: ToRow<W> + Clone,
-
    {
-
        HeaderedTable::<R, W>::new(selected, items, header, columns, empty_message).ui(self, frame)
-
    }
-

    pub fn shortcuts(
        &mut self,
        frame: &mut Frame,
modified src/ui/im/widget.rs
@@ -531,70 +531,6 @@ where
    }
}

-
pub struct HeaderedTable<'a, R, const W: usize> {
-
    items: &'a Vec<R>,
-
    selected: &'a mut Option<usize>,
-
    header: Vec<Column<'a>>,
-
    columns: Vec<Column<'a>>,
-
    empty_message: Option<String>,
-
}
-

-
impl<'a, R, const W: usize> HeaderedTable<'a, R, W> {
-
    pub fn new(
-
        selected: &'a mut Option<usize>,
-
        items: &'a Vec<R>,
-
        header: impl IntoIterator<Item = Column<'a>>,
-
        columns: impl IntoIterator<Item = Column<'a>>,
-
        empty_message: Option<String>,
-
    ) -> Self {
-
        Self {
-
            items,
-
            selected,
-
            header: header.into_iter().collect(),
-
            columns: columns.into_iter().collect(),
-
            empty_message,
-
        }
-
    }
-

-
    pub fn items(&self) -> &Vec<R> {
-
        self.items
-
    }
-
}
-

-
/// TODO(erikli): Implement `show` that returns an `InnerResponse` such that it can
-
/// used like a group.
-
impl<R, const W: usize> Widget for HeaderedTable<'_, R, W>
-
where
-
    R: ToRow<W> + Clone,
-
{
-
    fn ui<M>(self, ui: &mut Ui<M>, frame: &mut Frame) -> Response
-
    where
-
        M: Clone,
-
    {
-
        let mut response = Response::default();
-

-
        ui.container(
-
            Layout::vertical([Constraint::Length(3), Constraint::Min(1)]),
-
            1,
-
            |ui| {
-
                ui.column_bar(frame, self.header.clone().to_vec(), Some(Borders::Top));
-

-
                let table = ui.table(
-
                    frame,
-
                    self.selected,
-
                    self.items,
-
                    self.columns.to_vec(),
-
                    self.empty_message,
-
                    Some(Borders::BottomSides),
-
                );
-
                response.changed |= table.changed;
-
            },
-
        );
-

-
        response
-
    }
-
}
-

pub struct ColumnBar<'a> {
    columns: Vec<Column<'a>>,
    borders: Option<Borders>,