|
@@ -9,7 +9,7 @@ module BABYLON.GUI {
|
|
|
|
|
|
private _lines: any[];
|
|
|
private _resizeToFit: boolean = false;
|
|
|
-
|
|
|
+ private _lineSpacing: number = 0;
|
|
|
/**
|
|
|
* An event triggered after the text is changed
|
|
|
* @type {BABYLON.Observable}
|
|
@@ -20,6 +20,10 @@ module BABYLON.GUI {
|
|
|
return this._resizeToFit;
|
|
|
}
|
|
|
|
|
|
+ public set lineSpacing(value: number) {
|
|
|
+ this._lineSpacing = value;
|
|
|
+ }
|
|
|
+
|
|
|
set resizeToFit(value: boolean) {
|
|
|
this._resizeToFit = value;
|
|
|
|
|
@@ -106,7 +110,7 @@ module BABYLON.GUI {
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- if(this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY){
|
|
|
+ if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
|
|
|
context.shadowColor = this.shadowColor;
|
|
|
context.shadowBlur = this.shadowBlur;
|
|
|
context.shadowOffsetX = this.shadowOffsetX;
|
|
@@ -133,41 +137,41 @@ module BABYLON.GUI {
|
|
|
var _lines = this.text.split("\n");
|
|
|
|
|
|
if (this._textWrapping && !this._resizeToFit) {
|
|
|
- for(var _line of _lines) {
|
|
|
+ for (var _line of _lines) {
|
|
|
this._lines.push(this._parseLineWithTextWrapping(_line, context));
|
|
|
}
|
|
|
} else {
|
|
|
- for(var _line of _lines) {
|
|
|
+ for (var _line of _lines) {
|
|
|
this._lines.push(this._parseLine(_line, context));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- protected _parseLine(line: string='', context: CanvasRenderingContext2D): object {
|
|
|
- return {text: line, width: context.measureText(line).width};
|
|
|
+ protected _parseLine(line: string = '', context: CanvasRenderingContext2D): object {
|
|
|
+ return { text: line, width: context.measureText(line).width };
|
|
|
}
|
|
|
|
|
|
- protected _parseLineWithTextWrapping(line: string='', context: CanvasRenderingContext2D): object {
|
|
|
- var words = line.split(' ');
|
|
|
- var width = this._currentMeasure.width;
|
|
|
- var lineWidth = 0;
|
|
|
-
|
|
|
- for(var n = 0; n < words.length; n++) {
|
|
|
- var testLine = n > 0 ? line + " " + words[n] : words[0];
|
|
|
- var metrics = context.measureText(testLine);
|
|
|
- var testWidth = metrics.width;
|
|
|
- if (testWidth > width && n > 0) {
|
|
|
- this._lines.push({text: line, width: lineWidth});
|
|
|
- line = words[n];
|
|
|
- lineWidth = context.measureText(line).width;
|
|
|
- }
|
|
|
- else {
|
|
|
- lineWidth = testWidth;
|
|
|
- line = testLine;
|
|
|
- }
|
|
|
- }
|
|
|
+ protected _parseLineWithTextWrapping(line: string = '', context: CanvasRenderingContext2D): object {
|
|
|
+ var words = line.split(' ');
|
|
|
+ var width = this._currentMeasure.width;
|
|
|
+ var lineWidth = 0;
|
|
|
+
|
|
|
+ for (var n = 0; n < words.length; n++) {
|
|
|
+ var testLine = n > 0 ? line + " " + words[n] : words[0];
|
|
|
+ var metrics = context.measureText(testLine);
|
|
|
+ var testWidth = metrics.width;
|
|
|
+ if (testWidth > width && n > 0) {
|
|
|
+ this._lines.push({ text: line, width: lineWidth });
|
|
|
+ line = words[n];
|
|
|
+ lineWidth = context.measureText(line).width;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ lineWidth = testWidth;
|
|
|
+ line = testLine;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- return {text: line, width: lineWidth};
|
|
|
+ return { text: line, width: lineWidth };
|
|
|
}
|
|
|
|
|
|
protected _renderLines(context: CanvasRenderingContext2D): void {
|
|
@@ -191,9 +195,15 @@ module BABYLON.GUI {
|
|
|
|
|
|
rootY += this._currentMeasure.top;
|
|
|
|
|
|
- var maxLineWidth: number = 0;
|
|
|
+ var maxLineWidth: number = 0;
|
|
|
+
|
|
|
+ for (let i = 0; i < this._lines.length; i++) {
|
|
|
+ const line = this._lines[i];
|
|
|
+
|
|
|
+ if (i !== 0 && this._lineSpacing > 0 ){
|
|
|
+ rootY += this._lineSpacing;
|
|
|
+ }
|
|
|
|
|
|
- for (var line of this._lines) {
|
|
|
this._drawText(line.text, line.width, rootY, context);
|
|
|
rootY += this._fontOffset.height;
|
|
|
|