ArrayEditWidget.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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, "WidgetEvent", (data) => this.handleCountWidgetEvent(data));
  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. handleCountWidgetEvent(ev: Atomic.UIWidgetEvent) {
  33. if (ev.type == Atomic.UI_EVENT_TYPE_KEY_UP) {
  34. if (ev.key == Atomic.KEY_RETURN) {
  35. if (this.countRestore != this.countEditField.text) {
  36. this.countRestore = this.countEditField.text;
  37. if (this.onCountChanged) {
  38. this.onCountChanged(Number(this.countRestore));
  39. }
  40. }
  41. }
  42. }
  43. if (ev.type == Atomic.UI_EVENT_TYPE_CHANGED) {
  44. }
  45. }
  46. countEdit:Atomic.UIEditField;
  47. onCountChanged: (count:number) => void;
  48. countRestore: string;
  49. countEditField: Atomic.UIEditField;
  50. }
  51. export = ArrayEditWidget;