use ratatui::{
Frame, Terminal,
backend::CrosstermBackend,
widgets::{BorderType, Paragraph},
};
use ratatui_flow::*;
struct App {}
impl App {
fn new() -> Self {
Self {}
}
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
print!("\x1b[2J\x1b[1;1H");
let stdout = std::io::stdout();
let backend = CrosstermBackend::new(stdout);
let mut terminal = Terminal::new(backend)?;
let app = App::new();
terminal.draw(|f| ui(f, &app))?;
print!("\r\n");
Ok(())
}
fn ui(f: &mut Frame, _app: &App) {
let space = f.area();
let mut graph = NodeGraph::new(
vec![
NodeLayout::new((40, 10))
.with_title("a|b|c")
.with_border_type(BorderType::Thick),
NodeLayout::new((40, 10))
.with_title("b|c")
.with_border_type(BorderType::Thick),
NodeLayout::new((40, 10))
.with_title("c")
.with_border_type(BorderType::Rounded),
NodeLayout::new((40, 10))
.with_title("d>c")
.with_border_type(BorderType::Thick),
NodeLayout::new((40, 10))
.with_title("e|d")
.with_border_type(BorderType::Double),
NodeLayout::new((30, 5))
.with_title("f>(b,e)")
.with_border_type(BorderType::Thick),
NodeLayout::new((30, 5))
.with_title("g|(a,f)")
.with_border_type(BorderType::Double),
],
vec![
Connection::new(0usize.into(), 0usize.into(), 1usize.into(), 0usize.into())
.with_line_type(LineType::Double), Connection::new(1usize.into(), 0usize.into(), 2usize.into(), 0usize.into())
.with_line_type(LineType::Thick), Connection::new(3usize.into(), 0usize.into(), 2usize.into(), 1usize.into())
.with_line_type(LineType::Double), Connection::new(4usize.into(), 0usize.into(), 3usize.into(), 0usize.into()), Connection::new(4usize.into(), 0usize.into(), 0usize.into(), 1usize.into()), Connection::new(5usize.into(), 0usize.into(), 1usize.into(), 1usize.into()), Connection::new(5usize.into(), 0usize.into(), 4usize.into(), 6usize.into()), Connection::new(6usize.into(), 0usize.into(), 0usize.into(), 0usize.into())
.with_line_type(LineType::Double), Connection::new(6usize.into(), 0usize.into(), 5usize.into(), 0usize.into())
.with_line_type(LineType::Double), ],
space.width as usize,
space.height as usize,
);
graph.calculate();
let zones = graph.split(space);
for (idx, ea_zone) in zones.into_iter().enumerate() {
f.render_widget(Paragraph::new(format!("{idx}")), ea_zone);
}
f.render_stateful_widget(graph, space, &mut FlowState::default());
}