#graph #graphics #color

minifb_wrapper

A wrapper around minifb to make managing windows easier than ever

2 releases

0.1.3 Apr 30, 2023
0.1.2 Apr 25, 2023
0.1.1 Apr 25, 2023
0.1.0 Apr 24, 2023

#646 in Images

27 downloads per month

MIT/Apache

15KB
250 lines

A wrapper around minifb that makes opening and managing windows as straightforward as possible, and with hexidecimal RGB rather than raw u32.

This is an example code that will generate a UV coordinate map:

use miniwrap::*;

fn main() -> Result<(), WinErr> {
    let mut window = window!(?255, 255, "Window", "FFFFFF");

    //iterates with the value and position
    for (_, pos) in window.iter() {
        let r = to_hex2(pos.0 as u8).unwrap();
        let g = to_hex2(pos.1 as u8).unwrap();
        let string = format!("{r}{g}00");

        window.set(pos, &string)?;
    }

    //pressing escape will close the window
    loop {
        window.update();
    }    
}


lib.rs:

A wrapper around [minifb] that makes managing windows as simple as possible, with hexidecimal RGB rather than raw u32.

Window elements like buffers and dimensions are linked together in the [WindowContainer] struct. To keep the window alive, call update() from within a loop. This has a built-in graceful exit by pressing ESC.

let window = window!(?500, 500, "Window", "FFFFFF");

loop {
    window.update();
}

Heres an example of a UV map generated from pixel coordinates:

let window = window!(?500, 500, "Window", "FFFFFF");

//iterates with the value and position
for (_, pos) in window.iter() {
    let r = to_hex2(pos.0 as u8).unwrap();
    let g = to_hex2(pos.1 as u8).unwrap();
    let string = format!("{r}{g}00");

    window.set(pos, &string)?;
}

//pressing escape will close the window
loop {
    window.update();
}

Note with the hexidecimal conversions: functions that take hexidecimal will take a &str for convenience, but functions that return hexidecimal will return a [String].

Dependencies

~0.4–2.5MB
~42K SLoC