diff options
| author | lukeflo | 2024-11-16 18:32:55 +0100 |
|---|---|---|
| committer | lukeflo | 2024-11-16 18:32:55 +0100 |
| commit | 13bb655e3d63cf9e324ca055720d2fdb65e6b76e (patch) | |
| tree | 07b29fb168d4633e25acdf2d93935bd3765b8d96 /src/tui | |
| parent | 9c2fef5c1481d852b69ea342a38fec3eb6337524 (diff) | |
| download | bibiman-13bb655e3d63cf9e324ca055720d2fdb65e6b76e.tar.gz bibiman-13bb655e3d63cf9e324ca055720d2fdb65e6b76e.zip | |
selection popup fundament
Diffstat (limited to 'src/tui')
| -rw-r--r-- | src/tui/commands.rs | 21 | ||||
| -rw-r--r-- | src/tui/popup.rs | 10 | ||||
| -rw-r--r-- | src/tui/ui.rs | 37 |
3 files changed, 44 insertions, 24 deletions
diff --git a/src/tui/commands.rs b/src/tui/commands.rs index a9566d0..a3049ee 100644 --- a/src/tui/commands.rs +++ b/src/tui/commands.rs @@ -20,13 +20,13 @@ use ratatui::crossterm::event::{ }; use tui_input::Input; -// Possible ressources to open -#[derive(Debug, PartialEq, Eq)] -pub enum OpenRessource { - Pdf, - WebLink, - Note, -} +// // Possible ressources to open +// #[derive(Debug, PartialEq, Eq)] +// pub enum OpenRessource { +// Pdf, +// WebLink, +// Note, +// } /// Application command. #[derive(Debug, PartialEq, Eq)] @@ -62,7 +62,7 @@ pub enum CmdAction { // Edit file EditFile, // Open linked ressource - Open(OpenRessource), + Open, // Input command. Input(InputCmdAction), // Hexdump command. @@ -109,7 +109,8 @@ impl From<KeyEvent> for CmdAction { if key_event.modifiers == KeyModifiers::CONTROL { Self::SelectPrevRow(5) } else { - Self::Open(OpenRessource::WebLink) + Self::Nothing + // Self::Open(OpenRessource::WebLink) } } // Scroll info/preview area @@ -142,7 +143,7 @@ impl From<KeyEvent> for CmdAction { // Reset lists/tables KeyCode::Esc => Self::Reset, // Open linked ressource - KeyCode::Char('o') => Self::Open(OpenRessource::Pdf), + KeyCode::Char('o') => Self::Open, // KeyCode::Char('u') => Self::Open(OpenRessource::WebLink), // Edit currently selected entry KeyCode::Char('e') => Self::EditFile, diff --git a/src/tui/popup.rs b/src/tui/popup.rs index e15ed13..94df9b9 100644 --- a/src/tui/popup.rs +++ b/src/tui/popup.rs @@ -31,16 +31,16 @@ pub enum PopupKind { } #[derive(Debug, Default)] -pub struct PopupArea<'a> { +pub struct PopupArea { pub is_popup: bool, pub popup_kind: Option<PopupKind>, pub popup_message: String, pub popup_scroll_pos: u16, - pub popup_list: Vec<&'a str>, + pub popup_list: Vec<String>, pub popup_state: ListState, } -impl PopupArea<'_> { +impl PopupArea { pub fn popup_help<'a>() -> Text<'a> { let help = [ ("General", "first"), @@ -110,10 +110,10 @@ impl PopupArea<'_> { self.is_popup = true; } - pub fn popup_selection(&mut self, items: Vec<&'static str>) { + pub fn popup_selection(&mut self, items: Vec<String>) { self.popup_list = items; self.popup_kind = Some(PopupKind::Selection); - self.is_popup = true + self.is_popup = true; } pub fn popup_scroll_down(&mut self) { diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 6971fcb..daeba7f 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -163,7 +163,8 @@ pub fn render_popup(app: &mut App, frame: &mut Frame) { match app.bibiman.popup_area.popup_kind { Some(PopupKind::Help) => { let block = Block::bordered() - .title_top(" Keybindings (j,k|↓,↑)".bold()) + .title_top(" Keybindings ".bold()) + .title_bottom(" (j,k|↓,↑) ".bold()) .title_alignment(Alignment::Center) .style(POPUP_HELP_BOX) .border_set(symbols::border::THICK) @@ -218,16 +219,34 @@ pub fn render_popup(app: &mut App, frame: &mut Frame) { frame.render_widget(&content, popup_area) } Some(PopupKind::Selection) => { - // let list_items: Vec<ListItem> = app - // .bibiman - // .popup_area - // .popup_list - // .iter() - // .map(|item| ListItem::from(item.to_owned())) - // .collect(); + let list_items: Vec<ListItem> = app + .bibiman + .popup_area + .popup_list + .iter() + .map(|item| ListItem::from(item.to_owned())) + .collect(); + + let block = Block::bordered() + .title_top(" Open ".bold()) + .title_bottom(" (j,k|↓,↑) ".bold()) + .title_alignment(Alignment::Center) + .style(POPUP_HELP_BOX) + .border_set(symbols::border::THICK) + .border_style(Style::new().fg(MAIN_PURPLE)); + + let list = List::new(list_items) + .block(block) + .highlight_style(SELECTION_SELECTED_ROW_STYLE); - // let list = List::new(list_items).highlight_style(SELECTION_SELECTED_ROW_STYLE); + app.bibiman.popup_area.popup_state.select(Some(0)); + let popup_width = frame.area().width / 2; + let popup_heigth = list.len() + 2; + let popup_area = popup_area(frame.area(), popup_width, popup_heigth as u16); + + frame.render_widget(Clear, popup_area); + frame.render_stateful_widget(list, popup_area, &mut app.bibiman.popup_area.popup_state) // let sized_list = SizedWrapper { // inner: list.clone(), // width: (frame.area().width / 2) as usize, |
