Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
renderingEngine
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王剑峰
renderingEngine
Commits
2adff537
Commit
2adff537
authored
Nov 07, 2019
by
wjf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
l
parent
d7737d04
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
44 deletions
+60
-44
TextField.ts
src/2d/text/TextField.ts
+60
-44
No files found.
src/2d/text/TextField.ts
View file @
2adff537
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
.
_
textW
idth
;
let
textWidth
=
s
.
_
w
idth
;
// 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
.
_
textH
eight
||
trueHeight
;
let
maxH
=
s
.
_
h
eight
||
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
.
_
textH
eight
)
{
if
(
s
.
_
h
eight
)
{
//跟trueHeight比较
if
(
s
.
_verticalAlign
==
VERTICAL_ALIGN
.
MIDDLE
)
{
upY
=
(
s
.
_
textH
eight
-
trueHeight
)
*
0.5
;
upY
=
(
s
.
_
h
eight
-
trueHeight
)
*
0.5
;
}
else
if
(
s
.
_verticalAlign
==
VERTICAL_ALIGN
.
DOWN
)
{
upY
=
s
.
_
textH
eight
-
trueHeight
;
upY
=
s
.
_
h
eight
-
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;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment