-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack-vertical.js
More file actions
112 lines (86 loc) · 3.01 KB
/
Copy pathstack-vertical.js
File metadata and controls
112 lines (86 loc) · 3.01 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const BaseStackComponent = require('./base-stack-component.js');
const { Alignment, Layout } = require('./enums/index.js');
module.exports = class StackVertical extends BaseStackComponent {
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, spacing, layout) {
layout = layout || Layout.none;
let offsetY = 0;
let firstChild = true;
for (let child of this.children) {
if (firstChild) {
firstChild = false;
} else {
if (layout === Layout.none) {
offsetY += spacing;
}
}
child._originY = offsetY + this._originY + this.y + this.margin.top;
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;
child.width = this.width - this.margin.horizontalTotal;
break;
}
child.layoutComponent(document);
offsetY += child.height;
}
return offsetY;
}
layoutComponent(document) {
this._layoutChildren(document);
if (!this.width) {
this.width = this._contentWidth + this.margin.horizontalTotal;
}
let layoutOffsetY = this._layoutComponent(document, this.spacing, this.layout);
if (!this.height) {
this.height = layoutOffsetY + this.margin.verticalTotal;
}
if (this.children.length > 1) {
switch (this.layout) {
case Layout.spaceEvenly:
let availableSpace = this.height - layoutOffsetY;
let spacing = availableSpace / (this.children.length - 1);
layoutOffsetY = this._layoutComponent(document, spacing);
break;
case Layout.sizeEvenly:
let childHeight = (this.height - this.margin.verticalTotal - (this.spacing * (this.children.length - 1))) / this.children.length;
let offsetY = this._originY + this.x + this.margin.top;
for (let child of this.children) {
child._originY = offsetY;
child.height = childHeight;
child.layoutComponent(document);
offsetY += child.height + this.spacing;
}
break;
}
}
}
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;
}
}
}
}