From 0637dde94cbac0bad9a331aee23759646bb25fb3 Mon Sep 17 00:00:00 2001 From: lunar-mining Date: Thu, 13 Jan 2022 12:11:58 +0100 Subject: [PATCH] map: split screen and simplify display --- bin/map/src/app.rs | 1 + bin/map/src/ui.rs | 29 +++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/bin/map/src/app.rs b/bin/map/src/app.rs index c9e8edf7e..a941cf2c5 100644 --- a/bin/map/src/app.rs +++ b/bin/map/src/app.rs @@ -19,6 +19,7 @@ impl App { let node_id = Self::get_node_id(); let node_info = Self::get_node_info(); + // TODO: fix this for id in node_id.iter() { for info in node_info.iter() { hashmap.insert(id.to_string(), info.to_string()); diff --git a/bin/map/src/ui.rs b/bin/map/src/ui.rs index cb3014e4e..8b0365d17 100644 --- a/bin/map/src/ui.rs +++ b/bin/map/src/ui.rs @@ -1,14 +1,21 @@ +// list on left +// info page on right +// when selected takes up full page use crate::app::App; use tui::{ backend::Backend, + layout::{Constraint, Direction, Layout}, style::{Color, Modifier, Style}, text::Spans, - widgets::{Block, Borders, List, ListItem}, + widgets::{Block, List, ListItem, Paragraph}, Frame, }; pub fn ui(f: &mut Frame, app: &mut App) { - let size = f.size(); + let slice = Layout::default() + .direction(Direction::Horizontal) + .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) + .split(f.size()); let nodes: Vec = app .node_list @@ -22,12 +29,22 @@ pub fn ui(f: &mut Frame, app: &mut App) { }) .collect(); - // Create a List from all list nodes and highlight the currently selected one let nodes = List::new(nodes) - .block(Block::default().borders(Borders::ALL).title("List of nodes")) + .block(Block::default()) .highlight_style(Style::default().bg(Color::Black).add_modifier(Modifier::BOLD)) .highlight_symbol(">> "); - // Render the item list - f.render_stateful_widget(nodes, size, &mut app.node_list.state); + f.render_stateful_widget(nodes, slice[0], &mut app.node_list.state); + + let mut info_vec = Vec::new(); + for val in app.node_list.nodes.values() { + info_vec.push(Spans::from(val.to_string())) + } + + let graph = Paragraph::new(info_vec) + .block(Block::default()) + .style(Style::default()); + + // TODO: make this a stateful widget that changes with scroll + f.render_widget(graph, slice[1]); }