@@ -328,8 +328,9 @@ const getLayouts = (
328
328
*/
329
329
export default class RenderedCustomObjectInstance extends RenderedInstance {
330
330
childrenInstances : ChildInstance [ ] ;
331
- childrenRenderedInstances : RenderedInstance [ ] ;
332
331
childrenLayouts : ChildLayout [ ] ;
332
+ childrenRenderedInstances : RenderedInstance [ ] ;
333
+ childrenRenderedInstanceByNames : Map < string , RenderedInstance > ;
333
334
334
335
constructor (
335
336
project : gdProject ,
@@ -365,6 +366,7 @@ export default class RenderedCustomObjectInstance extends RenderedInstance {
365
366
this . childrenInstances = [ ] ;
366
367
this . childrenLayouts = [ ] ;
367
368
this . childrenRenderedInstances = [ ] ;
369
+ this . childrenRenderedInstanceByNames = new Map < string , RenderedInstance > ( ) ;
368
370
369
371
if ( ! eventBasedObject ) {
370
372
return ;
@@ -406,6 +408,7 @@ export default class RenderedCustomObjectInstance extends RenderedInstance {
406
408
this . childrenInstances . push ( childInstance ) ;
407
409
this . childrenLayouts . push ( childLayout ) ;
408
410
this . childrenRenderedInstances . push ( renderer ) ;
411
+ this . childrenRenderedInstanceByNames . set ( childObject . getName ( ) , renderer ) ;
409
412
} ) ;
410
413
}
411
414
@@ -498,10 +501,20 @@ export default class RenderedCustomObjectInstance extends RenderedInstance {
498
501
} else {
499
502
const anchorOrigin = childLayout . horizontalLayout . anchorOrigin || 0 ;
500
503
const anchorTarget = childLayout . horizontalLayout . anchorTarget || 0 ;
501
- // TODO Use anchorTargetObject instead of defaulting on the background
504
+
505
+ const targetRenderedInstance =
506
+ this . childrenRenderedInstanceByNames . get (
507
+ childLayout . horizontalLayout . anchorTargetObject || ''
508
+ ) || this . childrenRenderedInstances [ 0 ] ;
509
+ const targetInstance = targetRenderedInstance . _instance ;
510
+ const targetInstanceWidth = targetInstance . hasCustomSize ( )
511
+ ? targetInstance . getCustomWidth ( )
512
+ : targetRenderedInstance . getDefaultWidth ( ) ;
513
+
502
514
childInstance . x =
515
+ targetInstance . getX ( ) +
503
516
( childLayout . horizontalLayout . anchorDelta || 0 ) +
504
- anchorTarget * width -
517
+ anchorTarget * targetInstanceWidth -
505
518
anchorOrigin * renderedInstance . getDefaultWidth ( ) ;
506
519
}
507
520
if ( childLayout . verticalLayout . anchorOrigin == null ) {
@@ -510,10 +523,20 @@ export default class RenderedCustomObjectInstance extends RenderedInstance {
510
523
} else {
511
524
const anchorOrigin = childLayout . verticalLayout . anchorOrigin || 0 ;
512
525
const anchorTarget = childLayout . verticalLayout . anchorTarget || 0 ;
513
- // TODO Use anchorTargetObject instead of defaulting on the background
526
+
527
+ const targetRenderedInstance =
528
+ this . childrenRenderedInstanceByNames . get (
529
+ childLayout . horizontalLayout . anchorTargetObject || ''
530
+ ) || this . childrenRenderedInstances [ 0 ] ;
531
+ const targetInstance = targetRenderedInstance . _instance ;
532
+ const targetInstanceHeight = targetInstance . hasCustomSize ( )
533
+ ? targetInstance . getCustomHeight ( )
534
+ : targetRenderedInstance . getDefaultHeight ( ) ;
535
+
514
536
childInstance . y =
537
+ targetInstance . getY ( ) +
515
538
( childLayout . verticalLayout . anchorDelta || 0 ) +
516
- anchorTarget * height -
539
+ anchorTarget * targetInstanceHeight -
517
540
anchorOrigin * renderedInstance . getDefaultHeight ( ) ;
518
541
}
519
542
renderedInstance . update ( ) ;
0 commit comments