-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtoolbar.rs
More file actions
44 lines (40 loc) · 1.33 KB
/
toolbar.rs
File metadata and controls
44 lines (40 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use tui_realm_stdlib::Label;
use tuirealm::{AttrValue, Attribute, Component, Event, MockComponent};
use crate::{
app::{
messages::{Msg, View},
user_events::UserEvent,
},
trace_dbg,
};
const WORKLOAD_TOOLTIP: &str = "q: quit, Esc: close/back, l: logs, f: File view, x: menu, tab: switch view, ?: help";
const FILETREE_TOOLTIP: &str = "q: quit, ↑↓: navigate,←→: collapse/expand, x: menu, ?: help";
#[derive(MockComponent)]
pub struct Toolbar {
component: Label,
current_view: View,
}
impl Toolbar {
pub fn new() -> Self {
Self {
component: Label::default().text(WORKLOAD_TOOLTIP),
current_view: View::default(),
}
}
}
impl Component<Msg, UserEvent> for Toolbar {
fn on(&mut self, ev: tuirealm::Event<UserEvent>) -> Option<Msg> {
match ev {
Event::User(UserEvent::SwitchedToView(view)) => {
let view = trace_dbg!(view);
self.current_view = view;
match self.current_view {
View::Workloads => self.attr(Attribute::Text, AttrValue::String(WORKLOAD_TOOLTIP.to_owned())),
View::Files => self.attr(Attribute::Text, AttrValue::String(FILETREE_TOOLTIP.to_owned())),
}
None
}
_ => None,
}
}
}