Sfoglia il codice sorgente

fixed issue with padding and wrapping

Adam Bowman 8 anni fa
parent
commit
eb72a11860
1 ha cambiato i file con 12 aggiunte e 15 eliminazioni
  1. 12 15
      canvas2D/src/Engine/babylon.text2d.ts

+ 12 - 15
canvas2D/src/Engine/babylon.text2d.ts

@@ -531,7 +531,8 @@
                 let charWidths = [];
                 let charWidths = [];
                 let charsPerLine = [];
                 let charsPerLine = [];
                 let charCount = 0;
                 let charCount = 0;
-                let maxWidth = this.contentArea.width;
+                let contentAreaWidth = this.contentArea.width;
+                let contentAreaHeight = this.contentArea.height;
                 let numCharsCurrentWord = 0;
                 let numCharsCurrentWord = 0;
                 let widthCurrentWord = 0;
                 let widthCurrentWord = 0;
                 let numWordsPerLine = 0;
                 let numWordsPerLine = 0;
@@ -583,7 +584,7 @@
                         widthCurrentWord += ci.charWidth;
                         widthCurrentWord += ci.charWidth;
                     }
                     }
 
 
-                    if (this._wordWrap && numWordsPerLine > 0 && offset.x > maxWidth) {
+                    if (this._wordWrap && numWordsPerLine > 0 && offset.x > contentAreaWidth) {
 
 
                         lineLengths.push(offset.x - widthCurrentWord);
                         lineLengths.push(offset.x - widthCurrentWord);
                         charCount -= numCharsCurrentWord;
                         charCount -= numCharsCurrentWord;
@@ -595,12 +596,6 @@
                             j--;
                             j--;
                         }
                         }
 
 
-                        //skip white space at the beginning of next line
-                        while (this._isWhiteSpaceCharHoriz(text[i+1])) {
-                            i++;
-                            charCount++;
-                        }
-
                         charsPerLine.push(charCount);
                         charsPerLine.push(charCount);
                         charCount = numCharsCurrentWord;
                         charCount = numCharsCurrentWord;
                         offset.x = widthCurrentWord;
                         offset.x = widthCurrentWord;
@@ -628,21 +623,23 @@
                 }
                 }
 
 
                 let textHeight = lineLengths.length * lh;
                 let textHeight = lineLengths.length * lh;
-                let offsetX = 0;
-                offset.y += this.size.height + textHeight - lh;
-
+                let offsetX = this.padding.leftPixels;
+                
                 if (alignH == TextAlign.Right) {
                 if (alignH == TextAlign.Right) {
-                    offsetX = this.size.width - maxLineLen;
+                    offsetX += contentAreaWidth - maxLineLen;
                 } else if (alignH == TextAlign.Center) {
                 } else if (alignH == TextAlign.Center) {
-                    offsetX = (this.size.width - maxLineLen) * .5;
+                    offsetX += (contentAreaWidth - maxLineLen) * .5;
                 }
                 }
 
 
                 offset.x += offsetX;
                 offset.x += offsetX;
 
 
+                offset.y += contentAreaHeight + textHeight - lh;
+                offset.y += this.padding.bottomPixels;
+
                 if (alignV == TextAlign.Bottom) {
                 if (alignV == TextAlign.Bottom) {
-                    offset.y -= this.height;
+                    offset.y -= contentAreaHeight;
                 }else if (alignV == TextAlign.Center) {
                 }else if (alignV == TextAlign.Center) {
-                    offset.y -= (this.height - textHeight) * .5 + lineLengths.length * lh;
+                    offset.y -= (contentAreaHeight - textHeight) * .5 + lineLengths.length * lh;
                 }else {
                 }else {
                     offset.y -= lineLengths.length * lh;
                     offset.y -= lineLengths.length * lh;
                 }
                 }