Function fltk::draw::draw_rgba_nocopy
source · pub unsafe fn draw_rgba_nocopy<T: WidgetBase>(wid: &mut T, fb: &[u8])
Expand description
Draw a framebuffer (rgba) into a widget
Safety
The data passed should be valid and outlive the widget
Examples found in repository?
examples/fb.rs (line 28)
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
fn main() -> Result<(), Box<dyn std::error::Error>> {
let app = app::App::default();
let mut win = Window::default()
.with_size(WIDTH, HEIGHT)
.with_label("Framebuffer");
let mut frame = frame::Frame::default_fill();
win.end();
win.make_resizable(true);
win.show();
let mut framebuf: Vec<u8> = vec![0; (WIDTH * HEIGHT * 4) as usize];
let mut world = World::new();
unsafe {
draw::draw_rgba_nocopy(&mut frame, &framebuf);
}
app::add_idle3(move |_| {
world.update();
world.draw(&mut framebuf);
// draw::draw_rgba(&mut frame, &framebuf).unwrap(); // A safe variant of draw_rgba_nocopy
win.redraw();
// sleeps are necessary when calling redraw in the event loop
app::sleep(0.016);
});
app.run()?;
Ok(())
}