summaryrefslogtreecommitdiffstats
path: root/src/hbox.rs
diff options
context:
space:
mode:
authorrabite <rabite@posteo.de>2019-03-20 21:56:59 +0100
committerrabite <rabite@posteo.de>2019-03-20 21:56:59 +0100
commitfc2d6d268c6059981422bbe6879f887a5856a7e5 (patch)
tree92c5d518eea68fc1f0b35f61adbfcc12fe568ba6 /src/hbox.rs
parent04c40ec3ca728ecfc8e7998e66a468abfbfa22fc (diff)
hide left/right columns
Diffstat (limited to 'src/hbox.rs')
-rw-r--r--src/hbox.rs27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/hbox.rs b/src/hbox.rs
index a782911..15644f5 100644
--- a/src/hbox.rs
+++ b/src/hbox.rs
@@ -9,6 +9,7 @@ pub struct HBox<T: Widget> {
pub core: WidgetCore,
pub widgets: Vec<T>,
pub ratios: Option<Vec<usize>>,
+ pub zoom_active: bool,
pub active: Option<usize>,
}
@@ -18,6 +19,7 @@ impl<T> HBox<T> where T: Widget + PartialEq {
HBox { core: core.clone(),
widgets: vec![],
ratios: None,
+ zoom_active: false,
active: None
}
}
@@ -27,6 +29,12 @@ impl<T> HBox<T> where T: Widget + PartialEq {
let len = self.widgets.len();
if len == 0 { return Ok(()) }
+ if self.zoom_active {
+ let coords = self.core.coordinates.clone();
+ self.active_widget_mut()?.set_coordinates(&coords).log();
+ return Ok(());
+ }
+
let coords: Vec<Coordinates> = self.calculate_coordinates()?;
@@ -50,6 +58,12 @@ impl<T> HBox<T> where T: Widget + PartialEq {
self.widgets.insert(0, widget);
}
+ pub fn toggle_zoom(&mut self) -> HResult<()> {
+ self.clear().log();
+ self.zoom_active = !self.zoom_active;
+ self.resize_children()
+ }
+
pub fn set_ratios(&mut self, ratios: Vec<usize>) {
self.ratios = Some(ratios);
}
@@ -140,6 +154,11 @@ impl<T> Widget for HBox<T> where T: Widget + PartialEq {
}
fn refresh(&mut self) -> HResult<()> {
+ if self.zoom_active {
+ self.active_widget_mut()?.refresh().log();
+ return Ok(());
+ }
+
self.resize_children().log();
for child in &mut self.widgets {
child.refresh().log();
@@ -148,13 +167,17 @@ impl<T> Widget for HBox<T> where T: Widget + PartialEq {
}
fn get_drawlist(&self) -> HResult<String> {
+ if self.zoom_active {
+ return self.active_widget()?.get_drawlist();
+ }
+
Ok(self.widgets.iter().map(|child| {
- child.get_drawlist().unwrap()
+ child.get_drawlist().log_and().unwrap_or_else(|_| String::new())
}).collect())
}
fn on_event(&mut self, event: Event) -> HResult<()> {
- self.widgets.last_mut()?.on_event(event)?;
+ self.active_widget_mut()?.on_event(event)?;
Ok(())
}
}