diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2020-12-29 22:20:03 -0500 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2020-12-29 22:20:03 -0500 |
commit | 72f5e1eaf4c0fcbe39bd3f0d80cf9ab45d504057 (patch) | |
tree | c005e8edc21f1f09fe13ceabfda010d2036522fe /src | |
parent | 2b2672123d31bdcfd579916fa3fdc6cd961008a3 (diff) |
add back support for different sized columns
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/mod.rs | 14 | ||||
-rw-r--r-- | src/ui/views/tui_folder_view.rs | 32 |
2 files changed, 25 insertions, 21 deletions
diff --git a/src/ui/mod.rs b/src/ui/mod.rs index b5c98c8..16ebd19 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -1,19 +1,5 @@ -use tui::layout::Constraint; - mod tui_backend; pub mod views; pub mod widgets; pub use tui_backend::*; - -pub const DEFAULT_LAYOUT: [tui::layout::Constraint; 3] = [ - Constraint::Ratio(1, 8), - Constraint::Ratio(3, 8), - Constraint::Ratio(4, 8), -]; - -pub const NO_PREVIEW_LAYOUT: [tui::layout::Constraint; 3] = [ - Constraint::Ratio(1, 8), - Constraint::Ratio(7, 8), - Constraint::Ratio(0, 8), -]; diff --git a/src/ui/views/tui_folder_view.rs b/src/ui/views/tui_folder_view.rs index 55966ef..a9caaee 100644 --- a/src/ui/views/tui_folder_view.rs +++ b/src/ui/views/tui_folder_view.rs @@ -1,5 +1,5 @@ use tui::buffer::Buffer; -use tui::layout::{Direction, Layout, Rect}; +use tui::layout::{Constraint, Direction, Layout, Rect}; use tui::style::{Color, Style}; use tui::text::Span; use tui::widgets::{Paragraph, Widget, Wrap}; @@ -14,8 +14,6 @@ pub struct TuiFolderView<'a> { pub show_bottom_status: bool, } -use super::super::{DEFAULT_LAYOUT, NO_PREVIEW_LAYOUT}; - impl<'a> TuiFolderView<'a> { pub fn new(context: &'a JoshutoContext) -> Self { Self { @@ -35,12 +33,32 @@ impl<'a> Widget for TuiFolderView<'a> { let parent_list = curr_tab.parent_list_ref(); let child_list = curr_tab.child_list_ref(); - let constraints = if !self.context.config_ref().collapse_preview { - DEFAULT_LAYOUT + let column_ratio = self.context.config_ref().column_ratio; + let column_ratio = ( + column_ratio.0 as u32, + column_ratio.1 as u32, + column_ratio.2 as u32, + ); + let total = column_ratio.0 + column_ratio.1 + column_ratio.2; + + let default_layout = [ + Constraint::Ratio(column_ratio.0, total), + Constraint::Ratio(column_ratio.1, total), + Constraint::Ratio(column_ratio.2, total), + ]; + + let no_preview_layout = [ + Constraint::Ratio(column_ratio.0, total), + Constraint::Ratio(column_ratio.1 + column_ratio.2, total), + Constraint::Ratio(0, total), + ]; + + let constraints: [Constraint; 3] = if !self.context.config_ref().collapse_preview { + default_layout } else { match child_list { - Some(_) => DEFAULT_LAYOUT, - None => NO_PREVIEW_LAYOUT, + Some(_) => default_layout, + None => no_preview_layout, } }; |