summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-03-26 16:59:35 +0200
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-06-10 19:40:40 +0300
commitd50c2017762a48b3c461324ce1a3f6f7a5770b7c (patch)
tree3db2dd3474cc04e285909c084757ee2c53e1b36a
parentb741899fcfeb2082dc4450bb1a39cc442485a61c (diff)
ui: add hide menu shortcut
-rw-r--r--ui/src/components.rs5
-rw-r--r--ui/src/components/mail.rs12
-rw-r--r--ui/src/components/utilities.rs43
3 files changed, 51 insertions, 9 deletions
diff --git a/ui/src/components.rs b/ui/src/components.rs
index 1ded7791..08b57fca 100644
--- a/ui/src/components.rs
+++ b/ui/src/components.rs
@@ -151,11 +151,14 @@ pub trait Component: Display + Debug + Send {
fn is_dirty(&self) -> bool {
true
}
+ fn is_visible(&self) -> bool {
+ true
+ }
fn set_dirty(&mut self);
fn kill(&mut self, _id: EntityId) {}
fn set_id(&mut self, _id: EntityId) {}
- fn get_shortcuts(&self, context: &Context) -> ShortcutMap {
+ fn get_shortcuts(&self, _context: &Context) -> ShortcutMap {
Default::default()
}
}
diff --git a/ui/src/components/mail.rs b/ui/src/components/mail.rs
index f4d4322f..0fb9cd15 100644
--- a/ui/src/components/mail.rs
+++ b/ui/src/components/mail.rs
@@ -48,6 +48,7 @@ struct AccountMenuEntry {
pub struct AccountMenu {
accounts: Vec<AccountMenuEntry>,
dirty: bool,
+ visible: bool,
cursor: Option<(usize, usize)>,
}
@@ -77,6 +78,7 @@ impl AccountMenu {
.collect();
AccountMenu {
accounts,
+ visible: true,
dirty: true,
cursor: None,
}
@@ -270,6 +272,10 @@ impl Component for AccountMenu {
UIEventType::Resize => {
self.dirty = true;
}
+ UIEventType::Input(Key::Char('\t')) => {
+ self.visible = !self.visible;
+ self.dirty = true;
+ }
_ => {}
}
false
@@ -277,7 +283,13 @@ impl Component for AccountMenu {
fn is_dirty(&self) -> bool {
self.dirty
}
+ fn is_visible(&self) -> bool {
+ self.visible
+ }
fn set_dirty(&mut self) {
self.dirty = true;
}
+ fn get_shortcuts(&self, _context: &Context) -> ShortcutMap {
+ [("Toggle account menu visibility", Key::Char('\t'))].iter().cloned().collect()
+ }
}
diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs
index aaa06ced..eb40528e 100644
--- a/ui/src/components/utilities.rs
+++ b/ui/src/components/utilities.rs
@@ -114,6 +114,7 @@ pub struct VSplit {
left: Entity,
right: Entity,
show_divider: bool,
+ prev_visibility: (bool, bool),
/// This is the width of the right container to the entire width.
ratio: usize, // right/(container width) * 100
}
@@ -131,6 +132,7 @@ impl VSplit {
left,
right,
show_divider,
+ prev_visibility: (true, true),
ratio,
}
}
@@ -144,7 +146,21 @@ impl Component for VSplit {
let upper_left = upper_left!(area);
let bottom_right = bottom_right!(area);
let total_cols = get_x(bottom_right) - get_x(upper_left);
- let right_entity_width = (self.ratio * total_cols) / 100;
+ let visibility = (self.left.is_visible(), self.right.is_visible());
+ if visibility != self.prev_visibility {
+ self.set_dirty();
+ self.prev_visibility = visibility;
+ }
+ let right_entity_width = match visibility {
+ (true, true) => (self.ratio * total_cols) / 100,
+ (false, true) => total_cols,
+ (true, false) => 0,
+ (false, false) => {
+ clear_area(grid, area);
+ return;
+ }
+ };
+
let mid = get_x(bottom_right) - right_entity_width;
if get_y(upper_left) > 1 {
@@ -157,7 +173,7 @@ impl Component for VSplit {
}
}
- if self.show_divider {
+ if self.show_divider && mid != get_x(upper_left) {
for i in get_y(upper_left)..=get_y(bottom_right) {
grid[(mid, i)].set_ch(VERT_BOUNDARY);
grid[(mid, i)].set_fg(Color::Default);
@@ -176,12 +192,23 @@ impl Component for VSplit {
.dirty_areas
.push_back(((mid, get_y(upper_left)), (mid, get_y(bottom_right))));
}
- self.left
- .component
- .draw(grid, (upper_left, (mid - 1, get_y(bottom_right))), context);
- self.right
- .component
- .draw(grid, ((mid + 1, get_y(upper_left)), bottom_right), context);
+
+ if right_entity_width == total_cols {
+ self.right
+ .component
+ .draw(grid, area, context);
+ } else if right_entity_width == 0 {
+ self.left
+ .component
+ .draw(grid, area, context);
+ } else {
+ self.left
+ .component
+ .draw(grid, (upper_left, ((mid - 1), get_y(bottom_right))), context);
+ self.right
+ .component
+ .draw(grid, (set_x(upper_left, mid + 1), bottom_right), context);
+ }
}
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {