InspectorWidget.ts 3.4 KB

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