diff options
Diffstat (limited to 'src/ui/widgets/tui_view.rs')
-rw-r--r-- | src/ui/widgets/tui_view.rs | 74 |
1 files changed, 46 insertions, 28 deletions
diff --git a/src/ui/widgets/tui_view.rs b/src/ui/widgets/tui_view.rs index 9ab7e2c..7cfe223 100644 --- a/src/ui/widgets/tui_view.rs +++ b/src/ui/widgets/tui_view.rs @@ -2,11 +2,12 @@ use tui::buffer::Buffer; use tui::layout::{Direction, Layout, Rect}; use tui::style::{Color, Modifier, Style}; use tui::widgets::{Paragraph, Text, Widget}; -use unicode_width::UnicodeWidthStr; -use super::{TuiDirList, TuiDirListDetailed, TuiFooter, TuiTopBar}; +use super::{TuiDirList, TuiDirListDetailed, TuiFooter, TuiTabBar, TuiTopBar}; use crate::context::JoshutoContext; +const TAB_VIEW_WIDTH: u16 = 15; + pub struct TuiView<'a> { pub context: &'a JoshutoContext, pub show_bottom_status: bool, @@ -43,32 +44,49 @@ impl<'a> Widget for TuiView<'a> { .constraints(constraints.as_ref()) .split(f_size); - if self.context.tabs.len() > 1 { - let rect = Rect { - x: f_size.width - 5, - y: 0, - width: 5, - height: 1, - }; - - let rect = Rect { - x: 0, - y: 0, - width: f_size.width - 5, - height: 1, - }; - - TuiTopBar::new(curr_tab.curr_path.as_path()).draw(rect, buf); - } else { - let rect = Rect { - x: 0, - y: 0, - width: f_size.width, - height: 1, - }; - - TuiTopBar::new(curr_tab.curr_path.as_path()).draw(rect, buf); - } + { + let curr_path = curr_tab.curr_path.as_path(); + + if self.context.tabs.len() > 1 { + let topbar_width = if f_size.width > TAB_VIEW_WIDTH { + f_size.width - TAB_VIEW_WIDTH + } else { + 0 + }; + + let rect = Rect { + x: 0, + y: 0, + width: topbar_width, + height: 1, + }; + TuiTopBar::new(curr_path).draw(rect, buf); + + let rect = Rect { + x: topbar_width, + y: 0, + width: TAB_VIEW_WIDTH, + height: 1, + }; + let name = if let Some(ostr) = curr_path.file_name() { + ostr.to_str().unwrap_or("") + } else { + "" + }; + TuiTabBar::new(name, self.context.curr_tab_index, self.context.tabs.len()) + .draw(rect, buf); + } else { + let topbar_width = f_size.width; + + let rect = Rect { + x: 0, + y: 0, + width: topbar_width, + height: 1, + }; + TuiTopBar::new(curr_path).draw(rect, buf); + } + } if let Some(curr_list) = parent_list.as_ref() { TuiDirList::new(&curr_list).draw(layout_rect[0], buf); |