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
e3c51ee3
Commit
e3c51ee3
authored
Dec 05, 2019
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解决html文本的问题
parent
d364a706
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
39 deletions
+50
-39
TextField.ts
src/2d/text/TextField.ts
+12
-11
Label.ts
src/zeroing/game-warpper/nodes/Label.ts
+38
-28
No files found.
src/2d/text/TextField.ts
View file @
e3c51ee3
...
...
@@ -561,7 +561,7 @@ export class TextField extends Sprite {
}
else
{
//textWidth取每行最大值,如果没设置过textWidth
let
measureCache
=
{};
if
(
!
textWidth
)
{
const
shouldMeasureTextWidth
=
!
textWidth
;
for
(
let
i
=
0
,
l
=
hardLines
.
length
;
i
<
l
;
i
++
)
{
let
str
=
hardLines
[
i
];
if
(
!
str
)
continue
;
...
...
@@ -573,6 +573,7 @@ export class TextField extends Sprite {
}
lineWidth
+=
charWidth
;
}
if
(
shouldMeasureTextWidth
){
textWidth
=
Math
.
max
(
lineWidth
,
textWidth
);
}
}
...
...
src/zeroing/game-warpper/nodes/Label.ts
View file @
e3c51ee3
...
...
@@ -3,7 +3,7 @@
*/
import
{
TextField
}
from
"../../../2d/text"
;
import
{
dataCenter
}
from
"../data-center"
;
import
{
ESCAPE_REG_EXP
}
from
"../../utils"
;
import
{
ESCAPE_REG_EXP
,
htmlToPureText
}
from
"../../utils"
;
import
{
Event
}
from
"../../../2d/events"
;
/**
...
...
@@ -14,7 +14,6 @@ export class Label extends TextField {
private
_escapes
=
[];
private
_registeredEvents
=
[];
private
_htmlText
;
private
_el
;
/**
* 重载文本设置
...
...
@@ -26,6 +25,14 @@ export class Label extends TextField {
let
matchResult
=
value
.
match
(
ESCAPE_REG_EXP
);
if
(
matchResult
)
{
this
.
dealEscape
(
value
,
matchResult
,
this
.
onTextMutated
);
}
else
{
super
.
_setText
(
value
);
}
}
}
private
dealEscape
(
value
,
matchResult
,
onMutated
)
{
this
.
unregisterEvents
();
this
.
_originText
=
value
;
this
.
_escapes
.
splice
(
0
);
...
...
@@ -34,14 +41,10 @@ export class Label extends TextField {
let
args
=
escape
.
split
(
'|'
);
let
eventName
=
args
[
0
];
this
.
_escapes
.
push
(
escape
);
dataCenter
.
addEventListener
(
eventName
,
this
.
onData
Mutated
,
this
);
dataCenter
.
addEventListener
(
eventName
,
on
Mutated
,
this
);
this
.
_registeredEvents
.
push
(
eventName
);
}
this
.
onDataMutated
();
}
else
{
super
.
_setText
(
value
);
}
}
onMutated
();
}
get
htmlText
()
{
...
...
@@ -51,19 +54,17 @@ export class Label extends TextField {
/**
* 设置html文本
*/
set
htmlText
(
v
)
{
if
(
this
.
_htmlText
!=
v
)
{
this
.
_htmlText
=
v
;
set
htmlText
(
v
alue
)
{
if
(
this
.
_htmlText
!=
v
alue
)
{
this
.
_htmlText
=
v
alue
;
let
el
=
this
.
_el
;
if
(
!
el
){
el
=
this
.
_el
=
document
.
createElement
(
'div'
);
let
matchResult
=
value
.
match
(
ESCAPE_REG_EXP
);
if
(
matchResult
)
{
this
.
dealEscape
(
value
,
matchResult
,
this
.
onHtmlMutated
);
}
else
{
this
.
text
=
htmlToPureText
(
value
);
}
el
.
innerHTML
=
v
;
document
.
body
.
append
(
el
);
let
pureText
=
el
.
innerText
;
document
.
body
.
removeChild
(
el
);
this
.
text
=
pureText
;
}
}
...
...
@@ -72,16 +73,25 @@ export class Label extends TextField {
*/
private
unregisterEvents
()
{
for
(
let
item
of
this
.
_registeredEvents
)
{
dataCenter
.
removeEventListener
(
item
,
this
.
on
Data
Mutated
,
this
);
dataCenter
.
removeEventListener
(
item
,
this
.
on
Text
Mutated
,
this
);
}
this
.
_registeredEvents
.
splice
(
0
);
}
/**
* 当
数据
改变时
* 当
TEXT
改变时
* @param e
*/
private
on
DataMutated
(
e
=
null
)
{
private
on
TextMutated
=
(
e
=
null
)
=>
{
super
.
_setText
(
dataCenter
.
formatString
(
this
.
_originText
,
this
.
_escapes
));
}
/**
* 当HTML改变时
* @param e
*/
private
onHtmlMutated
=
(
e
=
null
)
=>
{
let
html
=
dataCenter
.
formatString
(
this
.
_originText
,
this
.
_escapes
);
this
.
text
=
htmlToPureText
(
html
);
}
}
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