Skip to content

Commit

Permalink
Makes rendering of footer legend more dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
robgonnella committed Sep 24, 2024
1 parent f89f99f commit edce626
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
3 changes: 3 additions & 0 deletions r-lanui/src/ui/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ pub trait CustomStatefulWidgetRef {

pub trait View: EventHandler + WidgetRef {
fn id(&self) -> ViewID;
fn legend(&self) -> &str {
""
}
}
3 changes: 3 additions & 0 deletions r-lanui/src/ui/views/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ impl View for DeviceView {
fn id(&self) -> ViewID {
ViewID::Device
}
fn legend(&self) -> &str {
"(c) configure | (t) trace | (s) SSH"
}
}

impl WidgetRef for DeviceView {
Expand Down
23 changes: 19 additions & 4 deletions r-lanui/src/ui/views/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use super::{
config::ConfigView, device::DeviceView, devices::DevicesView, CustomWidget, EventHandler, View,
};

const INFO_TEXT: &str = "(Esc) quit | (c) configure | (t) trace | (s) SSH";
const DEFAULT_PADDING: Padding = Padding::horizontal(2);

pub struct MainView {
Expand Down Expand Up @@ -173,8 +172,20 @@ impl MainView {
config_view.render_ref(inner_area, buf);
}

fn render_footer(&self, area: Rect, buf: &mut ratatui::prelude::Buffer, state: &State) {
let footer = InfoFooter::new(String::from(INFO_TEXT));
fn render_footer(
&self,
legend: &str,
area: Rect,
buf: &mut ratatui::prelude::Buffer,
state: &State,
) {
let mut info = String::from("(Esc) quit");

if legend.len() > 0 {
info = format!("{info} | {legend}");
}

let footer = InfoFooter::new(info);
footer.render(area, buf, state);
}
}
Expand Down Expand Up @@ -217,14 +228,18 @@ impl WidgetRef for MainView {

self.dispatcher.dispatch(Action::UpdateLayout(Some(layout)));

let focused_id = self.dispatcher.get_state().focused;
let view = self.sub_views.get(&focused_id).unwrap();
let legend = view.legend();

self.render_buffer_bg(area, buf, &state);
self.render_top(page_areas[0], buf, &state, state.message.clone());
self.render_search(page_areas[2], buf, &state);
self.render_devices(middle_areas[0], buf, &state);
self.render_selected_host(middle_column_sections[0], buf, &state);
self.render_host_view_port(middle_column_sections[1], buf, &state);
self.render_config(middle_areas[2], buf, &state);
self.render_footer(page_areas[2], buf, &state);
self.render_footer(legend, page_areas[2], buf, &state);
}
}

Expand Down

0 comments on commit edce626

Please sign in to comment.