TestButtons.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. var view = Atomic.game.uiView;
  2. var deltaTime = 0;
  3. var widgetClicked = false;
  4. function start() {
  5. // will go out of scope, however will be held while the
  6. // button is in a UI heirarchy
  7. var widget = new Atomic.UIWidget();
  8. widget.setSize(256, 256);
  9. view.addChild(widget);
  10. var button = new Atomic.UIButton();
  11. button.text = "Click Me To Destroy";
  12. button.setSize(256, 256);
  13. widget.addChild(button);
  14. widget.onClick = function() {
  15. widgetClicked = true;
  16. print ("Error: Widget on Click!");
  17. }
  18. button.onClick = function() {
  19. print ("Button on Click!");
  20. button.parent.destroy();
  21. try {
  22. // widget onClicked handler should not have been called
  23. MyAssert(!widgetClicked);
  24. // just the view should be alive
  25. MyAssert(Atomic.UI.debugGetWrappedWidgetCount() == 1);
  26. MyAssert(Atomic.UI.debugGetUIKeepAliveCount() == Atomic.UI.debugGetWrappedWidgetCount());
  27. print("success");
  28. } catch (e) {
  29. print (e);
  30. }
  31. // returning true signals the event was handled and stops event bubble
  32. // so parent widget should not get event, which is important as it is destroyed here
  33. return true;
  34. }
  35. }
  36. function update(timeStep) {
  37. deltaTime += timeStep;
  38. if (deltaTime > .5) {
  39. deltaTime = 0;
  40. }
  41. }