Crate pixels_graphics_lib
source · [−]Expand description
Rust Graphics Lib
This is a simple wrapper around Pixels
, it provides basic shape, image and text rendering.
This boilerplate code is needed to use it:
let event_loop = EventLoop::new();
let mut input = WinitInputHelper::new();
let (mut window, mut graphics) = setup((240, 160), WindowScaling::Auto, "Doc Example", &event_loop)?;
event_loop.run(move |event, _, control_flow| {
if let Event::RedrawRequested(_) = event {
if graphics.pixels
.render()
.map_err(|e| eprintln ! ("pixels.render() failed: {:?}", e))
.is_err()
{
*control_flow = ControlFlow::Exit;
return;
}
}
//put your rendering code here
if input.update(&event) {
if input.key_pressed(VirtualKeyCode::Escape) || input.quit() {
*control_flow = ControlFlow::Exit;
return;
}
if let Some(size) = input.window_resized() {
graphics.pixels.resize_surface(size.width, size.height);
}
//put your update/input handling code here
window.request_redraw();
}
});
Using the library is as simple as:
graphics.draw_text("Some text", 9, 1, 1, TextSize::Normal, BLACK);
graphics.draw_line(30, 30, 100, 120, BLUE);
Modules
Enums
Traits
Functions
Creates the window and pixels wrapper