-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontainer.js
More file actions
95 lines (76 loc) · 2.66 KB
/
Copy pathcontainer.js
File metadata and controls
95 lines (76 loc) · 2.66 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const BaseContainerComponent = require('./base-container-component.js');
const { Alignment } = require('./enums');
module.exports = class Container extends BaseContainerComponent {
constructor(properties) {
super(properties);
}
initializeComponent(data) {
super.initializeComponent(data);
const dataBindingSource = this.getBinding(data);
for (let child of this.children) {
child.initializeComponent(dataBindingSource);
}
}
layoutComponent(document) {
let maxWidth = 0;
let maxHeight = 0;
for (let child of this.children) {
if (this.width && child.horizontalAlignment == Alignment.fill) {
child.width = this.width - this.margin.horizontalTotal;
}
if (this.height && child.verticalAlignment == Alignment.fill) {
child.height = this.height - this.margin.verticalTotal;
}
child.layoutComponent(document);
maxWidth = Math.max(maxWidth, child.width);
maxHeight = Math.max(maxHeight, child.height);
}
if (!this.width) {
this.width = maxWidth + this.margin.horizontalTotal;
}
if (!this.height) {
this.height = maxHeight + this.margin.verticalTotal;
}
for (let child of this.children) {
switch (child.verticalAlignment) {
case Alignment.start:
child._originY = this._originY + this.y + this.margin.top;
break;
case Alignment.end:
child._originY = this._originY + this.y + this.height - this.margin.bottom - child.height;
break;
case Alignment.middle:
child._originY = this._originY + this.y + (this.height / 2) - (child.height / 2);
break;
case Alignment.fill:
child._originY = this._originY + this.y + this.margin.top;
break;
}
switch (child.horizontalAlignment) {
case Alignment.start:
child._originX = this._originX + this.x + this.margin.left;
break;
case Alignment.end:
child._originX = this._originX + this.x + this.width - this.margin.right - child.width;
break;
case Alignment.middle:
child._originX = this._originX + this.x + (this.width / 2) - (child.width / 2)
break;
case Alignment.fill:
child._originX = this._originX + this.x + this.margin.left;
break;
}
child.layoutComponent(document);
}
}
generateComponent(document, data) {
super.generateComponent(document, data);
const dataBindingSource = this.getBinding(data);
for (let child of this.children) {
child.generateComponent(document, dataBindingSource);
if (document.renderNextPage) {
return;
}
}
}
}