InspectorUtils.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. class InspectorUtils {
  8. private static Ctor = (() => {
  9. var fd = InspectorUtils.attrFontDesc = new Atomic.UIFontDescription();
  10. fd.id = "Vera";
  11. fd.size = 11;
  12. })();
  13. static createSeparator(parent:Atomic.UIWidget):Atomic.UISeparator {
  14. var sep = new Atomic.UISeparator();
  15. sep.gravity = Atomic.UI_GRAVITY_LEFT_RIGHT;
  16. sep.skinBg = "AESeparator";
  17. parent.addChild(sep);
  18. return sep;
  19. }
  20. static createContainer():Atomic.UIContainer {
  21. var container = new Atomic.UIContainer();
  22. container.skinBg = "AEContainer";
  23. return container;
  24. }
  25. static createAttrName(name:string):Atomic.UITextField {
  26. var nameField = new Atomic.UITextField();
  27. nameField.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
  28. nameField.skinBg = "InspectorTextAttrName";
  29. nameField.text = name;
  30. nameField.fontDescription = InspectorUtils.attrFontDesc;
  31. // atttribute name layout param
  32. var atlp = new Atomic.UILayoutParams();
  33. atlp.width = 100;
  34. nameField.layoutParams = atlp;
  35. return nameField;
  36. }
  37. static createEditField():Atomic.UIEditField {
  38. var edit = new Atomic.UIEditField();
  39. edit.id = "editfield";
  40. edit.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
  41. edit.skinBg = "TBAttrEditorField";
  42. edit.fontDescription = InspectorUtils.attrFontDesc;
  43. var lp = new Atomic.UILayoutParams();
  44. lp.width = 140;
  45. edit.layoutParams = lp;
  46. return edit;
  47. }
  48. static createAttrEditField(name:string, parent:Atomic.UIWidget):Atomic.UIEditField {
  49. var attrLayout = new Atomic.UILayout();
  50. attrLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  51. var _name = InspectorUtils.createAttrName(name);
  52. attrLayout.addChild(_name);
  53. var edit = InspectorUtils.createEditField();
  54. attrLayout.addChild(edit);
  55. parent.addChild(attrLayout);
  56. return edit;
  57. }
  58. static createAttrEditFieldWithSelectButton(name:string, parent:Atomic.UIWidget):{editField:Atomic.UIEditField, selectButton:Atomic.UIButton} {
  59. var attrLayout = new Atomic.UILayout();
  60. attrLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP;
  61. if (name) {
  62. var _name = InspectorUtils.createAttrName(name);
  63. attrLayout.addChild(_name);
  64. }
  65. var fieldLayout = new Atomic.UILayout();
  66. fieldLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP;
  67. var edit = InspectorUtils.createEditField();
  68. var selectButton = new Atomic.UIButton();
  69. selectButton.text = "...";
  70. selectButton.fontDescription = InspectorUtils.attrFontDesc;
  71. fieldLayout.addChild(edit);
  72. fieldLayout.addChild(selectButton);
  73. attrLayout.addChild(fieldLayout);
  74. parent.addChild(attrLayout);
  75. return {editField:edit, selectButton:selectButton};
  76. }
  77. // "static constructor"
  78. static attrFontDesc:Atomic.UIFontDescription;
  79. }
  80. export = InspectorUtils;