diff options
Diffstat (limited to 'src/miller_columns.rs')
-rw-r--r-- | src/miller_columns.rs | 86 |
1 files changed, 24 insertions, 62 deletions
diff --git a/src/miller_columns.rs b/src/miller_columns.rs index 3a240cb..ca621e4 100644 --- a/src/miller_columns.rs +++ b/src/miller_columns.rs @@ -1,8 +1,7 @@ use termion::event::Key; use failure::Backtrace; -use crate::coordinates::{Coordinates, Position, Size}; -use crate::preview::Previewer; +use crate::coordinates::{Coordinates}; use crate::widget::{Widget, WidgetCore}; use crate::hbox::HBox; use crate::fail::{HError, HResult, ErrorLog}; @@ -11,11 +10,6 @@ use crate::fail::{HError, HResult, ErrorLog}; pub struct MillerColumns<T> where T: Widget { pub widgets: HBox<T>, pub core: WidgetCore, - // pub left: Option<T>, - // pub main: Option<T>, - //pub preview: AsyncPreviewer, - pub preview: Previewer, - pub ratio: (u16, u16, u16), } impl<T> MillerColumns<T> @@ -26,8 +20,6 @@ where MillerColumns { widgets: HBox::new(core), core: core.clone(), - ratio: (20, 30, 50), - preview: Previewer::new(core) } } @@ -46,64 +38,45 @@ where self.widgets.prepend_widget(widget); } - pub fn calculate_coordinates(&self) -> (Coordinates, Coordinates, Coordinates) { - let coordinates = self.get_coordinates().unwrap(); - let xsize = coordinates.xsize(); - let ysize = coordinates.ysize(); - let top = coordinates.top().y(); - let ratio = self.ratio; - - let left_xsize = xsize * ratio.0 / 100; - let left_size = Size((left_xsize, ysize)); - let left_pos = coordinates.top(); - - let main_xsize = xsize * ratio.1 / 100; - let main_size = Size((main_xsize, ysize)); - let main_pos = Position((left_xsize + 2, top)); - - let preview_xsize = xsize * ratio.2 / 100; - let preview_size = Size((preview_xsize - 1, ysize)); - let preview_pos = Position((left_xsize + main_xsize + 3, top)); - - let left_coords = Coordinates { - size: left_size, - position: left_pos, - }; - - let main_coords = Coordinates { - size: main_size, - position: main_pos, - }; - - let preview_coords = Coordinates { - size: preview_size, - position: preview_pos, - }; + pub fn set_ratios(&mut self, ratios: Vec<usize>) { + self.widgets.set_ratios(ratios); + } - (left_coords, main_coords, preview_coords) + pub fn calculate_coordinates(&self) -> HResult<Vec<Coordinates>> { + self.widgets.calculate_coordinates() } pub fn get_left_widget(&self) -> HResult<&T> { let len = self.widgets.widgets.len(); - if len < 2 { + if len < 3 { return Err(HError::NoWidgetError(Backtrace::new())); } - let widget = self.widgets.widgets.get(len - 2)?; + let widget = self.widgets.widgets.get(len - 3)?; Ok(widget) } pub fn get_left_widget_mut(&mut self) -> HResult<&mut T> { let len = self.widgets.widgets.len(); - if len < 2 { + if len < 3 { return Err(HError::NoWidgetError(Backtrace::new())); } - let widget = self.widgets.widgets.get_mut(len - 2)?; + let widget = self.widgets.widgets.get_mut(len - 3)?; Ok(widget) } pub fn get_main_widget(&self) -> HResult<&T> { - let widget = self.widgets.widgets.last()?; + let len = self.widgets.widgets.len(); + let widget = self.widgets.widgets.get(len-2)?; Ok(widget) } pub fn get_main_widget_mut(&mut self) -> HResult<&mut T> { + let len = self.widgets.widgets.len(); + let widget = self.widgets.widgets.get_mut(len-2)?; + Ok(widget) + } + pub fn get_right_widget(&self) -> HResult<&T> { + let widget = self.widgets.widgets.last()?; + Ok(widget) + } + pub fn get_right_widget_mut(&mut self) -> HResult<&mut T> { let widget = self.widgets.widgets.last_mut()?; Ok(widget) } @@ -121,29 +94,18 @@ where Ok(&mut self.core) } fn refresh(&mut self) -> HResult<()> { - let (left_coords, main_coords, preview_coords) = self.calculate_coordinates(); - - if let Ok(left_widget) = self.get_left_widget_mut() { - left_widget.set_coordinates(&left_coords).log(); - } - - if let Ok(main_widget) = self.get_main_widget_mut() { - main_widget.set_coordinates(&main_coords).log(); - } - - let preview_widget = &mut self.preview; - preview_widget.set_coordinates(&preview_coords)?; + self.widgets.refresh().log(); Ok(()) } fn get_drawlist(&self) -> HResult<String> { let left_widget = self.get_left_widget()?; let main_widget = self.get_main_widget()?; - let preview = self.preview.get_drawlist()?; + let right_widget = self.get_right_widget()?; Ok(format!("{}{}{}", main_widget.get_drawlist()?, left_widget.get_drawlist()?, - preview)) + right_widget.get_drawlist()?)) } fn on_key(&mut self, key: Key) -> HResult<()> { |