Browse Source

map: render node info panel

lunar-mining 4 years ago
parent
commit
609fedc7b1
2 changed files with 16 additions and 19 deletions
  1. 9 8
      bin/map/src/node_info.rs
  2. 7 11
      bin/map/src/ui.rs

+ 9 - 8
bin/map/src/node_info.rs

@@ -1,24 +1,25 @@
 #[derive(Clone)]
 #[derive(Clone)]
 pub struct NodeInfoView {
 pub struct NodeInfoView {
     pub index: usize,
     pub index: usize,
+    pub infos: Vec<NodeInfo>,
 }
 }
 
 
 impl NodeInfoView {
 impl NodeInfoView {
-    pub fn new(_infos: Vec<NodeInfo>) -> NodeInfoView {
+    pub fn new(infos: Vec<NodeInfo>) -> NodeInfoView {
         let index = 0;
         let index = 0;
-        NodeInfoView { index }
+        NodeInfoView { index, infos }
     }
     }
 
 
     pub fn next(&mut self) {
     pub fn next(&mut self) {
-        //self.index = (self.index + 1) % self.info.len();
+        self.index = (self.index + 1) % self.infos.len();
     }
     }
 
 
     pub fn previous(&mut self) {
     pub fn previous(&mut self) {
-        //if self.index > 0 {
-        //    self.index -= 1;
-        //} else {
-        //    self.index = self.info.len() - 1;
-        //}
+        if self.index > 0 {
+            self.index -= 1;
+        } else {
+            self.index = self.infos.len() - 1;
+        }
     }
     }
 }
 }
 
 

+ 7 - 11
bin/map/src/ui.rs

@@ -1,13 +1,10 @@
-use crate::{
-    app::App,
-    //node_info::{NodeInfo, NodeInfoView},
-};
+use crate::app::App;
 use tui::{
 use tui::{
     backend::Backend,
     backend::Backend,
     layout::{Constraint, Direction, Layout},
     layout::{Constraint, Direction, Layout},
     style::{Color, Modifier, Style},
     style::{Color, Modifier, Style},
     text::Spans,
     text::Spans,
-    widgets::{Block, Borders, List, ListItem},
+    widgets::{Block, Borders, List, ListItem, Paragraph},
     Frame,
     Frame,
 };
 };
 
 
@@ -34,12 +31,11 @@ pub fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
 
 
     f.render_stateful_widget(nodes, slice[0], &mut app.node_list.state);
     f.render_stateful_widget(nodes, slice[0], &mut app.node_list.state);
 
 
-    //// call make info here
-    //let text: Vec<Spans> = app.node_info.info.iter().map(|i| Spans::from(i.to_string())).collect();
+    let info: Vec<Spans> =
+        app.node_info.infos.iter().map(|info| Spans::from(info.connections.to_string())).collect();
 
 
-    //let graph = Paragraph::new(text)
-    //    .block(Block::default().borders(Borders::ALL))
-    //    .style(Style::default().fg(Color::LightCyan).add_modifier(Modifier::BOLD));
+    let graph =
+        Paragraph::new(info).block(Block::default().borders(Borders::ALL)).style(Style::default());
 
 
-    //f.render_widget(graph, slice[1]);
+    f.render_widget(graph, slice[1]);
 }
 }