InspectorWidget.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. import ScriptWidget = require("ui/ScriptWidget");
  23. class InspectorWidget extends ScriptWidget {
  24. constructor() {
  25. super();
  26. var fd = this.attrFontDesc = new Atomic.UIFontDescription();
  27. fd.id = "Vera";
  28. fd.size = 11;
  29. var nlp = new Atomic.UILayoutParams();
  30. nlp.width = 310;
  31. var layout = this.rootLayout = new Atomic.UILayout();
  32. layout.spacing = 4;
  33. layout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  34. layout.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
  35. layout.layoutParams = nlp;
  36. layout.axis = Atomic.UI_AXIS_Y;
  37. this.gravity = Atomic.UI_GRAVITY_ALL;
  38. this.addChild(layout);
  39. this.subscribeToEvent("WidgetEvent", (data) => this.handleWidgetEvent(data));
  40. }
  41. onApply() {
  42. console.log("Apply Pressed!");
  43. }
  44. createAttrName(name:string):Atomic.UITextField {
  45. var nameField = new Atomic.UITextField();
  46. nameField.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
  47. nameField.skinBg = "InspectorTextAttrName";
  48. nameField.text = name;
  49. nameField.fontDescription = this.attrFontDesc;
  50. return nameField;
  51. }
  52. createSection(parent:Atomic.UIWidget, text:string, expanded:number):Atomic.UILayout {
  53. var section = new Atomic.UISection();
  54. section.text = text;
  55. section.value = expanded;
  56. section.fontDescription = this.attrFontDesc;
  57. var layout = this.createVerticalAttrLayout();
  58. parent.addChild(section);
  59. section.contentRoot.addChild(layout);
  60. return layout;
  61. }
  62. createVerticalAttrLayout():Atomic.UILayout {
  63. var layout = new Atomic.UILayout(Atomic.UI_AXIS_Y);
  64. layout.spacing = 3;
  65. layout.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
  66. layout.layoutSize = Atomic.UI_LAYOUT_SIZE_AVAILABLE;
  67. return layout;
  68. }
  69. createApplyButton():Atomic.UIButton {
  70. var button = new Atomic.UIButton();
  71. button.fontDescription = this.attrFontDesc;
  72. button.gravity = Atomic.UI_GRAVITY_RIGHT;
  73. button.text = "Apply";
  74. button.onClick = function() {
  75. this.onApply();
  76. }.bind(this);
  77. return button;
  78. }
  79. createAttrCheckBox(name:string, parent:Atomic.UIWidget):Atomic.UICheckBox {
  80. var attrLayout = new Atomic.UILayout();
  81. attrLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  82. var _name = this.createAttrName(name);
  83. attrLayout.addChild(_name);
  84. var box = new Atomic.UICheckBox();
  85. box.skinBg = "TBGreyCheckBox";
  86. attrLayout.addChild(box);
  87. parent.addChild(attrLayout);
  88. return box;
  89. }
  90. createAttrEditField(name:string, parent:Atomic.UIWidget):Atomic.UIEditField {
  91. var attrLayout = new Atomic.UILayout();
  92. attrLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  93. var _name = this.createAttrName(name);
  94. attrLayout.addChild(_name);
  95. var edit = new Atomic.UIEditField();
  96. edit.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
  97. edit.skinBg = "TBAttrEditorField";
  98. edit.fontDescription = this.attrFontDesc;
  99. var lp = new Atomic.UILayoutParams();
  100. lp.width = 140;
  101. edit.layoutParams = lp;
  102. attrLayout.addChild(edit);
  103. parent.addChild(attrLayout);
  104. return edit;
  105. }
  106. handleWidgetEvent(ev: Atomic.UIWidgetEvent):boolean {
  107. return false;
  108. }
  109. rootLayout:Atomic.UILayout;
  110. attrFontDesc:Atomic.UIFontDescription;
  111. }
  112. export = InspectorWidget;