Skip to content

Commit 2020ccb

Browse files
committed
Comment and clean up
1 parent c0956b3 commit 2020ccb

File tree

1 file changed

+69
-18
lines changed

1 file changed

+69
-18
lines changed

newIDE/app/src/ObjectsRendering/Renderers/RenderedCustomObjectInstance.js

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -137,22 +137,61 @@ class ChildInstance {
137137
}
138138

139139
type AxeLayout = {
140+
/**
141+
* The origin of the anchor on the object to place
142+
* as a factor of the current object size
143+
* (0 for left or top, 1 for right or bottom).
144+
*/
140145
anchorOrigin?: number,
146+
/**
147+
* The target of the anchor on the referential object
148+
* as a factor of the targeted object size
149+
* (0 for left or top, 1 for right or bottom).
150+
*/
141151
anchorTarget?: number,
152+
/**
153+
* The object name to take as referential.
154+
*/
142155
anchorTargetObject?: string,
156+
/**
157+
* A displacement to add on the anchored object.
158+
*/
143159
anchorDelta?: number,
160+
/**
161+
* The left or top margin in pixels.
162+
*/
144163
minSideAbsoluteMargin?: number,
164+
/**
165+
* The right or bottom margin in pixels.
166+
*/
145167
maxSideAbsoluteMargin?: number,
168+
/**
169+
* The left or top margin as a factor of the parent size.
170+
*/
146171
minSideProportionalMargin?: number,
172+
/**
173+
* The right or bottom margin as a factor of the parent size.
174+
*/
147175
maxSideProportionalMargin?: number,
148176
};
149177

178+
/**
179+
* Layout description that allows to position the child-objects
180+
* to follow the size of the parent.
181+
*/
150182
type ChildLayout = {
183+
/**
184+
* Some child-object are optional or only displayed according to the parent state.
185+
* For example, for buttons there is a background for each state.
186+
*/
151187
isShown: boolean,
152188
horizontalLayout: AxeLayout,
153189
verticalLayout: AxeLayout,
154190
};
155191

192+
/**
193+
* The keywords to find in the properties to build the ChildLayout.
194+
*/
156195
const layoutFields = [
157196
'Show',
158197
'LeftPadding',
@@ -196,6 +235,9 @@ const getVerticalAnchorValue = (anchorName: string) => {
196235
: null;
197236
};
198237

238+
/**
239+
* Build the layouts description from the custom object properties.
240+
*/
199241
const getLayouts = (
200242
eventBasedObject: gdEventsBasedObject,
201243
customObjectConfiguration: gdCustomObjectConfiguration
@@ -211,6 +253,9 @@ const getLayouts = (
211253
) {
212254
const property = properties.getAt(propertyIndex);
213255

256+
/**
257+
* The list of child-object where the layout is applied
258+
*/
214259
const childNames = property.getExtraInfo();
215260
if (!childNames) {
216261
continue;
@@ -223,6 +268,9 @@ const getLayouts = (
223268
const propertyValueNumber = Number.parseFloat(propertyValueString) || 0;
224269
const layoutField = layoutFields.find(field => name.includes(field));
225270

271+
// AnchorTarget extraInfo is not the list of child-object where the layout is applied
272+
// but the child that is the target of the anchor.
273+
// The extraInfos from the AnchorOrigin is used to get this child-object list
226274
let targetObjectName = '';
227275
let horizontalAnchorTarget: ?number = null;
228276
let verticalAnchorTarget: ?number = null;
@@ -477,25 +525,16 @@ export default class RenderedCustomObjectInstance extends RenderedInstance {
477525
const childInstance = this.childrenInstances[index];
478526
const childLayout = this.childrenLayouts[index];
479527

480-
childInstance.setCustomWidth(renderedInstance.getDefaultWidth());
481-
childInstance.setCustomHeight(renderedInstance.getDefaultHeight());
482-
483-
const childMinX =
484-
childLayout.horizontalLayout.minSideAbsoluteMargin ||
485-
(childLayout.horizontalLayout.minSideProportionalMargin || 0) * width;
486-
const childMaxX =
487-
width -
488-
(childLayout.horizontalLayout.maxSideAbsoluteMargin ||
489-
(childLayout.horizontalLayout.maxSideProportionalMargin || 0) *
490-
width);
491-
const childMinY =
492-
childLayout.verticalLayout.minSideAbsoluteMargin ||
493-
(childLayout.verticalLayout.minSideProportionalMargin || 0) * height;
494-
const childMaxY =
495-
height -
496-
(childLayout.verticalLayout.maxSideAbsoluteMargin ||
497-
(childLayout.verticalLayout.maxSideProportionalMargin || 0) * height);
498528
if (childLayout.horizontalLayout.anchorOrigin == null) {
529+
const childMinX =
530+
childLayout.horizontalLayout.minSideAbsoluteMargin ||
531+
(childLayout.horizontalLayout.minSideProportionalMargin || 0) * width;
532+
const childMaxX =
533+
width -
534+
(childLayout.horizontalLayout.maxSideAbsoluteMargin ||
535+
(childLayout.horizontalLayout.maxSideProportionalMargin || 0) *
536+
width);
537+
499538
childInstance.x = childMinX;
500539
childInstance.setCustomWidth(childMaxX - childMinX);
501540
} else {
@@ -516,8 +555,19 @@ export default class RenderedCustomObjectInstance extends RenderedInstance {
516555
(childLayout.horizontalLayout.anchorDelta || 0) +
517556
anchorTarget * targetInstanceWidth -
518557
anchorOrigin * renderedInstance.getDefaultWidth();
558+
childInstance.setCustomWidth(renderedInstance.getDefaultWidth());
519559
}
560+
520561
if (childLayout.verticalLayout.anchorOrigin == null) {
562+
const childMinY =
563+
childLayout.verticalLayout.minSideAbsoluteMargin ||
564+
(childLayout.verticalLayout.minSideProportionalMargin || 0) * height;
565+
const childMaxY =
566+
height -
567+
(childLayout.verticalLayout.maxSideAbsoluteMargin ||
568+
(childLayout.verticalLayout.maxSideProportionalMargin || 0) *
569+
height);
570+
521571
childInstance.y = childMinY;
522572
childInstance.setCustomHeight(childMaxY - childMinY);
523573
} else {
@@ -538,6 +588,7 @@ export default class RenderedCustomObjectInstance extends RenderedInstance {
538588
(childLayout.verticalLayout.anchorDelta || 0) +
539589
anchorTarget * targetInstanceHeight -
540590
anchorOrigin * renderedInstance.getDefaultHeight();
591+
childInstance.setCustomHeight(renderedInstance.getDefaultHeight());
541592
}
542593
renderedInstance.update();
543594
}

0 commit comments

Comments
 (0)