Crate direct_gui [−] [src]
Draw GUI controls directly on a buffer
Usage
This crate is on crates.io and can be used by adding
direct-gui
to the dependencies in your project's Cargo.toml
.
[dependencies]
direct-gui = "0.1"
and this to your crate root:
extern crate direct_gui;
Examples
use direct_gui::*; use direct_gui::controls::*; let screen_size = (800i32, 600i32); // Create a buffer where we will render to let mut buffer: Vec<u32> = vec![0; (screen_size.0 * screen_size.1) as usize]; // Create a new instance of the gui let mut gui = Gui::new(screen_size); // Load the sprite of a button let button_img = gui.load_sprite_from_file("examples/button.png", Color::from_u32(0xFF00FF)).unwrap(); // Create a new button using the sprite loaded before at pixel (20, 10) gui.register(Button::new_with_sprite(button_img).with_pos(20, 10)); // Handle "input events" by pretending that the mouse is hovering over the button. let cs = ControlState { mouse_pos: (22, 12), ..ControlState::default() }; gui.update(&cs); // Finally render the current gui state to the buffer gui.draw_to_buffer(&mut buffer);
Modules
controls |
Structs
Color |
A newtype representing the color in a buffer. |
ControlRef |
A newtype used to as a reference for controls. |
FontSettings | |
Gui |
The main entry point. |
InvalidControlReference |
An error type for when a reference is not valid anymore. |