| 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214 |
1×
1×
1×
1×
1×
1×
1×
5×
5×
5×
1×
1×
1×
1×
1×
9×
9×
9×
9×
9×
1×
38×
28×
10×
1×
8×
8×
8×
8×
8×
8×
8×
8×
6×
64×
64×
1×
64×
1×
64×
64×
64×
64×
64×
63×
6×
57×
1×
1×
1×
6×
5×
5×
5×
5×
6×
6×
8×
8×
8×
8×
1×
8×
8×
8×
8×
6×
6×
6×
6×
6×
6×
64×
64×
64×
1×
1×
1×
64×
1×
1×
1×
64×
64×
8×
8×
8×
8×
1×
11×
7×
74×
74×
4×
74×
4×
74×
1×
1×
10×
10×
10×
10×
10×
10×
1×
64×
64×
64×
64×
64×
64×
64×
64×
64×
64×
64×
64×
64×
64×
64×
64×
64×
64×
56×
56×
56×
56×
64×
1×
1×
| /* istanbul ignore next */
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
define(["require", "exports", "../elements/drawing-element", "../../primitives/size", "../../primitives/rect", "../../utility/base-util"], function (require, exports, drawing_element_1, size_1, rect_1, base_util_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Container module is used to group related objects
*/
var Container = /** @class */ (function (_super) {
__extends(Container, _super);
function Container() {
var _this = _super !== null && _super.apply(this, arguments) || this;
//private members
_this.desiredBounds = undefined;
/** @private */
_this.measureChildren = true;
/** @private */
_this.prevRotateAngle = 0;
return _this;
}
/**
* returns whether the container has child elements or not
*/
Container.prototype.hasChildren = function () {
if (this.children !== undefined && this.children.length > 0) {
return true;
}
return false;
};
/**
* Measures the minimum space that the container requires
*
* @param availableSize
*/
Container.prototype.measure = function (availableSize) {
// measure the element and find the desired size
this.desiredBounds = undefined;
var desired = undefined;
var child;
var center = { x: 0, y: 0 };
var y;
var x;
var childBounds;
if (this.hasChildren()) {
//Measuring the children
for (var i = 0; i < this.children.length; i++) {
child = this.children[parseInt(i.toString(), 10)];
if (child.horizontalAlignment === 'Stretch' && !availableSize.width) {
availableSize.width = child.bounds.width;
}
if (child.verticalAlignment === 'Stretch' && !availableSize.height) {
availableSize.height = child.bounds.height;
}
var force = child.horizontalAlignment === 'Stretch' || child.verticalAlignment === 'Stretch';
Eif (this.measureChildren || force || (child instanceof Container && child.measureChildren !== undefined)) {
child.measure(availableSize);
}
childBounds = this.GetChildrenBounds(child);
if (child.horizontalAlignment !== 'Stretch' && child.verticalAlignment !== 'Stretch') {
if (this.desiredBounds === undefined) {
this.desiredBounds = childBounds;
}
else {
this.desiredBounds.uniteRect(childBounds);
}
}
else Eif (this.actualSize && !this.actualSize.width && !this.actualSize.height &&
!child.preventContainer && child.horizontalAlignment === 'Stretch' && child.verticalAlignment === 'Stretch') {
Iif (this.desiredBounds === undefined) {
this.desiredBounds = child.bounds;
}
else {
this.desiredBounds.uniteRect(child.bounds);
}
}
}
if (this.desiredBounds !== undefined && this.rotateAngle !== 0) {
var offsetPt = {
x: this.desiredBounds.x + this.desiredBounds.width * this.pivot.x,
y: this.desiredBounds.y + this.desiredBounds.height * this.pivot.y
};
var newPoint = base_util_1.rotatePoint(this.rotateAngle, undefined, undefined, offsetPt);
this.desiredBounds.x = newPoint.x - this.desiredBounds.width * this.pivot.x;
this.desiredBounds.y = newPoint.y - this.desiredBounds.height * this.pivot.y;
}
Eif (this.desiredBounds) {
desired = new size_1.Size(this.desiredBounds.width, this.desiredBounds.height);
}
}
desired = this.validateDesiredSize(desired, availableSize);
this.stretchChildren(desired);
this.desiredSize = desired;
return desired;
};
/**
* Arranges the container and its children
* @param desiredSize
*/
Container.prototype.arrange = function (desiredSize) {
var child;
var bounds;
var childBounds = this.desiredBounds;
if (childBounds) {
var x = this.offsetX;
var y = this.offsetY;
this.offsetX = childBounds.x + childBounds.width * this.pivot.x;
this.offsetY = childBounds.y + childBounds.height * this.pivot.y;
// container has rotateAngle
Eif (this.hasChildren()) {
//Measuring the children
for (var i = 0; i < this.children.length; i++) {
child = this.children[parseInt(i.toString(), 10)];
var arrange = false;
if (child.horizontalAlignment === 'Stretch') {
child.offsetX = this.offsetX;
child.parentTransform = this.parentTransform + this.rotateAngle;
arrange = true;
}
if (child.verticalAlignment === 'Stretch') {
child.offsetY = this.offsetY;
child.parentTransform = this.parentTransform + this.rotateAngle;
arrange = true;
}
Eif (arrange || this.measureChildren || (child instanceof Container && child.measureChildren !== undefined)) {
child.arrange(child.desiredSize);
}
}
}
}
this.actualSize = desiredSize;
this.updateBounds();
this.prevRotateAngle = this.rotateAngle;
return desiredSize;
};
//protected methods
/**
* Stretches the child elements based on the size of the container
* @param size
*/
Container.prototype.stretchChildren = function (size) {
if (this.hasChildren()) {
for (var _i = 0, _a = this.children; _i < _a.length; _i++) {
var child = _a[_i];
if (child.horizontalAlignment === 'Stretch' || child.desiredSize.width === undefined) {
child.desiredSize.width = size.width - child.margin.left - child.margin.right;
}
if (child.verticalAlignment === 'Stretch' || child.desiredSize.height === undefined) {
child.desiredSize.height = size.height - child.margin.top - child.margin.bottom;
}
if (child instanceof Container) {
child.stretchChildren(child.desiredSize);
}
}
}
};
/**
* Finds the offset of the child element with respect to the container
* @param child
* @param center
*/
Container.prototype.findChildOffsetFromCenter = function (child, center) {
var topLeft = { x: center.x - child.desiredSize.width / 2, y: center.y - child.desiredSize.height / 2 };
var offset = base_util_1.getOffset(topLeft, child);
//Rotate based on child rotate angle
offset = base_util_1.rotatePoint(child.rotateAngle, center.x, center.y, offset);
//Rotate based on parent pivot
offset = base_util_1.rotatePoint(this.rotateAngle + this.parentTransform, this.offsetX, this.offsetY, offset);
child.offsetX = offset.x;
child.offsetY = offset.y;
};
//private methods - check its need
Container.prototype.GetChildrenBounds = function (child) {
var childBounds;
var childSize;
childSize = child.desiredSize.clone();
var diffAngle = child.rotateAngle - this.rotateAngle;
var refPoint = { x: child.offsetX, y: child.offsetY };
var left = refPoint.x - childSize.width * child.pivot.x;
var top = refPoint.y - childSize.height * child.pivot.y;
var right = left + childSize.width;
var bottom = top + childSize.height;
var topLeft = { x: left, y: top };
var topRight = { x: right, y: top };
var bottomLeft = { x: left, y: bottom };
var bottomRight = { x: right, y: bottom };
topLeft = base_util_1.rotatePoint(child.rotateAngle, child.offsetX, child.offsetY, topLeft);
topRight = base_util_1.rotatePoint(child.rotateAngle, child.offsetX, child.offsetY, topRight);
bottomLeft = base_util_1.rotatePoint(child.rotateAngle, child.offsetX, child.offsetY, bottomLeft);
bottomRight = base_util_1.rotatePoint(child.rotateAngle, child.offsetX, child.offsetY, bottomRight);
if (this.rotateAngle !== 0) {
topLeft = base_util_1.rotatePoint(-this.rotateAngle, undefined, undefined, topLeft);
topRight = base_util_1.rotatePoint(-this.rotateAngle, undefined, undefined, topRight);
bottomLeft = base_util_1.rotatePoint(-this.rotateAngle, undefined, undefined, bottomLeft);
bottomRight = base_util_1.rotatePoint(-this.rotateAngle, undefined, undefined, bottomRight);
}
return rect_1.Rect.toBounds([topLeft, topRight, bottomLeft, bottomRight]);
};
return Container;
}(drawing_element_1.DrawingElement));
exports.Container = Container;
});
|