Crates.io | direct-gui |
lib.rs | direct-gui |
version | 0.1.26 |
source | src |
created_at | 2018-01-13 12:26:11.306638 |
updated_at | 2020-10-10 13:28:44.301487 |
description | Simple direct rendering of GUI controls on a buffer |
homepage | https://github.com/tversteeg/direct-gui |
repository | https://github.com/tversteeg/direct-gui.git |
max_upload_size | |
id | 46647 |
size | 117,813 |
Simple direct rendering GUI controls
Add this to your Cargo.toml
:
[dependencies]
direct-gui = "0.1"
And this to your crate root:
extern crate direct_gui;
On Linux you need the xkb
& wayland
packages as required by minifb
-- sudo apt install libwayland-cursor0 libxkbcommon-dev libwayland-dev
cargo run --example button
cargo run --example label
cargo run --example sprite
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", 0xFF00FF).unwrap();
// Create a new button using the sprite loaded before at pixel (20, 10)
gui.register(Button::new(button_img).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);
Sprite feature by Hammster
Default font by usr_share