@@ -328,8 +328,9 @@ const getLayouts = (
328328 */
329329export default class RenderedCustomObjectInstance extends RenderedInstance {
330330 childrenInstances : ChildInstance [ ] ;
331- childrenRenderedInstances : RenderedInstance [ ] ;
332331 childrenLayouts : ChildLayout [ ] ;
332+ childrenRenderedInstances : RenderedInstance [ ] ;
333+ childrenRenderedInstanceByNames : Map < string , RenderedInstance > ;
333334
334335 constructor (
335336 project : gdProject ,
@@ -365,6 +366,7 @@ export default class RenderedCustomObjectInstance extends RenderedInstance {
365366 this . childrenInstances = [ ] ;
366367 this . childrenLayouts = [ ] ;
367368 this . childrenRenderedInstances = [ ] ;
369+ this . childrenRenderedInstanceByNames = new Map < string , RenderedInstance > ( ) ;
368370
369371 if ( ! eventBasedObject ) {
370372 return ;
@@ -406,6 +408,7 @@ export default class RenderedCustomObjectInstance extends RenderedInstance {
406408 this . childrenInstances . push ( childInstance ) ;
407409 this . childrenLayouts . push ( childLayout ) ;
408410 this . childrenRenderedInstances . push ( renderer ) ;
411+ this . childrenRenderedInstanceByNames . set ( childObject . getName ( ) , renderer ) ;
409412 } ) ;
410413 }
411414
@@ -498,10 +501,20 @@ export default class RenderedCustomObjectInstance extends RenderedInstance {
498501 } else {
499502 const anchorOrigin = childLayout . horizontalLayout . anchorOrigin || 0 ;
500503 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+
502514 childInstance . x =
515+ targetInstance . getX ( ) +
503516 ( childLayout . horizontalLayout . anchorDelta || 0 ) +
504- anchorTarget * width -
517+ anchorTarget * targetInstanceWidth -
505518 anchorOrigin * renderedInstance . getDefaultWidth ( ) ;
506519 }
507520 if ( childLayout . verticalLayout . anchorOrigin == null ) {
@@ -510,10 +523,20 @@ export default class RenderedCustomObjectInstance extends RenderedInstance {
510523 } else {
511524 const anchorOrigin = childLayout . verticalLayout . anchorOrigin || 0 ;
512525 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+
514536 childInstance . y =
537+ targetInstance . getY ( ) +
515538 ( childLayout . verticalLayout . anchorDelta || 0 ) +
516- anchorTarget * height -
539+ anchorTarget * targetInstanceHeight -
517540 anchorOrigin * renderedInstance . getDefaultHeight ( ) ;
518541 }
519542 renderedInstance . update ( ) ;
0 commit comments