UI.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'atomic component';
  2. //define font description style
  3. var fd = new Atomic.UIFontDescription();
  4. fd.id = "Vera";
  5. fd.size = 22;
  6. function createButton(self, text, event, layout) {
  7. //create UIButton element
  8. var button = new Atomic.UIButton();
  9. //set its text and font description style
  10. button.text = text;
  11. button.fontDescription = fd;
  12. //laying on the right side
  13. button.gravity = Atomic.UI_GRAVITY.UI_GRAVITY_RIGHT;
  14. //this event will be called when buttons is clicked
  15. button.onClick = function() {
  16. self.sendEvent(event);
  17. };
  18. //add button
  19. layout.addChild(button);
  20. }
  21. //UI component
  22. exports.component = function(self) {
  23. // create a root view
  24. self.uiView = new Atomic.UIView();
  25. // Create a layout, otherwise child widgets won't know how to size themselves
  26. // and would manually need to be sized
  27. var layout = new Atomic.UILayout();
  28. layout.rect = self.uiView.rect;
  29. layout.axis = Atomic.UI_AXIS.UI_AXIS_Y;
  30. layout.layoutPosition = Atomic.UI_LAYOUT_POSITION.UI_LAYOUT_POSITION_GRAVITY;
  31. //add layout to the root view
  32. self.uiView.addChild(layout);
  33. createButton(self, "Play Idle", "PlayIdle", layout);
  34. createButton(self, "Play Walk", "PlayWalk", layout);
  35. createButton(self, "Play Run", "PlayRun", layout);
  36. createButton(self, "Play Attack", "PlayAttack", layout);
  37. };