Skip to content

Commit d0eab78

Browse files
committed
refactor(isOverflow)
1 parent 53a6b8c commit d0eab78

File tree

3 files changed

+13
-27
lines changed

3 files changed

+13
-27
lines changed

packages/display-module/data/src/TextData.ts

+5-14
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ export class TextData extends UIData implements ITextData {
3535
}
3636

3737
setBoxStyle(value: IUI) {
38-
const t = this.__leaf as IText
39-
let box = t.__box
38+
let t = this.__leaf as IText, box = t.__box
4039

4140
if (value) {
4241

@@ -45,24 +44,16 @@ export class TextData extends UIData implements ITextData {
4544
else box = t.__box = UICreator.get('Rect', 0 as any) as IUI // 传递 0 可以优化内存占用
4645

4746
const layout = t.__layout, boxLayout = box.__layout
48-
if (!boxStyle) {
49-
box.parent = t as any
50-
box.__world = t.__world
51-
boxLayout.boxBounds = layout.boxBounds
52-
}
47+
if (!boxStyle) box.parent = t as any, box.__world = t.__world, boxLayout.boxBounds = layout.boxBounds
5348

5449
box.set(value)
5550
if (boxLayout.strokeChanged) layout.strokeChange()
5651
if (boxLayout.renderChanged) layout.renderChange()
5752
box.__updateChange()
5853

59-
} else {
60-
61-
if (box) {
62-
t.__box = box.parent = null
63-
box.destroy()
64-
}
65-
54+
} else if (box) {
55+
t.__box = box.parent = null
56+
box.destroy()
6657
}
6758

6859
this._boxStyle = value

packages/display/src/Box.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ export class Box extends Group implements IBox {
102102
copy(childrenRenderBounds, renderBounds)
103103
this.__updateRectRenderBounds()
104104

105-
isOverflow = !includes(renderBounds, childrenRenderBounds)
105+
isOverflow = !includes(renderBounds, childrenRenderBounds) || undefined
106106
if (isOverflow && this.__.overflow !== 'hide') add(renderBounds, childrenRenderBounds)
107107
} else this.__updateRectRenderBounds()
108108

109-
!this.isOverflow !== !isOverflow && (this.isOverflow = isOverflow) // 节省赋值
109+
this.isOverflow !== isOverflow && (this.isOverflow = isOverflow) // 节省赋值
110110
}
111111

112112
@rewrite(rect.__updateRenderBounds)

packages/display/src/Text.ts

+6-11
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,11 @@ export class Text extends UI implements IText {
153153

154154
if (italic) b.width += fontSize * 0.16 // 倾斜会导致文本的bounds增大
155155

156-
const isOverflow = !includes(b, contentBounds)
157-
if (isOverflow) {
158-
setList(data.__textBoxBounds = {} as IBoundsData, [b, contentBounds])
159-
layout.renderChanged = true
160-
} else data.__textBoxBounds = b
156+
const isOverflow = !includes(b, contentBounds) || undefined
157+
if (isOverflow) setList(data.__textBoxBounds = {} as IBoundsData, [b, contentBounds]), layout.renderChanged = true
158+
else data.__textBoxBounds = b
161159

162-
!this.isOverflow !== !isOverflow && (this.isOverflow = isOverflow) // 节省赋值
160+
this.isOverflow !== isOverflow && (this.isOverflow = isOverflow) // 节省赋值
163161
}
164162

165163
public __onUpdateSize(): void {
@@ -181,16 +179,13 @@ export class Text extends UI implements IText {
181179

182180
public __draw(canvas: ILeaferCanvas, options: IRenderOptions, originCanvas?: ILeaferCanvas): void {
183181
const box = this.__box
184-
if (box) {
185-
box.__nowWorld = this.__nowWorld
186-
box.__draw(canvas, options, originCanvas)
187-
}
182+
if (box) box.__nowWorld = this.__nowWorld, box.__draw(canvas, options, originCanvas)
188183
if (this.textEditing && !Export.running) return
189184
super.__draw(canvas, options, originCanvas)
190185
}
191186

192187
public destroy(): void {
193-
this.boxStyle = null
188+
if (this.boxStyle) this.boxStyle = null
194189
super.destroy()
195190
}
196191

0 commit comments

Comments
 (0)