#gui #gamedev

direct-gui

Simple direct rendering of GUI controls on a buffer

26 releases

✓ Uses Rust 2018 edition

0.1.25 Apr 16, 2020
0.1.24 Feb 12, 2020
0.1.22 Jul 28, 2019
0.1.21 Nov 16, 2018
0.1.12 Jan 31, 2018

#23 in #gui

Download history 77/week @ 2020-03-14 228/week @ 2020-03-21 37/week @ 2020-03-28 45/week @ 2020-04-04 194/week @ 2020-04-11 119/week @ 2020-04-18 10/week @ 2020-04-25 9/week @ 2020-05-02 28/week @ 2020-05-09 5/week @ 2020-05-16 30/week @ 2020-05-23 80/week @ 2020-05-30 10/week @ 2020-06-06 29/week @ 2020-06-13 1/week @ 2020-06-20 39/week @ 2020-06-27

330 downloads per month
Used in 3 crates

GPL-3.0 license

48KB
636 lines

direct-gui

Simple direct rendering GUI controls

CI Version Rust Documentation License

Documentation

Usage

Add this to your Cargo.toml:

[dependencies]
direct-gui = "0.1"

And this to your crate root:

extern crate direct_gui;

Run the examples

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

Example

cargo run --example label

Example

cargo run --example sprite

Example

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", 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);

Credits

Sprite feature by Hammster

Default font by usr_share

Dependencies

~5MB
~101K SLoC