mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
map: render scrolling node_info
This commit is contained in:
@@ -28,7 +28,7 @@ impl App {
|
||||
},
|
||||
NodeInfo {
|
||||
id: "038043325alsdlasjfrsdfsdfsdjsdf".to_string(),
|
||||
connections: 5,
|
||||
connections: 7,
|
||||
is_active: true,
|
||||
last_message: "gm".to_string(),
|
||||
},
|
||||
|
||||
@@ -45,6 +45,7 @@ fn run_app<B: Backend>(
|
||||
|
||||
app.node_list.state.select(Some(0));
|
||||
|
||||
app.node_info.index = 0;
|
||||
//let mut last_tick = Instant::now();
|
||||
|
||||
loop {
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct NodeInfoView {
|
||||
pub index: usize,
|
||||
pub info_map: HashMap<usize, NodeInfo>,
|
||||
pub infos: Vec<NodeInfo>,
|
||||
}
|
||||
|
||||
impl NodeInfoView {
|
||||
pub fn new(infos: Vec<NodeInfo>) -> NodeInfoView {
|
||||
let index = 0;
|
||||
NodeInfoView { index, infos }
|
||||
let mut info_map: HashMap<usize, NodeInfo> = HashMap::new();
|
||||
let mut index = 0;
|
||||
|
||||
for info in infos.clone() {
|
||||
info_map.insert(index, info);
|
||||
index += 1;
|
||||
}
|
||||
|
||||
NodeInfoView { index, info_map, infos }
|
||||
}
|
||||
|
||||
pub fn next(&mut self) {
|
||||
|
||||
@@ -31,11 +31,75 @@ pub fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
|
||||
|
||||
f.render_stateful_widget(nodes, slice[0], &mut app.node_list.state);
|
||||
|
||||
let info: Vec<Spans> =
|
||||
app.node_info.infos.iter().map(|info| Spans::from(info.connections.to_string())).collect();
|
||||
|
||||
let graph =
|
||||
Paragraph::new(info).block(Block::default().borders(Borders::ALL)).style(Style::default());
|
||||
|
||||
f.render_widget(graph, slice[1]);
|
||||
// TODO: cleanup this boilerplate
|
||||
// pass index value to render_info()
|
||||
match app.node_info.index {
|
||||
0 => {
|
||||
let id = &app.node_info.infos[0].id;
|
||||
let connections = app.node_info.infos[0].connections;
|
||||
let span = vec![
|
||||
Spans::from(format!("NodeId: {}", id)),
|
||||
Spans::from(format!("Number of connections: {}", connections)),
|
||||
];
|
||||
let graph = Paragraph::new(span)
|
||||
.block(Block::default().borders(Borders::ALL))
|
||||
.style(Style::default());
|
||||
f.render_widget(graph, slice[1]);
|
||||
}
|
||||
1 => {
|
||||
let id = &app.node_info.infos[1].id;
|
||||
let connections = app.node_info.infos[1].connections;
|
||||
let span = vec![
|
||||
Spans::from(format!("NodeId: {}", id)),
|
||||
Spans::from(format!("Number of connections: {}", connections)),
|
||||
];
|
||||
let graph = Paragraph::new(span)
|
||||
.block(Block::default().borders(Borders::ALL))
|
||||
.style(Style::default());
|
||||
f.render_widget(graph, slice[1]);
|
||||
}
|
||||
2 => {
|
||||
let id = &app.node_info.infos[2].id;
|
||||
let connections = app.node_info.infos[2].connections;
|
||||
let span = vec![
|
||||
Spans::from(format!("NodeId: {}", id)),
|
||||
Spans::from(format!("Number of connections: {}", connections)),
|
||||
];
|
||||
let graph = Paragraph::new(span)
|
||||
.block(Block::default().borders(Borders::ALL))
|
||||
.style(Style::default());
|
||||
f.render_widget(graph, slice[1]);
|
||||
}
|
||||
3 => {
|
||||
let id = &app.node_info.infos[3].id;
|
||||
let connections = app.node_info.infos[3].connections;
|
||||
let span = vec![
|
||||
Spans::from(format!("NodeId: {}", id)),
|
||||
Spans::from(format!("Number of connections: {}", connections)),
|
||||
];
|
||||
let graph = Paragraph::new(span)
|
||||
.block(Block::default().borders(Borders::ALL))
|
||||
.style(Style::default());
|
||||
f.render_widget(graph, slice[1]);
|
||||
}
|
||||
4 => {
|
||||
let id = &app.node_info.infos[4].id;
|
||||
let connections = app.node_info.infos[3].connections;
|
||||
let span = vec![
|
||||
Spans::from(format!("NodeId: {}", id)),
|
||||
Spans::from(format!("Number of connections: {}", connections)),
|
||||
];
|
||||
let graph = Paragraph::new(span)
|
||||
.block(Block::default().borders(Borders::ALL))
|
||||
.style(Style::default());
|
||||
f.render_widget(graph, slice[1]);
|
||||
}
|
||||
_ => {
|
||||
// do something
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// render_info(index)
|
||||
// return info at index
|
||||
// render info
|
||||
|
||||
Reference in New Issue
Block a user