InspectorUtils.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. class InspectorUtils {
  23. private static Ctor = (() => {
  24. var fd = InspectorUtils.attrFontDesc = new Atomic.UIFontDescription();
  25. fd.id = "Vera";
  26. fd.size = 11;
  27. })();
  28. static createSeparator(parent:Atomic.UIWidget):Atomic.UISeparator {
  29. var sep = new Atomic.UISeparator();
  30. sep.gravity = Atomic.UI_GRAVITY.UI_GRAVITY_LEFT_RIGHT;
  31. sep.skinBg = "AESeparator";
  32. parent.addChild(sep);
  33. return sep;
  34. }
  35. static createContainer():Atomic.UIContainer {
  36. var container = new Atomic.UIContainer();
  37. container.skinBg = "AEContainer";
  38. return container;
  39. }
  40. static createAttrName(name:string):Atomic.UITextField {
  41. var nameField = new Atomic.UITextField();
  42. nameField.textAlign = Atomic.UI_TEXT_ALIGN.UI_TEXT_ALIGN_LEFT;
  43. nameField.skinBg = "InspectorTextAttrName";
  44. nameField.text = name;
  45. nameField.fontDescription = InspectorUtils.attrFontDesc;
  46. // atttribute name layout param
  47. var atlp = new Atomic.UILayoutParams();
  48. atlp.width = 120;
  49. nameField.layoutParams = atlp;
  50. return nameField;
  51. }
  52. static createEditField():Atomic.UIEditField {
  53. var edit = new Atomic.UIEditField();
  54. edit.id = "editfield";
  55. edit.textAlign = Atomic.UI_TEXT_ALIGN.UI_TEXT_ALIGN_LEFT;
  56. edit.skinBg = "TBAttrEditorField";
  57. edit.fontDescription = InspectorUtils.attrFontDesc;
  58. var lp = new Atomic.UILayoutParams();
  59. lp.width = 160;
  60. lp.height = 24;
  61. edit.layoutParams = lp;
  62. return edit;
  63. }
  64. static createColorWidget():Atomic.UIColorWidget {
  65. var colorWidget = new Atomic.UIColorWidget();
  66. colorWidget.id = "colorfield";
  67. var lp = new Atomic.UILayoutParams();
  68. lp.width = 160;
  69. lp.height = 24;
  70. colorWidget.layoutParams = lp;
  71. return colorWidget;
  72. }
  73. static createAttrEditField(name:string, parent:Atomic.UIWidget):Atomic.UIEditField {
  74. var attrLayout = new Atomic.UILayout();
  75. attrLayout.layoutSize = Atomic.UI_LAYOUT_SIZE.UI_LAYOUT_SIZE_AVAILABLE;
  76. attrLayout.gravity = Atomic.UI_GRAVITY.UI_GRAVITY_LEFT_RIGHT;
  77. attrLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  78. var _name = InspectorUtils.createAttrName(name);
  79. attrLayout.addChild(_name);
  80. var edit = InspectorUtils.createEditField();
  81. attrLayout.addChild(edit);
  82. parent.addChild(attrLayout);
  83. return edit;
  84. }
  85. static createAttrCheckBox(name:string, parent:Atomic.UIWidget):{ textField:Atomic.UITextField, checkBox: Atomic.UICheckBox} {
  86. var attrLayout = new Atomic.UILayout();
  87. attrLayout.layoutSize = Atomic.UI_LAYOUT_SIZE.UI_LAYOUT_SIZE_AVAILABLE;
  88. attrLayout.gravity = Atomic.UI_GRAVITY.UI_GRAVITY_LEFT_RIGHT;
  89. attrLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  90. var _name = InspectorUtils.createAttrName(name);
  91. attrLayout.addChild(_name);
  92. var checkBox = new Atomic.UICheckBox();
  93. attrLayout.addChild(checkBox);
  94. parent.addChild(attrLayout);
  95. return {textField: _name, checkBox : checkBox};
  96. }
  97. static createAttrEditFieldWithSelectButton(name:string, parent:Atomic.UIWidget):{editField:Atomic.UIEditField, selectButton:Atomic.UIButton} {
  98. var attrLayout = new Atomic.UILayout();
  99. attrLayout.layoutDistributionPosition = Atomic.UI_LAYOUT_DISTRIBUTION_POSITION.UI_LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP;
  100. if (name) {
  101. var _name = InspectorUtils.createAttrName(name);
  102. attrLayout.addChild(_name);
  103. }
  104. var fieldLayout = new Atomic.UILayout();
  105. fieldLayout.layoutDistributionPosition = Atomic.UI_LAYOUT_DISTRIBUTION_POSITION.UI_LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP;
  106. var edit = InspectorUtils.createEditField();
  107. var selectButton = new Atomic.UIButton();
  108. selectButton.text = "...";
  109. selectButton.fontDescription = InspectorUtils.attrFontDesc;
  110. fieldLayout.addChild(edit);
  111. fieldLayout.addChild(selectButton);
  112. attrLayout.addChild(fieldLayout);
  113. parent.addChild(attrLayout);
  114. return {editField:edit, selectButton:selectButton};
  115. }
  116. static createAttrColorFieldWithSelectButton(name:string, parent:Atomic.UIWidget):{colorWidget:Atomic.UIColorWidget, selectButton:Atomic.UIButton} {
  117. var attrLayout = new Atomic.UILayout();
  118. attrLayout.layoutDistributionPosition = Atomic.UI_LAYOUT_DISTRIBUTION_POSITION.UI_LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP;
  119. if (name) {
  120. var _name = InspectorUtils.createAttrName(name);
  121. attrLayout.addChild(_name);
  122. }
  123. var fieldLayout = new Atomic.UILayout();
  124. fieldLayout.layoutDistributionPosition = Atomic.UI_LAYOUT_DISTRIBUTION_POSITION.UI_LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP;
  125. var colorWidget = InspectorUtils.createColorWidget();
  126. var selectButton = new Atomic.UIButton();
  127. selectButton.text = "...";
  128. selectButton.fontDescription = InspectorUtils.attrFontDesc;
  129. fieldLayout.addChild(colorWidget);
  130. fieldLayout.addChild(selectButton);
  131. attrLayout.addChild(fieldLayout);
  132. parent.addChild(attrLayout);
  133. return {colorWidget:colorWidget, selectButton:selectButton};
  134. }
  135. // "static constructor"
  136. static attrFontDesc:Atomic.UIFontDescription;
  137. }
  138. export = InspectorUtils;