#gui #gamedev

direct-gui

Simple direct rendering of GUI controls on a buffer

23 releases

0.1.22 Jul 28, 2019
0.1.21 Nov 16, 2018
0.1.20 May 16, 2018
0.1.18 Mar 4, 2018
0.1.12 Jan 31, 2018

#36 in GUI

Download history 31/week @ 2019-10-12 26/week @ 2019-10-19 50/week @ 2019-10-26 50/week @ 2019-11-02 3/week @ 2019-11-09 75/week @ 2019-11-16 6/week @ 2019-11-23 83/week @ 2019-11-30 672/week @ 2019-12-07 74/week @ 2019-12-14 4/week @ 2019-12-21 26/week @ 2019-12-28 3/week @ 2020-01-04 186/week @ 2020-01-11 118/week @ 2020-01-18

404 downloads per month
Used in 3 crates

GPL-3.0 license

46KB
558 lines

direct-gui

Simple direct rendering GUI controls

Build Status Cargo License: GPL-3.0 Downloads

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 xorg-dev package as required by minifb -- sudo apt install xorg-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

~4.5MB
~93K SLoC