diff --git a/src/interactive/app.rs b/src/interactive/app.rs index 4e9dc58e..321c795b 100644 --- a/src/interactive/app.rs +++ b/src/interactive/app.rs @@ -1,5 +1,5 @@ use crate::{ - interactive::widgets::{DrawState, MainWindow}, + interactive::widgets::{DrawState, HelpPaneState, MainWindow}, path_of, sorted_entries, traverse::{Traversal, TreeIndex}, ByteFormat, WalkOptions, WalkResult, @@ -56,9 +56,6 @@ impl Default for FocussedPane { } } -#[derive(Copy, Clone)] -pub struct HelpPaneState; - #[derive(Default)] pub struct AppState { pub root: TreeIndex, diff --git a/src/interactive/widgets/entries.rs b/src/interactive/widgets/entries.rs index b95edfc7..f37804ed 100644 --- a/src/interactive/widgets/entries.rs +++ b/src/interactive/widgets/entries.rs @@ -22,6 +22,7 @@ pub struct Entries<'a, 'b> { pub sorting: SortMode, pub selected: Option, pub list: &'b mut ListState, + pub borders: Borders, } impl<'a, 'b> Widget for Entries<'a, 'b> { @@ -32,6 +33,7 @@ impl<'a, 'b> Widget for Entries<'a, 'b> { display, sorting, selected, + borders, list, } = self; let is_top = |node_idx| { @@ -51,7 +53,7 @@ impl<'a, 'b> Widget for Entries<'a, 'b> { p => p, }; let title = format!(" {} ", title); - let block = Block::default().borders(Borders::ALL).title(&title); + let block = Block::default().borders(*borders).title(&title); let offset = list .update( selected.map(|selected| { diff --git a/src/interactive/widgets/help.rs b/src/interactive/widgets/help.rs new file mode 100644 index 00000000..d239499b --- /dev/null +++ b/src/interactive/widgets/help.rs @@ -0,0 +1,18 @@ +use tui::{buffer::Buffer, layout::Rect, widgets::Block, widgets::Borders, widgets::Widget}; + +#[derive(Copy, Clone)] +pub struct HelpPaneState; + +pub struct HelpPane { + pub state: HelpPaneState, + pub borders: Borders, +} + +impl Widget for HelpPane { + fn draw(&mut self, area: Rect, buf: &mut Buffer) { + Block::default() + .title("Help") + .borders(self.borders) + .draw(area, buf); + } +} diff --git a/src/interactive/widgets/main.rs b/src/interactive/widgets/main.rs index 203dad7a..a9b4f19a 100644 --- a/src/interactive/widgets/main.rs +++ b/src/interactive/widgets/main.rs @@ -1,15 +1,14 @@ use crate::{ interactive::{ - widgets::{Entries, Footer, ListState}, - AppState, DisplayOptions, + widgets::{Entries, Footer, HelpPane, ListState}, + AppState, DisplayOptions, FocussedPane, }, traverse::Traversal, }; -use tui::widgets::Block; use tui::{ buffer::Buffer, layout::{Constraint, Direction, Layout, Rect}, - widgets::Widget, + widgets::{Borders, Widget}, }; /// The state that can be mutated while drawing @@ -46,25 +45,36 @@ impl<'a, 'b, 'c> Widget for MainWindow<'a, 'b, 'c> { .split(area); let (entries_area, footer_area) = (regions[0], regions[1]); let (entries_area, help_area_state) = match state.help_pane { - Some(state) => (entries_area, Some((entries_area, state))), + Some(state) => { + let regions = Layout::default() + .direction(Direction::Horizontal) + .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) + .split(entries_area); + (regions[0], Some((regions[1], state))) + } None => (entries_area, None), }; + let (entries_borders, help_borders) = match state.focussed { + FocussedPane::Main => (Borders::ALL, Borders::NONE), + FocussedPane::Help => (Borders::NONE, Borders::ALL), + }; Entries { tree: &tree, root: state.root, display: *display, sorting: state.sorting, selected: state.selected, + borders: entries_borders, list: &mut draw_state.entries_list, } .draw(entries_area, buf); - if let Some((help_area, _)) = help_area_state { - use tui::widgets::Borders; - Block::default() - .title("Help") - .borders(Borders::ALL) - .draw(help_area, buf); + if let Some((help_area, state)) = help_area_state { + HelpPane { + state, + borders: help_borders, + } + .draw(help_area, buf); } Footer { diff --git a/src/interactive/widgets/mod.rs b/src/interactive/widgets/mod.rs index b5b3bc5b..c0b6d1cb 100644 --- a/src/interactive/widgets/mod.rs +++ b/src/interactive/widgets/mod.rs @@ -1,9 +1,11 @@ mod entries; mod footer; +mod help; mod list; mod main; pub use entries::*; pub use footer::*; +pub use help::*; pub use list::*; pub use main::*;