stackPanel.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. module BABYLON.GUI {
  3. export class StackPanel extends Container {
  4. private _isVertical = true;
  5. private _tempMeasureStore = Measure.Empty();
  6. public get isVertical(): boolean {
  7. return this._isVertical;
  8. }
  9. public set isVertical(value: boolean) {
  10. if (this._isVertical === value) {
  11. return;
  12. }
  13. this._isVertical = value;
  14. this._markAsDirty();
  15. }
  16. constructor(public name?: string) {
  17. super(name);
  18. }
  19. protected _getTypeName(): string {
  20. return "StackPanel";
  21. }
  22. protected _preMeasure(parentMeasure: Measure, context: CanvasRenderingContext2D): void {
  23. var stack = 0;
  24. for (var child of this._children) {
  25. this._tempMeasureStore.copyFrom(child._currentMeasure);
  26. child._currentMeasure.copyFrom(parentMeasure);
  27. child._measure();
  28. if (this._isVertical) {
  29. child.top = stack + "px";
  30. if (!child._top.ignoreAdaptiveScaling) {
  31. child._markAsDirty();
  32. }
  33. child._top.ignoreAdaptiveScaling = true;
  34. stack += child._currentMeasure.height;
  35. child.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  36. } else {
  37. child.left = stack + "px";
  38. if (!child._left.ignoreAdaptiveScaling) {
  39. child._markAsDirty();
  40. }
  41. child._left.ignoreAdaptiveScaling = true;
  42. stack += child._currentMeasure.width;
  43. child.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  44. }
  45. child._currentMeasure.copyFrom(this._tempMeasureStore);
  46. }
  47. let panelChanged = false;
  48. if (this._isVertical) {
  49. let previousHeight = this.height;
  50. this.height = stack + "px";
  51. panelChanged = previousHeight !== this.height || !this._height.ignoreAdaptiveScaling;
  52. this._height.ignoreAdaptiveScaling = true;
  53. } else {
  54. let previousWidth = this.width;
  55. this.width = stack + "px";
  56. panelChanged = previousWidth !== this.width || !this._width.ignoreAdaptiveScaling;
  57. this._width.ignoreAdaptiveScaling = true;
  58. }
  59. if (panelChanged) {
  60. this._markAllAsDirty();
  61. }
  62. super._preMeasure(parentMeasure, context);
  63. }
  64. }
  65. }