ui: add hide menu shortcut
parent
b741899fcf
commit
d50c201776
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue