Skip to content

Commit 3c37bb3

Browse files
committed
Allow to hide some child-objects.
1 parent 40c3f8e commit 3c37bb3

File tree

1 file changed

+58
-52
lines changed

1 file changed

+58
-52
lines changed

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

Lines changed: 58 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,13 @@ type AxeLayout = {
147147
};
148148

149149
type ChildLayout = {
150+
isShown: boolean,
150151
horizontalLayout: AxeLayout,
151152
verticalLayout: AxeLayout,
152153
};
153154

154155
const layoutFields = [
156+
'Show',
155157
'LeftPadding',
156158
'TopPadding',
157159
'RightPadding',
@@ -201,12 +203,11 @@ const getLayouts = (
201203
continue;
202204
}
203205

206+
// The property types should never be checked because we may introduce
207+
// new types to make the layout configuration easier.
204208
const name = property.getName();
205-
const isNumber = property.getType() === 'Number';
206209
const propertyValueString = instanceProperties.get(name).getValue();
207-
const propertyValueNumber = isNumber
208-
? Number.parseFloat(propertyValueString) || 0
209-
: 0;
210+
const propertyValueNumber = Number.parseFloat(propertyValueString) || 0;
210211
const layoutField = layoutFields.find(field => name.includes(field));
211212

212213
let targetObjectName = '';
@@ -224,18 +225,16 @@ const getLayouts = (
224225
const anchorTargetStringValue = instanceProperties
225226
.get(targetPropertyName)
226227
.getValue();
227-
const targetIsNumber = targetProperty.getType() === 'Number';
228-
const anchorTargetValueNumber = isNumber
229-
? Number.parseFloat(anchorTargetStringValue) || 0
230-
: 0;
228+
const anchorTargetValueNumber =
229+
Number.parseFloat(anchorTargetStringValue) || 0;
231230
if (layoutField === 'HorizontalAnchorOrigin') {
232-
anchorTarget = targetIsNumber
233-
? anchorTargetValueNumber
234-
: getHorizontalAnchorValue(anchorTargetStringValue);
231+
anchorTarget =
232+
getHorizontalAnchorValue(anchorTargetStringValue) ||
233+
anchorTargetValueNumber;
235234
} else {
236-
anchorTarget = targetIsNumber
237-
? anchorTargetValueNumber
238-
: getVerticalAnchorValue(anchorTargetStringValue);
235+
anchorTarget =
236+
getVerticalAnchorValue(anchorTargetStringValue) ||
237+
anchorTargetValueNumber;
239238
}
240239
}
241240

@@ -244,12 +243,17 @@ const getLayouts = (
244243
let layout = layouts.get(childName);
245244
if (!layout) {
246245
layout = {
246+
isShown: true,
247247
horizontalLayout: {},
248248
verticalLayout: {},
249249
};
250250
layouts.set(childName, layout);
251251
}
252-
if (layoutField === 'LeftPadding') {
252+
if (layoutField === 'Show') {
253+
if (propertyValueString === 'false') {
254+
layout.isShown = false;
255+
}
256+
} else if (layoutField === 'LeftPadding') {
253257
layout.horizontalLayout.minSideAbsoluteMargin = propertyValueNumber;
254258
} else if (layoutField === 'RightPadding') {
255259
layout.horizontalLayout.maxSideAbsoluteMargin = propertyValueNumber;
@@ -258,9 +262,8 @@ const getLayouts = (
258262
} else if (layoutField === 'BottomPadding') {
259263
layout.verticalLayout.maxSideAbsoluteMargin = propertyValueNumber;
260264
} else if (layoutField === 'HorizontalAnchorOrigin') {
261-
const anchorOrigin = isNumber
262-
? propertyValueNumber
263-
: getHorizontalAnchorValue(propertyValueString);
265+
const anchorOrigin =
266+
getHorizontalAnchorValue(propertyValueString) || propertyValueNumber;
264267
if (anchorOrigin !== null) {
265268
layout.horizontalLayout.anchorOrigin = anchorOrigin;
266269
}
@@ -269,9 +272,8 @@ const getLayouts = (
269272
}
270273
layout.horizontalLayout.anchorTargetObject = targetObjectName;
271274
} else if (layoutField === 'VerticalAnchorOrigin') {
272-
const anchorOrigin = isNumber
273-
? propertyValueNumber
274-
: getVerticalAnchorValue(propertyValueString);
275+
const anchorOrigin =
276+
getVerticalAnchorValue(propertyValueString) || propertyValueNumber;
275277
if (anchorOrigin !== null) {
276278
layout.verticalLayout.anchorOrigin = anchorOrigin;
277279
}
@@ -333,39 +335,43 @@ export default class RenderedCustomObjectInstance extends RenderedInstance {
333335
return;
334336
}
335337

336-
const layouts = getLayouts(eventBasedObject, customObjectConfiguration);
338+
const childLayouts = getLayouts(
339+
eventBasedObject,
340+
customObjectConfiguration
341+
);
337342

338-
this.childrenRenderedInstances = mapReverseFor(
339-
0,
340-
eventBasedObject.getObjectsCount(),
341-
i => {
342-
const childObject = eventBasedObject.getObjectAt(i);
343-
const childObjectConfiguration = customObjectConfiguration.getChildObjectConfiguration(
344-
childObject.getName()
345-
);
346-
const childInstance = new ChildInstance();
347-
this.childrenInstances.push(childInstance);
348-
this.childrenLayouts.push(
349-
layouts.get(childObject.getName()) || {
350-
horizontalLayout: {},
351-
verticalLayout: {},
352-
}
353-
);
354-
const renderer = ObjectsRenderingService.createNewInstanceRenderer(
355-
project,
356-
layout,
357-
// $FlowFixMe Use real object instances.
358-
childInstance,
359-
childObjectConfiguration,
360-
this._pixiObject
361-
);
362-
if (renderer instanceof RenderedTextInstance) {
363-
// TODO EBO Remove this line when an alignment property is added to the text object.
364-
renderer._pixiObject.style.align = 'center';
365-
}
366-
return renderer;
343+
mapReverseFor(0, eventBasedObject.getObjectsCount(), i => {
344+
const childObject = eventBasedObject.getObjectAt(i);
345+
346+
const childLayout = childLayouts.get(childObject.getName()) || {
347+
isShown: true,
348+
horizontalLayout: {},
349+
verticalLayout: {},
350+
};
351+
if (!childLayout.isShown) {
352+
return;
367353
}
368-
);
354+
355+
const childObjectConfiguration = customObjectConfiguration.getChildObjectConfiguration(
356+
childObject.getName()
357+
);
358+
const childInstance = new ChildInstance();
359+
const renderer = ObjectsRenderingService.createNewInstanceRenderer(
360+
project,
361+
layout,
362+
// $FlowFixMe Use real object instances.
363+
childInstance,
364+
childObjectConfiguration,
365+
this._pixiObject
366+
);
367+
if (renderer instanceof RenderedTextInstance) {
368+
// TODO EBO Remove this line when an alignment property is added to the text object.
369+
renderer._pixiObject.style.align = 'center';
370+
}
371+
this.childrenInstances.push(childInstance);
372+
this.childrenLayouts.push(childLayout);
373+
this.childrenRenderedInstances.push(renderer);
374+
});
369375
}
370376

371377
/**

0 commit comments

Comments
 (0)