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 {getRGBA} from "../utils";
import {Rectangle} from "../math";
import { getRGBA } from "../utils";
import { Rectangle } from "../math";
import Sprite from "../display/Sprite";
import { Event } from "../../../types/2d/events/Event";
//文本canvas上xy的偏移量
const padding = 10;
......@@ -111,26 +112,26 @@ export class TextField extends Sprite {
* @type {number}
* @default 0
*/
public set textWidth(value: number) {
if (this._textWidth != value) {
this._textWidth = value;
this.dirty = true;
}
;
}
public get textWidth(): number {
if (this._textWidth) {
//有就这个
return this._textWidth
} else {
//没有就计算出的给width,还是
this.updateText();
return this.width - padding * 2;
}
}
private _textWidth: number = 0;
// public set textWidth(value: number) {
// if (this._textWidth != value) {
// this._textWidth = value;
// this.dirty = true;
// }
// ;
// }
// public get textWidth(): number {
// if (this._textWidth) {
// //有就这个
// return this._textWidth
// } else {
// //没有就计算出的给width,还是
// this.updateText();
// return this.width - padding * 2;
// }
// }
// private _textWidth: number = 0;
/**
* 文本的行高,设置过能进行垂直适配,
......@@ -141,26 +142,41 @@ export class TextField extends Sprite {
* @type {number}
* @default 0
*/
public set textHeight(value: number) {
if (this._textHeight != value) {
this._textHeight = value;
// public set textHeight(value: number) {
// if (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;
}
}
public get textHeight(): number {
if (this._textHeight) {
//有就这个
return this._textHeight
} else {
//没有就计算出的给height,还是
this.updateText();
return this.height - padding * 2
set height(value: number) {
if (this._height !== value) {
this.dispatchEvent(Event.RESIZE);
this._height = value;
this.dirty = true;
}
}
private _textHeight: number = 0;
/**
* 行间距
* @property lineSpacing
......@@ -483,7 +499,7 @@ export class TextField extends Sprite {
s.canvas.width = 0;
s.canvas.height = 0;
s._localBoundsSelf.clear();
this.anchorTexture = {x: 0, y: 0};
this.anchorTexture = { x: 0, y: 0 };
this.updateTexture();
return
}
......@@ -497,7 +513,7 @@ export class TextField extends Sprite {
s.realLines = realLines;
s._prepContext(ctx);
let textWidth = s._textWidth;
let textWidth = s._width;
// let lineH = s._lineSpacing + s.size;
//单行文本时
if (s._text.indexOf("\n") < 0 && s.lineType == TEXT_lINETYPE.SINGLE) {
......@@ -555,7 +571,7 @@ export class TextField extends Sprite {
}
// let maxH = lineH * realLines.length;
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 tx = 0;
if (s._textAlign == TEXT_ALIGN.CENTER) {
......@@ -578,12 +594,12 @@ export class TextField extends Sprite {
let lineH = s._lineSpacing + s.size;
//如果有_textHeight,就需要应用竖直对齐
var upY: number = 0;
if (s._textHeight) {
if (s._height) {
//跟trueHeight比较
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) {
upY = s._textHeight - trueHeight;
upY = s._height - trueHeight;
}
}
for (let i = 0; i < realLines.length; i++) {
......@@ -598,7 +614,7 @@ export class TextField extends Sprite {
s.offsetX = -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)
// 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