{
   "author" : "ludions",
   "name" : "Chopsticks GUI",
   "ancestor_list" : [],
   "description" : "A GUI example of nesting Views and multiplying widgets, including mouse actions and Pen drawing for each of the views. Thanks to hjh for spotting an early bug on sc-users. Add your own sound...",
   "labels" : [
      "gui views",
      "gui interaction"
   ],
   "id" : "1-4UM",
   "is_private" : null,
   "code" : "(\r\nvar numX=12, numY=8, width, height, margin;\r\nw = Window.new(\"CompositeView\", Window.availableBounds).front;\r\nwidth = (Window.availableBounds.width/numX).floor;\r\nheight = (Window.availableBounds.height/numY).floor;\r\nmargin = (width + height)/20;\r\nw.addFlowLayout(0@0, 0@0);\r\nt = Array.fill(numX * numY, { arg i;\r\n    var u, n, col, moveTo, lineTo, toggle;\r\n    col = Color.rand;\r\n    toggle = i%2;\r\n    n = CompositeView.new(w, Rect(0, 0, width, height))\r\n        .background_(col);\r\n    u=UserView(n, Rect(margin, margin, width-(margin*2), height-(margin*2))); // OK\r\n    u.background_(col);\r\n    u.drawFunc={|uview|\r\n        if(toggle.asBoolean, {\r\n            moveTo = 0@uview.bounds.height.rand;\r\n            lineTo = uview.bounds.width@uview.bounds.height.rand;\r\n        }, {\r\n            moveTo = uview.bounds.width.rand@uview.bounds.height;\r\n            lineTo = uview.bounds.width.rand@0;\r\n         });\r\n        Pen.moveTo(moveTo);\r\n        Pen.lineTo(lineTo);\r\n        Pen.stroke;\r\n    };\r\n    u.mouseDownAction={|view|\r\n        col = Color.rand;\r\n        u.background_(col);\r\n        n.background_(col);\r\n        toggle = (toggle - 1).abs;\r\n    };\r\n    u.animate_(true);\r\n});\r\nw.front;\r\n)"
}
