Jelajahi Sumber

padding and setter fix

Royi Bernthal 7 tahun lalu
induk
melakukan
783f7a5c3a
1 mengubah file dengan 7 tambahan dan 32 penghapusan
  1. 7 32
      gui/src/controls/textBlock.ts

+ 7 - 32
gui/src/controls/textBlock.ts

@@ -18,8 +18,11 @@ module BABYLON.GUI {
 
         set resizeToFit(value: boolean) {
             this._resizeToFit = value;
-            this._width.ignoreAdaptiveScaling = true;
-            this._height.ignoreAdaptiveScaling = true;
+
+            if (this._resizeToFit) {
+                this._width.ignoreAdaptiveScaling = true;
+                this._height.ignoreAdaptiveScaling = true;
+            }
         }
 
         public get textWrapping(): boolean {
@@ -128,34 +131,6 @@ module BABYLON.GUI {
             }
         }
 
-        /*public getRawFontSize(): object {
-            var ignoreAdaptiveScaling: boolean = this._fontSize.ignoreAdaptiveScaling;
-
-            this._fontSize.ignoreAdaptiveScaling = false;
-            
-            var _lines = this.text.split("\n");
-            
-            var maxLineWidth: number = 0;
-
-            _lines.forEach(_line => {
-                //can't get context here? if so, have 2 calculations in _additionalProcessing instead? one with idealWidth and one without
-                var lineWidth: number = this._parseLine(_line, context).width;
-
-                if (lineWidth > maxLineWidth) maxLineWidth = lineWidth;
-            });
-
-            this._prepareFont();
-
-            this._fontSize.ignoreAdaptiveScaling = ignoreAdaptiveScaling;
-
-            this._prepareFont();
-
-            return {
-                width: maxLineWidth,
-                height: this._fontOffset.height * _lines.length + 'px'
-            }
-        }*/
-
         protected _parseLine(line: string='', context: CanvasRenderingContext2D): object {
           return {text: line, width: context.measureText(line).width};
         }
@@ -215,8 +190,8 @@ module BABYLON.GUI {
             }
 
             if (this._resizeToFit) {
-                this.width = maxLineWidth + 'px';
-                this.height = this._fontOffset.height * this._lines.length + 'px';
+                this.width = this.paddingLeftInPixels + this.paddingRightInPixels + maxLineWidth + 'px';
+                this.height = this.paddingTopInPixels + this.paddingBottomInPixels + this._fontOffset.height * this._lines.length + 'px';
             }
 
             console.log('width', this.width);