InspectorUtils.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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_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_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_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 createAttrEditField(name:string, parent:Atomic.UIWidget):Atomic.UIEditField {
  65. var attrLayout = new Atomic.UILayout();
  66. attrLayout.layoutSize = Atomic.UI_LAYOUT_SIZE_AVAILABLE;
  67. attrLayout.gravity = Atomic.UI_GRAVITY_LEFT_RIGHT;
  68. attrLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  69. var _name = InspectorUtils.createAttrName(name);
  70. attrLayout.addChild(_name);
  71. var edit = InspectorUtils.createEditField();
  72. attrLayout.addChild(edit);
  73. parent.addChild(attrLayout);
  74. return edit;
  75. }
  76. static createAttrCheckBox(name:string, parent:Atomic.UIWidget):{ textField:Atomic.UITextField, checkBox: Atomic.UICheckBox} {
  77. var attrLayout = new Atomic.UILayout();
  78. attrLayout.layoutSize = Atomic.UI_LAYOUT_SIZE_AVAILABLE;
  79. attrLayout.gravity = Atomic.UI_GRAVITY_LEFT_RIGHT;
  80. attrLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  81. var _name = InspectorUtils.createAttrName(name);
  82. attrLayout.addChild(_name);
  83. var checkBox = new Atomic.UICheckBox();
  84. attrLayout.addChild(checkBox);
  85. parent.addChild(attrLayout);
  86. return {textField: _name, checkBox : checkBox};
  87. }
  88. static createAttrEditFieldWithSelectButton(name:string, parent:Atomic.UIWidget):{editField:Atomic.UIEditField, selectButton:Atomic.UIButton} {
  89. var attrLayout = new Atomic.UILayout();
  90. attrLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP;
  91. if (name) {
  92. var _name = InspectorUtils.createAttrName(name);
  93. attrLayout.addChild(_name);
  94. }
  95. var fieldLayout = new Atomic.UILayout();
  96. fieldLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP;
  97. var edit = InspectorUtils.createEditField();
  98. var selectButton = new Atomic.UIButton();
  99. selectButton.text = "...";
  100. selectButton.fontDescription = InspectorUtils.attrFontDesc;
  101. fieldLayout.addChild(edit);
  102. fieldLayout.addChild(selectButton);
  103. attrLayout.addChild(fieldLayout);
  104. parent.addChild(attrLayout);
  105. return {editField:edit, selectButton:selectButton};
  106. }
  107. // "static constructor"
  108. static attrFontDesc:Atomic.UIFontDescription;
  109. }
  110. export = InspectorUtils;