mirror of
https://git.meli.delivery/meli/meli
synced 2024-11-15 06:12:47 +00:00
ui: add hide menu shortcut
This commit is contained in:
parent
b741899fcf
commit
d50c201776
@ -151,11 +151,14 @@ pub trait Component: Display + Debug + Send {
|
|||||||
fn is_dirty(&self) -> bool {
|
fn is_dirty(&self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
fn is_visible(&self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
fn set_dirty(&mut self);
|
fn set_dirty(&mut self);
|
||||||
fn kill(&mut self, _id: EntityId) {}
|
fn kill(&mut self, _id: EntityId) {}
|
||||||
fn set_id(&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()
|
Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ struct AccountMenuEntry {
|
|||||||
pub struct AccountMenu {
|
pub struct AccountMenu {
|
||||||
accounts: Vec<AccountMenuEntry>,
|
accounts: Vec<AccountMenuEntry>,
|
||||||
dirty: bool,
|
dirty: bool,
|
||||||
|
visible: bool,
|
||||||
cursor: Option<(usize, usize)>,
|
cursor: Option<(usize, usize)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,6 +78,7 @@ impl AccountMenu {
|
|||||||
.collect();
|
.collect();
|
||||||
AccountMenu {
|
AccountMenu {
|
||||||
accounts,
|
accounts,
|
||||||
|
visible: true,
|
||||||
dirty: true,
|
dirty: true,
|
||||||
cursor: None,
|
cursor: None,
|
||||||
}
|
}
|
||||||
@ -270,6 +272,10 @@ impl Component for AccountMenu {
|
|||||||
UIEventType::Resize => {
|
UIEventType::Resize => {
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
}
|
}
|
||||||
|
UIEventType::Input(Key::Char('\t')) => {
|
||||||
|
self.visible = !self.visible;
|
||||||
|
self.dirty = true;
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
@ -277,7 +283,13 @@ impl Component for AccountMenu {
|
|||||||
fn is_dirty(&self) -> bool {
|
fn is_dirty(&self) -> bool {
|
||||||
self.dirty
|
self.dirty
|
||||||
}
|
}
|
||||||
|
fn is_visible(&self) -> bool {
|
||||||
|
self.visible
|
||||||
|
}
|
||||||
fn set_dirty(&mut self) {
|
fn set_dirty(&mut self) {
|
||||||
self.dirty = true;
|
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,
|
left: Entity,
|
||||||
right: Entity,
|
right: Entity,
|
||||||
show_divider: bool,
|
show_divider: bool,
|
||||||
|
prev_visibility: (bool, bool),
|
||||||
/// This is the width of the right container to the entire width.
|
/// This is the width of the right container to the entire width.
|
||||||
ratio: usize, // right/(container width) * 100
|
ratio: usize, // right/(container width) * 100
|
||||||
}
|
}
|
||||||
@ -131,6 +132,7 @@ impl VSplit {
|
|||||||
left,
|
left,
|
||||||
right,
|
right,
|
||||||
show_divider,
|
show_divider,
|
||||||
|
prev_visibility: (true, true),
|
||||||
ratio,
|
ratio,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -144,7 +146,21 @@ impl Component for VSplit {
|
|||||||
let upper_left = upper_left!(area);
|
let upper_left = upper_left!(area);
|
||||||
let bottom_right = bottom_right!(area);
|
let bottom_right = bottom_right!(area);
|
||||||
let total_cols = get_x(bottom_right) - get_x(upper_left);
|
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;
|
let mid = get_x(bottom_right) - right_entity_width;
|
||||||
|
|
||||||
if get_y(upper_left) > 1 {
|
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) {
|
for i in get_y(upper_left)..=get_y(bottom_right) {
|
||||||
grid[(mid, i)].set_ch(VERT_BOUNDARY);
|
grid[(mid, i)].set_ch(VERT_BOUNDARY);
|
||||||
grid[(mid, i)].set_fg(Color::Default);
|
grid[(mid, i)].set_fg(Color::Default);
|
||||||
@ -176,12 +192,23 @@ impl Component for VSplit {
|
|||||||
.dirty_areas
|
.dirty_areas
|
||||||
.push_back(((mid, get_y(upper_left)), (mid, get_y(bottom_right))));
|
.push_back(((mid, get_y(upper_left)), (mid, get_y(bottom_right))));
|
||||||
}
|
}
|
||||||
self.left
|
|
||||||
.component
|
if right_entity_width == total_cols {
|
||||||
.draw(grid, (upper_left, (mid - 1, get_y(bottom_right))), context);
|
self.right
|
||||||
self.right
|
.component
|
||||||
.component
|
.draw(grid, area, context);
|
||||||
.draw(grid, ((mid + 1, get_y(upper_left)), bottom_right), 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 {
|
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user