Commit 2adff537 authored by wjf's avatar wjf

l

parent d7737d04
import {SCALE_MODES, TEXT_ALIGN, TEXT_lINETYPE, VERTICAL_ALIGN} from "../const"; import { SCALE_MODES, TEXT_ALIGN, TEXT_lINETYPE, VERTICAL_ALIGN } from "../const";
import Texture from "../texture/Texture"; import Texture from "../texture/Texture";
import {getRGBA} from "../utils"; import { getRGBA } from "../utils";
import {Rectangle} from "../math"; import { Rectangle } from "../math";
import Sprite from "../display/Sprite"; import Sprite from "../display/Sprite";
import { Event } from "../../../types/2d/events/Event";
//文本canvas上xy的偏移量 //文本canvas上xy的偏移量
const padding = 10; const padding = 10;
...@@ -111,26 +112,26 @@ export class TextField extends Sprite { ...@@ -111,26 +112,26 @@ export class TextField extends Sprite {
* @type {number} * @type {number}
* @default 0 * @default 0
*/ */
public set textWidth(value: number) { // public set textWidth(value: number) {
if (this._textWidth != value) { // if (this._textWidth != value) {
this._textWidth = value; // this._textWidth = value;
this.dirty = true; // this.dirty = true;
} // }
; // ;
} // }
public get textWidth(): number { // public get textWidth(): number {
if (this._textWidth) { // if (this._textWidth) {
//有就这个 // //有就这个
return this._textWidth // return this._textWidth
} else { // } else {
//没有就计算出的给width,还是 // //没有就计算出的给width,还是
this.updateText(); // this.updateText();
return this.width - padding * 2; // return this.width - padding * 2;
} // }
} // }
private _textWidth: number = 0; // private _textWidth: number = 0;
/** /**
* 文本的行高,设置过能进行垂直适配, * 文本的行高,设置过能进行垂直适配,
...@@ -141,26 +142,41 @@ export class TextField extends Sprite { ...@@ -141,26 +142,41 @@ export class TextField extends Sprite {
* @type {number} * @type {number}
* @default 0 * @default 0
*/ */
public set textHeight(value: number) { // public set textHeight(value: number) {
if (this._textHeight != value) { // if (this._textHeight != value) {
this._textHeight = value; // this._textHeight = value;
// this.dirty = true;
// }
// }
// public get textHeight(): number {
// if (this._textHeight) {
// //有就这个
// return this._textHeight
// } else {
// //没有就计算出的给height,还是
// this.updateText();
// return this.height - padding * 2
// }
// }
// private _textHeight: number = 0;
set width(value: number) {
if (this._width !== value) {
this.dispatchEvent(Event.RESIZE);
this._width = value;
this.dirty = true; this.dirty = true;
} }
} }
set height(value: number) {
public get textHeight(): number { if (this._height !== value) {
if (this._textHeight) { this.dispatchEvent(Event.RESIZE);
//有就这个 this._height = value;
return this._textHeight this.dirty = true;
} else {
//没有就计算出的给height,还是
this.updateText();
return this.height - padding * 2
} }
} }
private _textHeight: number = 0;
/** /**
* 行间距 * 行间距
* @property lineSpacing * @property lineSpacing
...@@ -483,7 +499,7 @@ export class TextField extends Sprite { ...@@ -483,7 +499,7 @@ export class TextField extends Sprite {
s.canvas.width = 0; s.canvas.width = 0;
s.canvas.height = 0; s.canvas.height = 0;
s._localBoundsSelf.clear(); s._localBoundsSelf.clear();
this.anchorTexture = {x: 0, y: 0}; this.anchorTexture = { x: 0, y: 0 };
this.updateTexture(); this.updateTexture();
return return
} }
...@@ -497,7 +513,7 @@ export class TextField extends Sprite { ...@@ -497,7 +513,7 @@ export class TextField extends Sprite {
s.realLines = realLines; s.realLines = realLines;
s._prepContext(ctx); s._prepContext(ctx);
let textWidth = s._textWidth; let textWidth = s._width;
// let lineH = s._lineSpacing + s.size; // let lineH = s._lineSpacing + s.size;
//单行文本时 //单行文本时
if (s._text.indexOf("\n") < 0 && s.lineType == TEXT_lINETYPE.SINGLE) { if (s._text.indexOf("\n") < 0 && s.lineType == TEXT_lINETYPE.SINGLE) {
...@@ -555,7 +571,7 @@ export class TextField extends Sprite { ...@@ -555,7 +571,7 @@ export class TextField extends Sprite {
} }
// let maxH = lineH * realLines.length; // let maxH = lineH * realLines.length;
var trueHeight: number = s.size * realLines.length + s._lineSpacing * (realLines.length - 1); var trueHeight: number = s.size * realLines.length + s._lineSpacing * (realLines.length - 1);
let maxH = s._textHeight || trueHeight; let maxH = s._height || trueHeight;
let maxW = textWidth; let maxW = textWidth;
let tx = 0; let tx = 0;
if (s._textAlign == TEXT_ALIGN.CENTER) { if (s._textAlign == TEXT_ALIGN.CENTER) {
...@@ -578,12 +594,12 @@ export class TextField extends Sprite { ...@@ -578,12 +594,12 @@ export class TextField extends Sprite {
let lineH = s._lineSpacing + s.size; let lineH = s._lineSpacing + s.size;
//如果有_textHeight,就需要应用竖直对齐 //如果有_textHeight,就需要应用竖直对齐
var upY: number = 0; var upY: number = 0;
if (s._textHeight) { if (s._height) {
//跟trueHeight比较 //跟trueHeight比较
if (s._verticalAlign == VERTICAL_ALIGN.MIDDLE) { if (s._verticalAlign == VERTICAL_ALIGN.MIDDLE) {
upY = (s._textHeight - trueHeight) * 0.5; upY = (s._height - trueHeight) * 0.5;
} else if (s._verticalAlign == VERTICAL_ALIGN.DOWN) { } else if (s._verticalAlign == VERTICAL_ALIGN.DOWN) {
upY = s._textHeight - trueHeight; upY = s._height - trueHeight;
} }
} }
for (let i = 0; i < realLines.length; i++) { for (let i = 0; i < realLines.length; i++) {
...@@ -598,7 +614,7 @@ export class TextField extends Sprite { ...@@ -598,7 +614,7 @@ export class TextField extends Sprite {
s.offsetX = -padding; s.offsetX = -padding;
s.offsetY = -padding; s.offsetY = -padding;
this.anchorTexture = {x: (padding + 0.5) / can.width, y: padding / can.height} this.anchorTexture = { x: (padding + 0.5) / can.width, y: padding / can.height }
// document.body.appendChild(can) // document.body.appendChild(can)
// s._bounds.height = maxH; // s._bounds.height = maxH;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment