Selaa lähdekoodia

map: split screen and simplify display

lunar-mining 4 vuotta sitten
vanhempi
sitoutus
0637dde94c
2 muutettua tiedostoa jossa 24 lisäystä ja 6 poistoa
  1. 1 0
      bin/map/src/app.rs
  2. 23 6
      bin/map/src/ui.rs

+ 1 - 0
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());

+ 23 - 6
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<B: Backend>(f: &mut Frame<B>, 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<ListItem> = app
         .node_list
@@ -22,12 +29,22 @@ pub fn ui<B: Backend>(f: &mut Frame<B>, 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]);
 }