guigui
GUI tool for creative coding projects Inspired from dat.GUI. Check out the demo.
Install
npm install guigui --save
Getting started
var guigui = ; var targetObject = x: 0; guigui;
A couple things happened here. First by calling the add Method of guigui, you automatically created a panel called Settings
in which your component will go. Then guigui detected the type of the x
property from targetObject
to be a Number and picked the slider component accordingly.
Components
When possible guigui will auto detect the targeted property type and chose which component should be used. Here are the available components.
Slider
to manipulate numerical values in a given range.Toggler
a button with a truthy and a falsy state to handle booleans. Equivalent to checkbox.Launcher
a button to launch a function.Text
a text input for string modification.Select
a dropdown select component.Colorpicker
To handle colors.
The select component will be invoked for a Number or a String if the third parameter of the guigui.add()
function is an array.
Also the ColorPicker cannot be invoked from the add
function. Instead you need to call the guigui.addColorPicker()
function.
For all components you can use a third options arguments to configure the component more precisely. See below for more explanations.
// The source object we want to controlconst myObject = num: 9 name: 'My Object' {} isActive: false color: '#FF0000' type: 'awesome' // Add some components to control myObjectguiguiguiguiguiguiguigui // Special cases, Select and ColorPicker componentsguiguiguigui
Panels and folders
If you don't do it yourself, guigui will automatically create a panel called Settings
when you first use guigui.add(...)
. You can however create any number of panels yourself with the guigui.addPanel()
method.
// manually create panelsconst panel1 = guiguiconst panel2 = guigui // create components inside these panelsconst o = a: 0 b: 1 c: 2panel1panel1panel2
Each panel can contain components and folders. To create a folder in a panel you need to call the guigui.addFolder()
method.
// creates folder in guigui default panelconst f1 = guiguiconst f2 = guigui // add folders to another folderconst subF1 = f1const subF2 = f1
Slider
Controls a number.
const o = a: 06 guigui
Text
Controls a string.
const o = a: 'foo' guigui
Toggler
Controls a boolean.
const o = a: true guigui
Launcher
Launches a function.
const o = {} guigui
Select
Changes a value from an array of choices.
const choices = 0 1 2 3const o = a: 0 guigui
ColorPicker
Controls hex colors from string or number. It's also compatible with THREE.js Color class.
const o = css: '#DA5137' hex: '#84AF52' three: 0x97C4E9 guiguiguiguiguigui
Callbacks and events
All components can be passed a watch
option, a boolean, to specify if the component should auto update when targetObject[property]
is changed outside of the Gui. This option defaults to false.
const o = x: 0 y: 0guiox = 1// our slider component value will be updated to 1 guioy = 2// our slider component value did not change
Additionnaly all components extend EventEmitter
and you can listen for value changes for custom behaviors.
gui
Motivations
This library was mainly made as an exercise, and also to fill my need for a GUI tool for creative development. I also encountered various annoying behaviors with dat.GUI that i wished to avoid here :
- Slider value representation should ALWAYS be based on the
step
param. - Sometimes the colorPicker of dat.GUI will become black when trying to edit the text input.
- Min and Max of slider should be displayed.
What's next
- Panel Scrolling
- Drag and drop
- Themes
Contributing
npm installnpm start
Demo
To work on demo in local you will want to link your local version of guigui to the one used in the demo folder.
npm linkcd demonpm link guiguinpm start