ArrayEditWidget.ts 1.9 KB

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