map: render node info panel

This commit is contained in:
lunar-mining
2022-01-16 19:31:24 +01:00
parent da83426f1f
commit 609fedc7b1
2 changed files with 16 additions and 19 deletions

View File

@@ -1,24 +1,25 @@
#[derive(Clone)]
pub struct NodeInfoView {
pub index: usize,
pub infos: Vec<NodeInfo>,
}
impl NodeInfoView {
pub fn new(_infos: Vec<NodeInfo>) -> NodeInfoView {
pub fn new(infos: Vec<NodeInfo>) -> NodeInfoView {
let index = 0;
NodeInfoView { index }
NodeInfoView { index, infos }
}
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) {
//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;
}
}
}

View File

@@ -1,13 +1,10 @@
use crate::{
app::App,
//node_info::{NodeInfo, NodeInfoView},
};
use crate::app::App;
use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout},
style::{Color, Modifier, Style},
text::Spans,
widgets::{Block, Borders, List, ListItem},
widgets::{Block, Borders, List, ListItem, Paragraph},
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);
//// 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]);
}