Code Sketch


My own little GUI with a Button Reactor
By: Björn Regnell
Category: Programming
clear(); turtle0.invisible()

case class Button(
  name:String,
  x:Double,
  y:Double,
  reaction:() => Unit
) {
  val length = name.size*12
  val but = Staging.line(x, y, length, 0)
  but.setPenThickness(40)
  but.setPenColor(gray.darker)
  val tex = Staging.text(name, 0, 12)
  tex.setPenColor(white)
  tex.setFontSize(18)
  tex.onMouseClick { (x, y) => reaction() }
  but.onMouseClick { (x, y) => reaction() }
}
  
var i = 0

def reactor() {
  i += 1
  println("Björn was pressed " + i)
}

Button("BJÖRN",0,0,reactor)