Просмотр исходного кода

map: cleanup and render info box

lunar-mining 4 лет назад
Родитель
Сommit
8e71f4f686
4 измененных файлов с 5 добавлено и 44 удалено
  1. 1 4
      bin/map/src/app.rs
  2. 1 10
      bin/map/src/list.rs
  3. 1 1
      bin/map/src/main.rs
  4. 2 29
      bin/map/src/ui.rs

+ 1 - 4
bin/map/src/app.rs

@@ -1,14 +1,11 @@
 use crate::{
-    node::{NodeId, NodeInfo},
     list::StatefulList,
+    node::{NodeId, NodeInfo},
 };
 use rand::Rng;
 use smol::Timer;
 use std::{collections::HashMap, time::Duration};
 
-// the information here should be continually updating
-// nodes are added from the result of rpc requests
-
 #[derive(Clone)]
 pub struct App {
     pub node_list: StatefulList,

+ 1 - 10
bin/map/src/list.rs

@@ -1,20 +1,11 @@
-use crate::{
-    node::{NodeId, NodeInfo},
-    ui::render_selected,
-};
+use crate::node::{NodeId, NodeInfo};
 use std::collections::HashMap;
 use tui::widgets::ListState;
 
-// TODO: make this just a list
-// hashmaps are owned by App
 #[derive(Clone)]
 pub struct StatefulList {
     pub state: ListState,
     pub nodes: NodeId,
-    //pub nodes: HashMap<NodeId, NodeInfo>,
-    //pub node_info: NodeInfo,
-    //pub index: HashMap<usize, NodeInfo>,
-    //pub node_info: InfoScreen,
 }
 
 impl StatefulList {

+ 1 - 1
bin/map/src/main.rs

@@ -17,8 +17,8 @@ use tui::{
 };
 
 pub mod app;
-pub mod node;
 pub mod list;
+pub mod node;
 pub mod ui;
 
 use crate::app::App;

+ 2 - 29
bin/map/src/ui.rs

@@ -36,37 +36,10 @@ pub fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
 
     f.render_stateful_widget(nodes, slice[0], &mut app.node_list.state);
 
-    // TODO render node info as box
-    //let node_info: Vec<ListItem> = app
-    //    .node_list
-    //    .node_info
-    //    .info
-    //    .iter()
-    //    .map(|i| {
-    //        let line1 = Spans::from(i.to_string());
-    //        ListItem::new(vec![line1]).style(Style::default())
-    //    })
-    //    .collect();
-
-    //let node_info = List::new(node_info)
-    //    .block(Block::default().borders(Borders::ALL))
-    //    .highlight_style(Style::default().fg(Color::LightCyan).add_modifier(Modifier::BOLD));
-
-    //f.render_stateful_widget(node_info, slice[1], &mut app.node_list.state);
-}
-
-// TODO: rename to frame2
-pub fn render_selected(n: &NodeInfo) {
-    //let slice = Layout::default()
-    //    .direction(Direction::Horizontal)
-    //    .margin(2)
-    //    .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
-    //    .split(f.size());
-
-    let text: Vec<Spans> = n.info.iter().map(|i| Spans::from(i.to_string())).collect();
+    let text: Vec<Spans> = app.node_info.info.iter().map(|i| Spans::from(i.to_string())).collect();
     let graph = Paragraph::new(text)
         .block(Block::default().borders(Borders::ALL))
         .style(Style::default().fg(Color::LightCyan).add_modifier(Modifier::BOLD));
 
-    //f.render_widget(graph, slice[1]);
+    f.render_widget(graph, slice[1]);
 }