lunar-mining пре 4 година
родитељ
комит
00e6b6f82c
4 измењених фајлова са 40 додато и 6 уклоњено
  1. 2 1
      bin/map/src/app.rs
  2. 4 0
      bin/map/src/list.rs
  3. 1 0
      bin/map/src/main.rs
  4. 33 5
      bin/map/src/ui.rs

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

@@ -10,6 +10,7 @@ use std::collections::HashMap;
 #[derive(Clone)]
 #[derive(Clone)]
 pub struct App {
 pub struct App {
     pub node_list: StatefulList,
     pub node_list: StatefulList,
+    pub show_popup: bool,
 }
 }
 
 
 impl App {
 impl App {
@@ -25,7 +26,7 @@ impl App {
                 hashmap.insert(id.to_string(), info.to_string());
                 hashmap.insert(id.to_string(), info.to_string());
             }
             }
         }
         }
-        App { node_list: StatefulList::new(hashmap) }
+        App { node_list: StatefulList::new(hashmap), show_popup: false }
     }
     }
 
 
     fn get_node_id() -> Vec<String> {
     fn get_node_id() -> Vec<String> {

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

@@ -2,6 +2,10 @@ use crate::types::{NodeId, NodeInfo};
 use std::collections::HashMap;
 use std::collections::HashMap;
 use tui::widgets::ListState;
 use tui::widgets::ListState;
 
 
+//pub struct NodeInfo {
+//    pub index: u32
+//}
+
 #[derive(Clone)]
 #[derive(Clone)]
 pub struct StatefulList {
 pub struct StatefulList {
     pub state: ListState,
     pub state: ListState,

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

@@ -58,6 +58,7 @@ fn run_app<B: Backend>(
                 }
                 }
                 Key::Char('j') => app.node_list.next(),
                 Key::Char('j') => app.node_list.next(),
                 Key::Char('k') => app.node_list.previous(),
                 Key::Char('k') => app.node_list.previous(),
+                Key::Char('\n') => app.show_popup = !app.show_popup,
                 _ => (),
                 _ => (),
             }
             }
         }
         }

+ 33 - 5
bin/map/src/ui.rs

@@ -1,13 +1,21 @@
+// first one selected
+
 // list on left
 // list on left
 // info page on right
 // info page on right
 // when selected takes up full page
 // when selected takes up full page
+// identifier is random string
+//
+// event handler for the list
+// when the list is selected
+// updates a hashmap that keep track of selected??
+
 use crate::app::App;
 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, List, ListItem, Paragraph},
+    widgets::{Block, Borders, List, ListItem, Paragraph},
     Frame,
     Frame,
 };
 };
 
 
@@ -31,8 +39,8 @@ pub fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
 
 
     let nodes = List::new(nodes)
     let nodes = List::new(nodes)
         .block(Block::default())
         .block(Block::default())
-        .highlight_style(Style::default().bg(Color::Black).add_modifier(Modifier::BOLD))
-        .highlight_symbol(">> ");
+        .highlight_style(Style::default().bg(Color::Black).add_modifier(Modifier::BOLD));
+    //.highlight_symbol(">> ");
 
 
     f.render_stateful_widget(nodes, slice[0], &mut app.node_list.state);
     f.render_stateful_widget(nodes, slice[0], &mut app.node_list.state);
 
 
@@ -41,10 +49,30 @@ pub fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
         info_vec.push(Spans::from(val.to_string()))
         info_vec.push(Spans::from(val.to_string()))
     }
     }
 
 
-    let graph = Paragraph::new(info_vec)
+    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())
         .block(Block::default())
-        .style(Style::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);
+    //    f.render_widget(block, slice[1]);
+    //}
 
 
     // TODO: make this a stateful widget that changes with scroll
     // TODO: make this a stateful widget that changes with scroll
     f.render_widget(graph, slice[1]);
     f.render_widget(graph, slice[1]);
+    //f.render_stateful_widget(info, slice[1], &mut app.node_list.state);
 }
 }