Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zeroing-engine
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
劳工
zeroing-engine
Commits
c83815d2
Commit
c83815d2
authored
May 19, 2020
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复显示对象未设置尺寸与设置0的问题
parent
9566ced2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
30 deletions
+72
-30
Container.ts
src/2d/display/Container.ts
+20
-10
Sprite.ts
src/2d/display/Sprite.ts
+28
-10
TextField.ts
src/2d/text/TextField.ts
+24
-10
No files found.
src/2d/display/Container.ts
View file @
c83815d2
...
@@ -706,7 +706,8 @@ export default class Container extends DisplayObject {
...
@@ -706,7 +706,8 @@ export default class Container extends DisplayObject {
* @member {number}
* @member {number}
*/
*/
get
width
():
number
{
get
width
():
number
{
return
this
.
_width
||
this
.
scale
.
x
*
this
.
getLocalBounds
().
width
;
let
value
=
this
.
_width
;
return
!
value
&&
value
!=
0
?
this
.
scale
.
x
*
this
.
getLocalBounds
().
width
:
value
;
}
}
set
width
(
value
:
number
)
{
set
width
(
value
:
number
)
{
...
@@ -718,10 +719,14 @@ export default class Container extends DisplayObject {
...
@@ -718,10 +719,14 @@ export default class Container extends DisplayObject {
// this.scale.x = 1;
// this.scale.x = 1;
// }
// }
if
(
this
.
_width
!==
value
)
{
if
(
this
.
_width
!==
value
)
{
//子类有用,有_width,才需设置scaleX
if
(
!
value
&&
value
!=
0
)
{
this
.
_width
=
value
;
this
.
_width
=
undefined
;
this
.
_localBoundsSelf
.
width
=
value
;
}
else
{
//if (this.stage) this.stage.layoutInvalid = true;
//子类有用,有_width,才需设置scaleX
this
.
_width
=
value
;
this
.
_localBoundsSelf
.
width
=
value
;
//if (this.stage) this.stage.layoutInvalid = true;
}
this
.
dispatchEvent
(
Event
.
RESIZE
);
this
.
dispatchEvent
(
Event
.
RESIZE
);
}
}
}
}
...
@@ -731,7 +736,8 @@ export default class Container extends DisplayObject {
...
@@ -731,7 +736,8 @@ export default class Container extends DisplayObject {
* @member {number}
* @member {number}
*/
*/
get
height
():
number
{
get
height
():
number
{
return
this
.
_height
||
this
.
scale
.
y
*
this
.
getLocalBounds
().
height
;
let
value
=
this
.
_height
;
return
!
value
&&
value
!=
0
?
this
.
scale
.
y
*
this
.
getLocalBounds
().
height
:
value
;
}
}
set
height
(
value
:
number
)
{
set
height
(
value
:
number
)
{
...
@@ -742,10 +748,14 @@ export default class Container extends DisplayObject {
...
@@ -742,10 +748,14 @@ export default class Container extends DisplayObject {
// } else {
// } else {
// this.scale.y = 1;
// this.scale.y = 1;
// }
// }
if
(
this
.
_height
!==
value
)
{
if
(
!
value
&&
value
!=
0
)
{
this
.
_height
=
value
;
this
.
_height
=
undefined
;
this
.
_localBoundsSelf
.
height
=
value
;
}
else
{
//if (this.stage) this.stage.layoutInvalid = true;
if
(
this
.
_height
!==
value
)
{
this
.
_height
=
value
;
this
.
_localBoundsSelf
.
height
=
value
;
//if (this.stage) this.stage.layoutInvalid = true;
}
this
.
dispatchEvent
(
Event
.
RESIZE
);
this
.
dispatchEvent
(
Event
.
RESIZE
);
}
}
}
}
...
...
src/2d/display/Sprite.ts
View file @
c83815d2
...
@@ -94,9 +94,9 @@ export default class Sprite extends Container {
...
@@ -94,9 +94,9 @@ export default class Sprite extends Container {
this
.
_texture
=
null
;
this
.
_texture
=
null
;
this
.
_width
=
0
;
//
this._width = 0;
this
.
_height
=
0
;
//
this._height = 0;
this
.
_tint
=
null
;
this
.
_tint
=
null
;
this
.
_tintRGB
=
null
;
this
.
_tintRGB
=
null
;
...
@@ -391,14 +391,22 @@ export default class Sprite extends Container {
...
@@ -391,14 +391,22 @@ export default class Sprite extends Container {
* @member {number}
* @member {number}
*/
*/
get
width
()
{
get
width
()
{
return
Math
.
abs
(
this
.
scale
.
x
)
*
this
.
_texture
.
orig
.
width
;
let
value
=
this
.
_width
;
return
!
value
&&
value
!=
0
?
Math
.
abs
(
this
.
scale
.
x
)
*
this
.
_texture
.
orig
.
width
:
value
;
}
}
set
width
(
value
)
{
set
width
(
value
)
{
const
s
=
sign
(
this
.
scale
.
x
)
||
1
;
if
(
this
.
_width
!==
value
)
{
if
(
!
value
&&
value
!=
0
)
{
this
.
scale
.
x
=
1
}
else
{
const
s
=
sign
(
this
.
scale
.
x
)
||
1
;
this
.
scale
.
x
=
s
*
value
/
this
.
_texture
.
orig
.
width
;
this
.
scale
.
x
=
s
*
value
/
this
.
_texture
.
orig
.
width
;
this
.
_width
=
value
;
}
this
.
_width
=
value
;
this
.
dispatchEvent
(
Event
.
RESIZE
);
}
}
}
/**
/**
...
@@ -406,13 +414,23 @@ export default class Sprite extends Container {
...
@@ -406,13 +414,23 @@ export default class Sprite extends Container {
* @member {number}
* @member {number}
*/
*/
get
height
()
{
get
height
()
{
return
Math
.
abs
(
this
.
scale
.
y
)
*
this
.
_texture
.
orig
.
height
;
let
value
=
this
.
_height
;
return
!
value
&&
value
!=
0
?
Math
.
abs
(
this
.
scale
.
y
)
*
this
.
_texture
.
orig
.
height
:
value
;
}
}
set
height
(
value
)
{
set
height
(
value
)
{
const
s
=
sign
(
this
.
scale
.
y
)
||
1
;
if
(
!
value
&&
value
!=
0
)
{
this
.
scale
.
y
=
s
*
value
/
this
.
_texture
.
orig
.
height
;
this
.
_height
=
undefined
;
this
.
_height
=
value
;
}
else
{
if
(
!
value
&&
value
!=
0
)
{
this
.
scale
.
y
=
1
}
else
{
const
s
=
sign
(
this
.
scale
.
y
)
||
1
;
this
.
scale
.
y
=
s
*
value
/
this
.
_texture
.
orig
.
height
;
}
this
.
_height
=
value
;
this
.
dispatchEvent
(
Event
.
RESIZE
);
}
}
}
/**
/**
...
...
src/2d/text/TextField.ts
View file @
c83815d2
...
@@ -169,28 +169,42 @@ export class TextField extends Sprite {
...
@@ -169,28 +169,42 @@ export class TextField extends Sprite {
// private _textHeight: number = 0;
// private _textHeight: number = 0;
get
width
():
number
{
get
width
():
number
{
if
(
this
.
_width
)
return
this
.
_width
;
if
(
!
this
.
_width
&&
this
.
_width
!=
0
)
{
this
.
updateText
();
this
.
updateText
();
return
this
.
scale
.
x
*
this
.
getLocalBounds
().
width
;
return
this
.
scale
.
x
*
this
.
getLocalBounds
().
width
;
}
else
{
return
this
.
_width
;
}
}
}
set
width
(
value
:
number
)
{
set
width
(
value
:
number
)
{
if
(
this
.
_width
!==
value
)
{
if
(
this
.
_width
!==
value
)
{
this
.
_width
=
value
;
if
(
!
value
&&
value
!=
0
)
{
this
.
_width
=
undefined
;
}
else
{
this
.
_width
=
value
;
}
this
.
dirty
=
true
;
this
.
dirty
=
true
;
this
.
dispatchEvent
(
Event
.
RESIZE
);
this
.
dispatchEvent
(
Event
.
RESIZE
);
}
}
}
}
get
height
():
number
{
get
height
():
number
{
if
(
this
.
_height
)
return
this
.
_height
;
if
(
!
this
.
_height
&&
this
.
_height
!=
0
)
{
this
.
updateText
();
this
.
updateText
();
return
this
.
scale
.
y
*
this
.
getLocalBounds
().
height
;
return
this
.
scale
.
y
*
this
.
getLocalBounds
().
height
;
}
else
{
return
this
.
_height
;
}
}
}
set
height
(
value
:
number
)
{
set
height
(
value
:
number
)
{
if
(
this
.
_height
!==
value
)
{
if
(
this
.
_height
!==
value
)
{
this
.
_height
=
value
;
if
(
!
value
&&
value
!=
0
)
{
this
.
_height
=
undefined
;
}
else
{
this
.
_height
=
value
;
}
this
.
dirty
=
true
;
this
.
dirty
=
true
;
this
.
dispatchEvent
(
Event
.
RESIZE
);
this
.
dispatchEvent
(
Event
.
RESIZE
);
}
}
...
@@ -691,7 +705,7 @@ export class TextField extends Sprite {
...
@@ -691,7 +705,7 @@ export class TextField extends Sprite {
s
.
realLines
=
realLines
;
s
.
realLines
=
realLines
;
s
.
_prepContext
(
ctx
);
s
.
_prepContext
(
ctx
);
let
textWidth
=
s
.
_width
;
let
textWidth
=
!
s
.
_width
&&
s
.
_width
!=
0
?
0
:
s
.
_width
;
// let lineH = s._lineSpacing + s.size;
// let lineH = s._lineSpacing + s.size;
//单行文本时
//单行文本时
if
(
isPureText
&&
text
.
indexOf
(
"
\n
"
)
<
0
&&
s
.
lineType
==
TEXT_lINETYPE
.
SINGLE
)
{
if
(
isPureText
&&
text
.
indexOf
(
"
\n
"
)
<
0
&&
s
.
lineType
==
TEXT_lINETYPE
.
SINGLE
)
{
...
@@ -719,7 +733,7 @@ export class TextField extends Sprite {
...
@@ -719,7 +733,7 @@ export class TextField extends Sprite {
}
}
}
else
{
}
else
{
//textWidth取每行最大值,如果没设置过textWidth
//textWidth取每行最大值,如果没设置过textWidth
const
shouldMeasureTextWidth
=
!
textWidth
;
const
shouldMeasureTextWidth
=
!
s
.
_width
&&
s
.
_width
!=
0
?
true
:
false
;
let
index
=
0
;
let
index
=
0
;
for
(
let
i
=
0
,
l
=
hardLines
.
length
;
i
<
l
;
i
++
)
{
for
(
let
i
=
0
,
l
=
hardLines
.
length
;
i
<
l
;
i
++
)
{
let
str
=
hardLines
[
i
];
let
str
=
hardLines
[
i
];
...
...
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