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

map: partially implemented NodeInfo struct

lunar-mining 4 лет назад
Родитель
Сommit
a30b6c15dc
3 измененных файлов с 34 добавлено и 19 удалено
  1. 1 0
      bin/map/src/app.rs
  2. 18 4
      bin/map/src/list.rs
  3. 15 15
      bin/map/src/ui.rs

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

@@ -47,6 +47,7 @@ impl App {
         node_info
     }
 
+    // every 5 seconds
     // TODO: implement this
     //fn update(&mut self) {
     //    let node = self.node.remove(0);

+ 18 - 4
bin/map/src/list.rs

@@ -2,27 +2,41 @@ use crate::types::{NodeId, NodeInfo};
 use std::collections::HashMap;
 use tui::widgets::ListState;
 
-//pub struct NodeInfo {
-//    pub index: u32
-//}
+#[derive(Clone)]
+pub struct NodeExtra {
+    pub index: u32,
+    pub noise: String,
+}
 
+impl NodeExtra {
+    pub fn new() -> NodeExtra {
+        let mut index = 0;
+        NodeExtra { index, noise: String::new()}
+    }
+}
 #[derive(Clone)]
 pub struct StatefulList {
     pub state: ListState,
     pub nodes: HashMap<NodeId, NodeInfo>,
+    pub nodex: NodeExtra,
 }
 
 impl StatefulList {
     pub fn new(nodes: HashMap<NodeId, NodeInfo>) -> StatefulList {
-        StatefulList { state: ListState::default(), nodes }
+        StatefulList { state: ListState::default(), nodes, nodex: NodeExtra::new() }
     }
 
     pub fn next(&mut self) {
+        let index = self.nodex.index;
+
+        // index
         let i = match self.state.selected() {
             Some(i) => {
                 if i >= self.nodes.len() - 1 {
+                    //index = 0;
                     0
                 } else {
+                    //index + 1;
                     i + 1
                 }
             }

+ 15 - 15
bin/map/src/ui.rs

@@ -15,7 +15,7 @@ use tui::{
     layout::{Constraint, Direction, Layout},
     style::{Color, Modifier, Style},
     text::Spans,
-    widgets::{Block, Borders, List, ListItem, Paragraph},
+    widgets::{Block, List, ListItem, Paragraph},
     Frame,
 };
 
@@ -49,23 +49,23 @@ pub fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
         info_vec.push(Spans::from(val.to_string()))
     }
 
-    let info: Vec<ListItem> = app
-        .node_list
-        .nodes
-        .values()
-        //.iter()
-        .map(|i| {
-            let line2 = Spans::from(i.to_string());
-            ListItem::new(vec![line2]).style(Style::default())
-        })
-        .collect();
+    //let info: Vec<ListItem> = app
+    //    .node_list
+    //    .nodes
+    //    .values()
+    //    //.iter()
+    //    .map(|i| {
+    //        let line2 = Spans::from(i.to_string());
+    //        ListItem::new(vec![line2]).style(Style::default())
+    //    })
+    //    .collect();
 
     let graph = Paragraph::new(info_vec).block(Block::default()).style(Style::default());
 
-    let info = List::new(info)
-        .block(Block::default())
-        .highlight_style(Style::default().bg(Color::Black).add_modifier(Modifier::BOLD))
-        .highlight_symbol(">> ");
+    //let info = List::new(info)
+    //    .block(Block::default())
+    //    .highlight_style(Style::default().bg(Color::Black).add_modifier(Modifier::BOLD))
+    //    .highlight_symbol(">> ");
 
     //if app.show_popup {
     //    let block = Block::default().title("Popup").borders(Borders::ALL);