InspectorWidget.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. import ScriptWidget = require("ui/ScriptWidget");
  8. class InspectorWidget extends ScriptWidget {
  9. constructor() {
  10. super();
  11. var fd = this.attrFontDesc = new Atomic.UIFontDescription();
  12. fd.id = "Vera";
  13. fd.size = 11;
  14. var nlp = new Atomic.UILayoutParams();
  15. nlp.width = 310;
  16. var layout = this.rootLayout = new Atomic.UILayout();
  17. layout.spacing = 4;
  18. layout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  19. layout.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
  20. layout.layoutParams = nlp;
  21. layout.axis = Atomic.UI_AXIS_Y;
  22. this.gravity = Atomic.UI_GRAVITY_ALL;
  23. this.addChild(layout);
  24. this.subscribeToEvent("WidgetEvent", (data) => this.handleWidgetEvent(data));
  25. }
  26. onApply() {
  27. console.log("Apply Pressed!");
  28. }
  29. createAttrName(name:string):Atomic.UITextField {
  30. var nameField = new Atomic.UITextField();
  31. nameField.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
  32. nameField.skinBg = "InspectorTextAttrName";
  33. nameField.text = name;
  34. nameField.fontDescription = this.attrFontDesc;
  35. return nameField;
  36. }
  37. createSection(parent:Atomic.UIWidget, text:string, expanded:number):Atomic.UILayout {
  38. var section = new Atomic.UISection();
  39. section.text = text;
  40. section.value = expanded;
  41. section.fontDescription = this.attrFontDesc;
  42. var layout = this.createVerticalAttrLayout();
  43. parent.addChild(section);
  44. section.contentRoot.addChild(layout);
  45. return layout;
  46. }
  47. createVerticalAttrLayout():Atomic.UILayout {
  48. var layout = new Atomic.UILayout(Atomic.UI_AXIS_Y);
  49. layout.spacing = 3;
  50. layout.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
  51. layout.layoutSize = Atomic.UI_LAYOUT_SIZE_AVAILABLE;
  52. return layout;
  53. }
  54. createApplyButton():Atomic.UIButton {
  55. var button = new Atomic.UIButton();
  56. button.fontDescription = this.attrFontDesc;
  57. button.gravity = Atomic.UI_GRAVITY_RIGHT;
  58. button.text = "Apply";
  59. button.onClick = function() {
  60. this.onApply();
  61. }.bind(this);
  62. return button;
  63. }
  64. createAttrCheckBox(name:string, parent:Atomic.UIWidget):Atomic.UICheckBox {
  65. var attrLayout = new Atomic.UILayout();
  66. attrLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  67. var _name = this.createAttrName(name);
  68. attrLayout.addChild(_name);
  69. var box = new Atomic.UICheckBox();
  70. box.skinBg = "TBGreyCheckBox";
  71. attrLayout.addChild(box);
  72. parent.addChild(attrLayout);
  73. return box;
  74. }
  75. createAttrEditField(name:string, parent:Atomic.UIWidget):Atomic.UIEditField {
  76. var attrLayout = new Atomic.UILayout();
  77. attrLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  78. var _name = this.createAttrName(name);
  79. attrLayout.addChild(_name);
  80. var edit = new Atomic.UIEditField();
  81. edit.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
  82. edit.skinBg = "TBAttrEditorField";
  83. edit.fontDescription = this.attrFontDesc;
  84. var lp = new Atomic.UILayoutParams();
  85. lp.width = 140;
  86. edit.layoutParams = lp;
  87. attrLayout.addChild(edit);
  88. parent.addChild(attrLayout);
  89. return edit;
  90. }
  91. handleWidgetEvent(ev: Atomic.UIWidgetEvent):boolean {
  92. return false;
  93. }
  94. rootLayout:Atomic.UILayout;
  95. attrFontDesc:Atomic.UIFontDescription;
  96. }
  97. export = InspectorWidget;