stackPanel.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. module BABYLON.GUI {
  3. export class StackPanel extends Container {
  4. private _isVertical = true;
  5. public get isVertical(): boolean {
  6. return this._isVertical;
  7. }
  8. public set isVertical(value: boolean) {
  9. if (this._isVertical === value) {
  10. return;
  11. }
  12. this._isVertical = value;
  13. this._markAsDirty();
  14. }
  15. constructor(public name: string) {
  16. super(name);
  17. }
  18. protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void {
  19. var stack = 0;
  20. for (var child of this._children) {
  21. child._currentMeasure.copyFrom(parentMeasure);
  22. child._measure();
  23. if (this._isVertical) {
  24. child.top = stack + "px";
  25. stack += child._currentMeasure.height;
  26. child.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  27. } else {
  28. child.left = stack + "px";
  29. stack += child._currentMeasure.width;
  30. child.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  31. }
  32. }
  33. if (this._isVertical) {
  34. this.height = stack + "px";
  35. } else {
  36. this.width = stack + "px";
  37. }
  38. super._additionalProcessing(parentMeasure, context);
  39. }
  40. }
  41. }