瀏覽代碼

Fix textblock line spacing bug

David Catuhe 6 年之前
父節點
當前提交
a68ed5c0f8
共有 4 個文件被更改,包括 29 次插入3 次删除
  1. 1 0
      dist/preview release/what's new.md
  2. 26 1
      gui/src/2D/controls/textBlock.ts
  3. 1 1
      src/Meshes/mesh.ts
  4. 1 1
      src/Misc/sceneSerializer.ts

+ 1 - 0
dist/preview release/what's new.md

@@ -97,6 +97,7 @@
 - Added a note on shallow bounding of getBoundingInfo ([tibotiber](https://github.com/tibotiber))
 
 ## Bug fixes
+- Fixed Textblock line spacing evaluation when linespacing > 0 ([Deltakosh](https://github.com/deltakosh/))
 - Fixed Xbox One gamepad controller button schemes ([MackeyK24](https://github.com/MackeyK24/))
 - Added support for `AnimationGroup` serialization ([Drigax](https://github.com/drigax/))
 - Removing assetContainer from scene will also remove gui layers ([TrevorDev](https://github.com/TrevorDev))

+ 26 - 1
gui/src/2D/controls/textBlock.ts

@@ -257,6 +257,17 @@ export class TextBlock extends Control {
             }
             let newHeight = this.paddingTopInPixels + this.paddingBottomInPixels + this._fontOffset.height * this._lines.length;
 
+            if (this._lines.length > 0 && this._lineSpacing.internalValue !== 0) {
+                let lineSpacing = 0;
+                if (this._lineSpacing.isPixel) {
+                    lineSpacing= this._lineSpacing.getValue(this._host);
+                } else {
+                    lineSpacing = (this._lineSpacing.getValue(this._host) * this._height.getValueInPixel(this._host, this._cachedParentMeasure.height));
+                }
+
+                newHeight += (this._lines.length - 1) * lineSpacing;
+            }
+
             if (newHeight !== this._height.internalValue) {
                 this._height.updateInPlace(newHeight, ValueAndUnit.UNITMODE_PIXEL);
                 this._rebuildLayout = true;
@@ -425,7 +436,21 @@ export class TextBlock extends Control {
                 }
                 const lines = this._lines ? this._lines : this._breakLines(
                     this.widthInPixels - this.paddingLeftInPixels - this.paddingRightInPixels, context);
-                return this.paddingTopInPixels + this.paddingBottomInPixels + this._fontOffset.height * lines.length;
+
+                let newHeight = this.paddingTopInPixels + this.paddingBottomInPixels + this._fontOffset.height * lines.length;
+
+                if (this._lines.length > 0 && this._lineSpacing.internalValue !== 0) {
+                    let lineSpacing = 0;
+                    if (this._lineSpacing.isPixel) {
+                        lineSpacing= this._lineSpacing.getValue(this._host);
+                    } else {
+                        lineSpacing = (this._lineSpacing.getValue(this._host) * this._height.getValueInPixel(this._host, this._cachedParentMeasure.height));
+                    }
+    
+                    newHeight += (lines.length - 1) * lineSpacing;
+                }
+
+                return newHeight;
             }
         }
         return 0;

+ 1 - 1
src/Meshes/mesh.ts

@@ -2847,7 +2847,7 @@ export class Mesh extends AbstractMesh implements IGetSetVerticesData {
         }
 
         // Material
-        if (this.material) {
+        if (this.material && !this.material.doNotSerialize) {
             serializationObject.materialId = this.material.id;
         } else {
             this.material = null;

+ 1 - 1
src/Misc/sceneSerializer.ts

@@ -46,7 +46,7 @@ var finalizeSingleMesh = (mesh: Mesh, serializationObject: any) => {
     //only works if the mesh is already loaded
     if (mesh.delayLoadState === Constants.DELAYLOADSTATE_LOADED || mesh.delayLoadState === Constants.DELAYLOADSTATE_NONE) {
         //serialize material
-        if (mesh.material && !mesh.doNotSerialize) {
+        if (mesh.material && !mesh.material.doNotSerialize) {
             if (mesh.material instanceof MultiMaterial) {
                 serializationObject.multiMaterials = serializationObject.multiMaterials || [];
                 serializationObject.materials = serializationObject.materials || [];