-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContainerComponent.js
37 lines (35 loc) · 1.19 KB
/
ContainerComponent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import Component from "./Component.js"
import { Vector } from "./Math.js"
export default class ComponentContainer extends Component {
getSize() {
let desiredHeight = 0
let desiredWidth = 0
for (const component of this.componentsOrder) {
if (component.options.isDesiredContainerChild) {
let componentSize = component.getFullSize(new Vector(0, 0))
let componentPosition = component.getPosition(
new Vector(0, 0),
componentSize
)
let topLeftMarginVector = new Vector(
component.margin.z,
component.margin.x
)
let finalSize = componentSize
.add_vec(componentPosition)
.sub_vec(topLeftMarginVector)
if (finalSize.x > desiredWidth) desiredWidth = finalSize.x
if (finalSize.y > desiredHeight) desiredHeight = finalSize.y
}
}
return new Vector(desiredWidth, desiredHeight)
}
onChildResize(child) {
if (child.options.isDesiredContainerChild) this.resize()
}
resizeChildren(size) {
for (const component of this.componentsOrder) {
if (!component.options.isDesiredContainerChild) component.resize(size)
}
}
}