mirui 0.1.2

A lightweight, no_std ECS-driven UI framework for embedded, desktop, and WebAssembly
Documentation
use mirui::draw::{DrawCommand, Renderer, SwRenderer};
use mirui::types::{Color, Rect};
use sdl2::event::Event;
use sdl2::keyboard::Keycode;
use sdl2::pixels::PixelFormatEnum;

const W: u32 = 480;
const H: u32 = 320;

fn main() {
    let sdl = sdl2::init().unwrap();
    let video = sdl.video().unwrap();
    let window = video
        .window("mirui - hello", W, H)
        .position_centered()
        .build()
        .unwrap();
    let mut canvas = window.into_canvas().build().unwrap();
    let texture_creator = canvas.texture_creator();
    let mut texture = texture_creator
        .create_texture_streaming(PixelFormatEnum::RGBA32, W, H)
        .unwrap();

    let mut buf = vec![0u8; (W * H * 4) as usize];
    let clip = Rect {
        x: 0,
        y: 0,
        w: W as u16,
        h: H as u16,
    };

    // Draw with mirui's SwRenderer
    let mut renderer = SwRenderer::new(&mut buf, W, H);

    // Background
    renderer.draw(
        &DrawCommand::Fill {
            area: Rect {
                x: 0,
                y: 0,
                w: W as u16,
                h: H as u16,
            },
            color: Color::rgb(30, 30, 46),
            radius: 0,
            opa: 255,
        },
        &clip,
    );

    // Blue rectangle
    renderer.draw(
        &DrawCommand::Fill {
            area: Rect {
                x: 40,
                y: 40,
                w: 200,
                h: 120,
            },
            color: Color::rgb(88, 166, 255),
            radius: 0,
            opa: 255,
        },
        &clip,
    );

    // Green rectangle
    renderer.draw(
        &DrawCommand::Fill {
            area: Rect {
                x: 140,
                y: 100,
                w: 200,
                h: 120,
            },
            color: Color::rgb(63, 185, 80),
            radius: 0,
            opa: 200,
        },
        &clip,
    );

    // Red rectangle
    renderer.draw(
        &DrawCommand::Fill {
            area: Rect {
                x: 240,
                y: 160,
                w: 200,
                h: 120,
            },
            color: Color::rgb(248, 81, 73),
            radius: 0,
            opa: 180,
        },
        &clip,
    );

    renderer.flush();

    // Blit to SDL
    texture.update(None, &buf, (W * 4) as usize).unwrap();
    canvas.copy(&texture, None, None).unwrap();
    canvas.present();

    // Event loop
    let mut event_pump = sdl.event_pump().unwrap();
    'running: loop {
        for event in event_pump.poll_iter() {
            match event {
                Event::Quit { .. }
                | Event::KeyDown {
                    keycode: Some(Keycode::Escape),
                    ..
                } => break 'running,
                _ => {}
            }
        }
        std::thread::sleep(std::time::Duration::from_millis(16));
    }
}