1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use std::error::Error;

use ratatui::{
    prelude::{Constraint, Direction, Layout},
    widgets::Paragraph,
};
use widgetui::*;

struct TestChunk;

pub fn chunk_generator(frame: Res<WidgetFrame>, mut chunks: ResMut<Chunks>) -> WidgetResult {
    // A Custom macro to simplify creating your chunks!
    let chunk = layout! {
        frame.size(),
        (%50),
        (#1) => {#3, %100, #3},
        (%50)
    }[1][1];

    chunks.register_chunk::<TestChunk>(chunk);

    Ok(())
}

pub fn render(
    mut frame: ResMut<WidgetFrame>,
    chunks: Res<Chunks>,
    mut events: ResMut<Events>,
) -> WidgetResult {
    let chunk = chunks.get_chunk::<TestChunk>()?;

    frame.render_widget(Paragraph::new("Hello, world!"), chunk);

    if events.key(crossterm::event::KeyCode::Char('q')) {
        events.register_exit();
    }

    Ok(())
}

fn main() -> Result<(), Box<dyn Error>> {
    App::new(100)?
        .handle_panics()
        .widgets((chunk_generator, render))
        .run()
}