#menu #gfx

dev_menu

A simple in-engine developer menu library

25 breaking releases

0.26.0 Feb 6, 2019
0.25.0 Nov 15, 2018
0.24.0 Nov 6, 2018
0.22.0 May 27, 2018
0.1.0 May 28, 2015

#4 in #menu

Download history 55/week @ 2018-11-22 188/week @ 2018-11-29 14/week @ 2018-12-06 31/week @ 2018-12-13 208/week @ 2018-12-20 4/week @ 2018-12-27 31/week @ 2019-01-03 8/week @ 2019-01-10 4/week @ 2019-01-17 6/week @ 2019-01-24 11/week @ 2019-01-31 13/week @ 2019-02-07 1/week @ 2019-02-14 6/week @ 2019-02-21 61/week @ 2019-02-28

254 downloads per month

MIT license

11KB
189 lines

dev_menu Build Status

In-game developer menu for Piston and gfx-rs

Documentation

Usage

A Menu instance can be intitialized to operate on some particular type, for example a "Settings" struct:

pub struct Settings {
	setting_a: bool,
	setting_b: f32,
	// ... etc
}

...

let mut menu = dev_menu::Menu<Settings>::new();

Menu items display in a vertical list, and the selection can be changed with the up and down arrow keys.

Items can be added to the menu with add_item. An ActionItem, when selected, executes a given closure when the spacebar or left or right arrow keys are hit. For example, it can be used to toggle a boolean setting as follows:

menu.add_item(dev_menu::MenuItem::action_item(
	"Toggle Setting A", // Label for the item
	Box::new(|ref mut settings| { settings.setting_a = !settings.setting_a; }) // Closure to execute
));

A SliderItem, when selected, can be used to increment or decrement a particular value while the right or left arrow keys are held down, using a pair of accessor closures to get or set the value within the settings object. It will also display the current value to the right of the label. For example:

menu.add_item(dev_menu::MenuItem::slider_item(
	"Setting B = ", // Label for the item. Value will show to the right
	[-5.0, 5.0], // Valid range for the value
	0.01, // Value to increment / decrement by on each update, while key is held down
	Box::new(|ref settings| { settings.setting_b }), // Closure for retrieving value
	Box::new(|ref mut settings, value| { settings.setting_b = value }), // Closure for setting value
));

To update and render the menu, using the Piston event loop:

for e in window.events() {

	// Send event to menu, with the settings object that should be accessed and/or modified
	menu.event(&e, &mut settings);

	...

	e.render(|args| {

		...

		// Draw the menu with gfx_debug_draw::DebugRenderer
		menu.draw(&settings, &mut debug_renderer);

		...
	}
}

Dependencies

~4MB
~72K SLoC