diff --git a/src/core/text/Text.js b/src/core/text/Text.js index a62e10c..f876593 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -33,9 +33,8 @@ * @param {string} text - The string that you would like the text to display * @param {object|PIXI.TextStyle} [style] - The style parameters * @param {HTMLCanvasElement} [canvas] - The canvas element for drawing text - * @param {boolean} [trim] - Trim transparent borders */ - constructor(text, style, canvas, trim) + constructor(text, style, canvas) { canvas = canvas || document.createElement('canvas'); @@ -104,13 +103,6 @@ this.style = style; this.localStyleID = -1; - - /** - * Trim transparent borders - * - * @member {boolean} - */ - this.trim = trim; } /** @@ -334,7 +326,7 @@ */ updateTexture() { - if (this.trim) + if (this._style.trim) { const trimmed = this.getTrimmed(this.canvas); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index a62e10c..f876593 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -33,9 +33,8 @@ * @param {string} text - The string that you would like the text to display * @param {object|PIXI.TextStyle} [style] - The style parameters * @param {HTMLCanvasElement} [canvas] - The canvas element for drawing text - * @param {boolean} [trim] - Trim transparent borders */ - constructor(text, style, canvas, trim) + constructor(text, style, canvas) { canvas = canvas || document.createElement('canvas'); @@ -104,13 +103,6 @@ this.style = style; this.localStyleID = -1; - - /** - * Trim transparent borders - * - * @member {boolean} - */ - this.trim = trim; } /** @@ -334,7 +326,7 @@ */ updateTexture() { - if (this.trim) + if (this._style.trim) { const trimmed = this.getTrimmed(this.canvas); diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 3b25528..3058c70 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -27,6 +27,7 @@ stroke: 'black', strokeThickness: 0, textBaseline: 'alphabetic', + trim: false, wordWrap: false, wordWrapWidth: 100, }; @@ -76,6 +77,7 @@ * e.g 'blue', '#FCFF00' * @param {number} [style.strokeThickness=0] - A number that represents the thickness of the stroke. * Default is 0 (no stroke) + * @param {boolean} [style.trim=false] - Trim transparent borders * @param {string} [style.textBaseline='alphabetic'] - The baseline of the text that is rendered. * @param {boolean} [style.wordWrap=false] - Indicates if word wrap should be used * @param {number} [style.wordWrapWidth=100] - The width at which text will wrap, it needs wordWrap to be set to true @@ -402,6 +404,19 @@ } } + get trim() + { + return this._trim; + } + set trim(trim) + { + if (this._trim !== trim) + { + this._trim = trim; + this.styleID++; + } + } + get wordWrap() { return this._wordWrap;