35

I would like to create a button using dat.gui library. In a perfect world, this would work like this:

gui.add("button", "click me");
David Smith
  • 38,044
  • 11
  • 44
  • 61
Lonelydatum
  • 1,148
  • 1
  • 13
  • 26

3 Answers3

62

This creates a button with text left aligned.

var obj = { add:function(){ console.log("clicked") }};

gui.add(obj,'add');
kerl
  • 270
  • 1
  • 3
  • 17
Lonelydatum
  • 1,148
  • 1
  • 13
  • 26
30

FWIW, dat.gui assumes the GUI type based on the target's initial value type.

  • boolean => checkbox
  • int/float => slider
  • string => text input
  • function => button

Examples can be found here: http://workshop.chromeexperiments.com/examples/gui/#1--Basic-Usage

eriksssss
  • 410
  • 6
  • 6
0

The chrome experiments example link above is no longer live, but there's a great fiddle; forked and added the button example from Loneydatum's answer.

https://jsfiddle.net/SeanB/qpwsnuxd/3/

var object4 = { add:function(){ alert("clicked") }};
gui.add(object4,'add');
// original fiddle https://jsfiddle.net/ikatyang/182ztwao/
sb333
  • 37
  • 5