ArrayEditWidget.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import InspectorUtils = require("./InspectorUtils");
  2. class ArrayEditWidget extends Atomic.UILayout {
  3. constructor(title:string) {
  4. super();
  5. var nlp = new Atomic.UILayoutParams();
  6. nlp.width = 310;
  7. this.spacing = 4;
  8. this.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  9. this.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
  10. this.layoutParams = nlp;
  11. this.axis = Atomic.UI_AXIS_Y;
  12. this.gravity = Atomic.UI_GRAVITY_ALL;
  13. var countEdit = InspectorUtils.createAttrEditField(title, this);
  14. InspectorUtils.createSeparator(this);
  15. this.countEditField = <Atomic.UIEditField> countEdit.getWidget("editfield");
  16. this.subscribeToEvent(this.countEditField, "WidgetEvent", (data) => this.handleCountWidgetEvent(data));
  17. this.subscribeToEvent(this.countEditField, "WidgetFocusChanged", (data) => this.handleCountWidgetFocusChanged(data));
  18. }
  19. handleCountWidgetFocusChanged(ev) {
  20. if (ev.focused) {
  21. this.countRestore = this.countEditField.text;
  22. } else {
  23. this.countEditField.text = this.countRestore;
  24. }
  25. }
  26. handleCountWidgetEvent(ev: Atomic.UIWidgetEvent) {
  27. if (ev.type == Atomic.UI_EVENT_TYPE_KEY_UP) {
  28. if (ev.key == Atomic.KEY_RETURN) {
  29. if (this.countRestore != this.countEditField.text) {
  30. this.countRestore = this.countEditField.text;
  31. if (this.onCountChanged) {
  32. this.onCountChanged(Number(this.countRestore));
  33. }
  34. }
  35. }
  36. }
  37. if (ev.type == Atomic.UI_EVENT_TYPE_CHANGED) {
  38. }
  39. }
  40. onCountChanged: (count:number) => void;
  41. countRestore: string;
  42. countEditField: Atomic.UIEditField;
  43. }
  44. export = ArrayEditWidget;