appcui 0.4.8

A feature-rich and cross-platform TUI/CUI framework for Rust, enabling modern terminal-based applications on Windows, Linux, and macOS. Includes built-in UI components like buttons, menus, list views, tree views, checkboxes, and more. Perfect for building fast and interactive CLI tools and text-based interfaces.
Documentation
use super::super::Graph;
use super::super::GraphNode;
use crate::graphics::*;

pub(in super::super) fn rearange<T: GraphNode>(graph: &mut Graph<T>, space: i32) {
    if graph.nodes.is_empty() {
        return;
    }
    let len = graph.nodes.len() as u32;
    let columns = (((len as f64).sqrt()) as u32).max(1);
    let mut cell_size = Size::new(1, 1);
    for node in &graph.nodes {
        let sz = node.rect.size();
        cell_size.width = cell_size.width.max(sz.width);
        cell_size.height = cell_size.height.max(sz.height);
    }
    let mut column = 0;
    let mut x = 0;
    let mut y = 0;
    for node in &mut graph.nodes {
        node.rect.set_left(x, true);
        node.rect.set_top(y, true);
        x += (cell_size.width as i32) + space * 2;
        column += 1;
        if column == columns {
            x = 0;
            column = 0;
            y += (cell_size.height as i32) + space;
        }
    }
}