ui.rs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // first one selected
  2. // list on left
  3. // info page on right
  4. // when selected takes up full page
  5. // identifier is random string
  6. //
  7. // event handler for the list
  8. // when the list is selected
  9. // updates a hashmap that keep track of selected??
  10. use crate::app::App;
  11. use tui::{
  12. backend::Backend,
  13. layout::{Constraint, Direction, Layout},
  14. style::{Color, Modifier, Style},
  15. text::Spans,
  16. widgets::{Block, List, ListItem},
  17. Frame,
  18. };
  19. pub fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
  20. let slice = Layout::default()
  21. .direction(Direction::Horizontal)
  22. .margin(1)
  23. .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
  24. .split(f.size());
  25. let nodes: Vec<ListItem> = app
  26. .node_list
  27. .nodes
  28. .iter()
  29. .map(|(id, info)| {
  30. let line1 = Spans::from(id.to_string());
  31. let line2 = Spans::from(info.to_string());
  32. ListItem::new(vec![line1, line2]).style(Style::default())
  33. })
  34. .collect();
  35. let nodes = List::new(nodes)
  36. .block(Block::default())
  37. .highlight_style(Style::default().fg(Color::LightCyan).add_modifier(Modifier::BOLD));
  38. f.render_stateful_widget(nodes, slice[0], &mut app.node_list.state);
  39. let node_info: Vec<ListItem> = app
  40. .node_list
  41. .node_info
  42. .info
  43. .iter()
  44. .map(|i| {
  45. let line1 = Spans::from(i.to_string());
  46. ListItem::new(vec![line1]).style(Style::default())
  47. })
  48. .collect();
  49. let node_info = List::new(node_info)
  50. .block(Block::default())
  51. .highlight_style(Style::default().fg(Color::LightCyan).add_modifier(Modifier::BOLD));
  52. f.render_stateful_widget(node_info, slice[1], &mut app.node_list.state);
  53. }