|
@@ -1,11 +1,11 @@
|
|
|
-import { Measure } from "../measure";
|
|
|
import { Rectangle } from "./rectangle";
|
|
|
import { Grid } from "./grid";
|
|
|
import { Control } from "./control";
|
|
|
import { Slider } from "./slider";
|
|
|
import { Container } from "./container";
|
|
|
import { PointerInfo, Observer, Nullable } from "babylonjs";
|
|
|
-import { AdvancedDynamicTexture } from "2D";
|
|
|
+import { AdvancedDynamicTexture, Measure } from "2D";
|
|
|
+import { _ScrollViewerWindow } from "./scrollViewerWindow";
|
|
|
|
|
|
/**
|
|
|
* Class used to hold a viewer window and sliders in a grid
|
|
@@ -14,20 +14,20 @@ export class ScrollViewer extends Rectangle {
|
|
|
private _grid: Grid;
|
|
|
private _horizontalBarSpace: Rectangle;
|
|
|
private _verticalBarSpace: Rectangle;
|
|
|
- private _dragSpace: Rectangle;
|
|
|
private _horizontalBar: Slider;
|
|
|
private _verticalBar: Slider;
|
|
|
- private _barColor: string = "grey";
|
|
|
- private _barBorderColor: string = "#444444";
|
|
|
- private _barBackground: string = "white";
|
|
|
- private _scrollGridWidth: number = 30;
|
|
|
- private _scrollGridHeight: number = 30;
|
|
|
+ private _barColor: string;
|
|
|
+ private _barBorderColor: string;
|
|
|
+ private _barBackground: string ;
|
|
|
+ private _barSize: number = 20;
|
|
|
private _endLeft: number;
|
|
|
private _endTop: number;
|
|
|
- private _window: Container;
|
|
|
+ private _window: _ScrollViewerWindow;
|
|
|
private _pointerIsOver: Boolean = false;
|
|
|
private _wheelPrecision: number = 0.05;
|
|
|
private _onPointerObserver: Nullable<Observer<PointerInfo>>;
|
|
|
+ private _clientWidth: number;
|
|
|
+ private _clientHeight: number;
|
|
|
|
|
|
/**
|
|
|
* Adds a new control to the current container
|
|
@@ -67,15 +67,12 @@ export class ScrollViewer extends Rectangle {
|
|
|
* Creates a new ScrollViewer
|
|
|
* @param name of ScrollViewer
|
|
|
*/
|
|
|
- constructor(
|
|
|
- /** name of ScrollViewer */
|
|
|
- public name?: string) {
|
|
|
+ constructor(name?: string) {
|
|
|
super(name);
|
|
|
|
|
|
this.onDirtyObservable.add(() => {
|
|
|
this._horizontalBarSpace.color = this.color;
|
|
|
this._verticalBarSpace.color = this.color;
|
|
|
- this._dragSpace.color = this.color;
|
|
|
});
|
|
|
|
|
|
this.onPointerEnterObservable.add(() => {
|
|
@@ -90,99 +87,97 @@ export class ScrollViewer extends Rectangle {
|
|
|
this._horizontalBar = new Slider();
|
|
|
this._verticalBar = new Slider();
|
|
|
|
|
|
- this._window = new Container();
|
|
|
+ this._window = new _ScrollViewerWindow();
|
|
|
this._window.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
|
|
|
this._window.verticalAlignment = Control.VERTICAL_ALIGNMENT_TOP;
|
|
|
|
|
|
- this._grid.addColumnDefinition(1, true);
|
|
|
- this._grid.addColumnDefinition(this._scrollGridWidth, true);
|
|
|
- this._grid.addRowDefinition(1, true);
|
|
|
- this._grid.addRowDefinition(this._scrollGridHeight, true);
|
|
|
+ this._grid.addColumnDefinition(1);
|
|
|
+ this._grid.addColumnDefinition(0, true);
|
|
|
+ this._grid.addRowDefinition(1);
|
|
|
+ this._grid.addRowDefinition(0, true);
|
|
|
|
|
|
super.addControl(this._grid);
|
|
|
this._grid.addControl(this._window, 0, 0);
|
|
|
|
|
|
this._verticalBar.paddingLeft = 0;
|
|
|
- this._verticalBar.width = "25px";
|
|
|
+ this._verticalBar.width = "100%";
|
|
|
+ this._verticalBar.height = "100%";
|
|
|
+ this._verticalBar.barOffset = 0;
|
|
|
this._verticalBar.value = 0;
|
|
|
- this._verticalBar.maximum = 100;
|
|
|
+ this._verticalBar.maximum = 1;
|
|
|
this._verticalBar.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;
|
|
|
this._verticalBar.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
|
|
|
- this._verticalBar.left = 0.05;
|
|
|
this._verticalBar.isThumbClamped = true;
|
|
|
- this._verticalBar.color = "grey";
|
|
|
- this._verticalBar.borderColor = "#444444";
|
|
|
- this._verticalBar.background = "white";
|
|
|
this._verticalBar.isVertical = true;
|
|
|
this._verticalBar.rotation = Math.PI;
|
|
|
+ this._verticalBar.displayValueBar = false;
|
|
|
+ this._verticalBar.isVisible = false;
|
|
|
|
|
|
this._verticalBarSpace = new Rectangle();
|
|
|
this._verticalBarSpace.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
|
|
|
this._verticalBarSpace.verticalAlignment = Control.VERTICAL_ALIGNMENT_TOP;
|
|
|
- this._verticalBarSpace.color = this.color;
|
|
|
this._verticalBarSpace.thickness = 1;
|
|
|
this._grid.addControl(this._verticalBarSpace, 0, 1);
|
|
|
this._verticalBarSpace.addControl(this._verticalBar);
|
|
|
|
|
|
this._verticalBar.onValueChangedObservable.add((value) => {
|
|
|
- this._window.top = value * this._endTop / 100 + "px";
|
|
|
+ this._window.top = value * this._endTop + "px";
|
|
|
});
|
|
|
|
|
|
this._horizontalBar.paddingLeft = 0;
|
|
|
- this._horizontalBar.height = "25px";
|
|
|
+ this._horizontalBar.width = "100%";
|
|
|
+ this._horizontalBar.height = "100%";
|
|
|
+ this._horizontalBar.barOffset = 0;
|
|
|
this._horizontalBar.value = 0;
|
|
|
- this._horizontalBar.maximum = 100;
|
|
|
+ this._horizontalBar.maximum = 1;
|
|
|
this._horizontalBar.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;
|
|
|
this._horizontalBar.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
|
|
|
- this._horizontalBar.left = 0.05;
|
|
|
this._horizontalBar.isThumbClamped = true;
|
|
|
- this._horizontalBar.color = "grey";
|
|
|
- this._horizontalBar.borderColor = "#444444";
|
|
|
- this._horizontalBar.background = "white";
|
|
|
+ this._horizontalBar.displayValueBar = false;
|
|
|
+ this._horizontalBar.isVisible = false;
|
|
|
|
|
|
this._horizontalBarSpace = new Rectangle();
|
|
|
this._horizontalBarSpace.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
|
|
|
this._horizontalBarSpace.verticalAlignment = Control.VERTICAL_ALIGNMENT_TOP;
|
|
|
- this._horizontalBarSpace.color = this.color;
|
|
|
this._horizontalBarSpace.thickness = 1;
|
|
|
this._grid.addControl(this._horizontalBarSpace, 1, 0);
|
|
|
this._horizontalBarSpace.addControl(this._horizontalBar);
|
|
|
|
|
|
this._horizontalBar.onValueChangedObservable.add((value) => {
|
|
|
- this._window.left = value * this._endLeft / 100 + "px";
|
|
|
+ this._window.left = value * this._endLeft + "px";
|
|
|
});
|
|
|
|
|
|
- this._dragSpace = new Rectangle();
|
|
|
- this._dragSpace.color = this.color;
|
|
|
- this._dragSpace.thickness = 2;
|
|
|
- this._dragSpace.background = this._barColor;
|
|
|
- this._grid.addControl(this._dragSpace, 1, 1);
|
|
|
+ // Colors
|
|
|
+ this.barColor = "grey";
|
|
|
+ this.barBackground = "transparent";
|
|
|
+ }
|
|
|
+
|
|
|
+ /** Reset the scroll viewer window to initial size */
|
|
|
+ public resetWindow() {
|
|
|
+ this._window.width = "100%";
|
|
|
+ this._window.height = "100%";
|
|
|
}
|
|
|
|
|
|
protected _getTypeName(): string {
|
|
|
return "ScrollViewer";
|
|
|
}
|
|
|
|
|
|
+ private _buildClientSizes() {
|
|
|
+ this._window.parentClientWidth = this._currentMeasure.width - (this._verticalBar.isVisible ? this._barSize : 0) - 2 * this.thickness;
|
|
|
+ this._window.parentClientHeight = this._currentMeasure.height - (this._horizontalBar.isVisible ? this._barSize : 0) - 2 * this.thickness;
|
|
|
+
|
|
|
+ this._clientWidth = this._window.parentClientWidth;
|
|
|
+ this._clientHeight = this._window.parentClientHeight;
|
|
|
+ }
|
|
|
+
|
|
|
protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void {
|
|
|
super._additionalProcessing(parentMeasure, context);
|
|
|
|
|
|
- this._measureForChildren.left = 0;
|
|
|
- this._measureForChildren.top = 0;
|
|
|
-
|
|
|
- this._measureForChildren.width = this.widthInPixels - 2 * this.thickness;
|
|
|
- this._measureForChildren.height = this.heightInPixels - 2 * this.thickness;
|
|
|
+ this._buildClientSizes();
|
|
|
}
|
|
|
-
|
|
|
- protected _processMeasures(parentMeasure: Measure, context: CanvasRenderingContext2D): void {
|
|
|
- super._processMeasures(parentMeasure, context);
|
|
|
-
|
|
|
- let innerWidth = this.widthInPixels - this._scrollGridWidth - 2 * this.thickness;
|
|
|
- let innerHeight = this.heightInPixels - this._scrollGridHeight - 2 * this.thickness;
|
|
|
- this._horizontalBar.width = (innerWidth * 0.8) + "px";
|
|
|
- this._verticalBar.height = (innerHeight * 0.8) + "px";
|
|
|
|
|
|
- this._grid.setColumnDefinition(0, innerWidth, true);
|
|
|
- this._grid.setRowDefinition(0, innerHeight, true);
|
|
|
+ protected _postMeasure(): void {
|
|
|
+ super._postMeasure();
|
|
|
|
|
|
this._updateScroller();
|
|
|
}
|
|
@@ -224,7 +219,27 @@ export class ScrollViewer extends Rectangle {
|
|
|
this._barColor = color;
|
|
|
this._horizontalBar.color = color;
|
|
|
this._verticalBar.color = color;
|
|
|
- this._dragSpace.background = color;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** Gets or sets the size of the bar */
|
|
|
+ public get barSize(): number {
|
|
|
+ return this._barSize;
|
|
|
+ }
|
|
|
+
|
|
|
+ public set barSize(value: number) {
|
|
|
+ if (this._barSize === value) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ this._barSize = value;
|
|
|
+ this._markAsDirty();
|
|
|
+
|
|
|
+ if (this._horizontalBar.isVisible) {
|
|
|
+ this._grid.setRowDefinition(1, this._barSize, true);
|
|
|
+ }
|
|
|
+ if (this._verticalBar.isVisible) {
|
|
|
+ this._grid.setColumnDefinition(1, this._barSize, true);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/** Gets or sets the bar color */
|
|
@@ -259,39 +274,36 @@ export class ScrollViewer extends Rectangle {
|
|
|
|
|
|
/** @hidden */
|
|
|
private _updateScroller(): void {
|
|
|
- let windowContentsWidth = this._window.widthInPixels;
|
|
|
- let windowContentsHeight = this._window.heightInPixels;
|
|
|
-
|
|
|
- let viewerWidth = this.widthInPixels;
|
|
|
- let viewerHeight = this.heightInPixels;
|
|
|
-
|
|
|
- let innerWidth = viewerWidth - this._scrollGridWidth - 2 * this.thickness;
|
|
|
- let innerHeight = viewerHeight - this._scrollGridHeight - 2 * this.thickness;
|
|
|
+ let windowContentsWidth = this._window._currentMeasure.width;
|
|
|
+ let windowContentsHeight = this._window._currentMeasure.height;
|
|
|
|
|
|
- if (windowContentsWidth <= innerWidth) {
|
|
|
- this._grid.setRowDefinition(0, viewerHeight - 2 * this.thickness , true);
|
|
|
+ if (this._horizontalBar.isVisible && windowContentsWidth <= this._clientWidth) {
|
|
|
this._grid.setRowDefinition(1, 0, true);
|
|
|
this._horizontalBar.isVisible = false;
|
|
|
+ this._horizontalBar.value = 0;
|
|
|
+ this._rebuildLayout = true;
|
|
|
}
|
|
|
- else {
|
|
|
- this._grid.setRowDefinition(0, innerHeight, true);
|
|
|
- this._grid.setRowDefinition(1, this._scrollGridHeight, true);
|
|
|
+ else if (!this._horizontalBar.isVisible && windowContentsWidth > this._clientWidth) {
|
|
|
+ this._grid.setRowDefinition(1, this._barSize, true);
|
|
|
this._horizontalBar.isVisible = true;
|
|
|
+ this._rebuildLayout = true;
|
|
|
}
|
|
|
|
|
|
- if (windowContentsHeight < innerHeight) {
|
|
|
- this._grid.setColumnDefinition(0, viewerWidth - 2 * this.thickness, true);
|
|
|
+ if (this._verticalBar.isVisible && windowContentsHeight <= this._clientHeight) {
|
|
|
this._grid.setColumnDefinition(1, 0, true);
|
|
|
this._verticalBar.isVisible = false;
|
|
|
+ this._verticalBar.value = 0;
|
|
|
+ this._rebuildLayout = true;
|
|
|
}
|
|
|
- else {
|
|
|
- this._grid.setColumnDefinition(0, innerWidth, true);
|
|
|
- this._grid.setColumnDefinition(1, this._scrollGridWidth, true);
|
|
|
+ else if (!this._verticalBar.isVisible && windowContentsHeight > this._clientHeight) {
|
|
|
+ this._grid.setColumnDefinition(1, this._barSize, true);
|
|
|
this._verticalBar.isVisible = true;
|
|
|
+ this._rebuildLayout = true;
|
|
|
}
|
|
|
|
|
|
- this._endLeft = innerWidth - windowContentsWidth;
|
|
|
- this._endTop = innerHeight - windowContentsHeight;
|
|
|
+ this._buildClientSizes();
|
|
|
+ this._endLeft = this._clientWidth - windowContentsWidth;
|
|
|
+ this._endTop = this._clientHeight - windowContentsHeight;
|
|
|
}
|
|
|
|
|
|
public _link(host: AdvancedDynamicTexture): void {
|
|
@@ -335,7 +347,7 @@ export class ScrollViewer extends Rectangle {
|
|
|
|
|
|
super._renderHighlightSpecific(context);
|
|
|
|
|
|
- this._window._renderHighlightSpecific(context);
|
|
|
+ this._grid._renderHighlightSpecific(context);
|
|
|
|
|
|
context.restore();
|
|
|
}
|