-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack-horizontal.js
More file actions
108 lines (81 loc) · 2.92 KB
/
Copy pathstack-horizontal.js
File metadata and controls
108 lines (81 loc) · 2.92 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
const BaseStackComponent = require('./base-stack-component.js');
const { Alignment, Layout } = require('./enums/index.js');
module.exports = class StackHorizontal 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 offsetX = 0;
let firstChild = true;
for (let child of this.children) {
if (firstChild) {
firstChild = false;
} else {
if (layout === Layout.none) {
offsetX += spacing;
}
}
child._originX = offsetX + this._originX + this.x + this.margin.left;
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;
child.height = this.height;
break;
}
child.layoutComponent(document);
offsetX += child.width;
}
return offsetX;
}
layoutComponent(document) {
this._layoutChildren(document);
if (!this.height) {
this.height = this._contentHeight + this.margin.verticalTotal;
}
let layoutOffsetX = this._layoutComponent(document, this.spacing, this.layout);
if (!this.width) {
this.width = layoutOffsetX + this.margin.horizontalTotal;
}
switch (this.layout) {
case Layout.spaceEvenly:
let availableSpace = this.width - this.margin.horizontalTotal - layoutOffsetX;
let spacing = availableSpace / (this.children.length > 1 ? this.children.length - 1 : 1);
layoutOffsetX = this._layoutComponent(document, spacing);
break;
case Layout.sizeEvenly:
let childWidth = (this.width - this.margin.horizontalTotal - (this.spacing * (this.children.length - 1))) / this.children.length;
let offsetX = this._originX + this.x + this.margin.left;
for (let child of this.children) {
child._originX = offsetX;
child.width = childWidth;
child.layoutComponent(document);
offsetX += child.width + 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);
}
}
}