Question
We are looking for a better way to know when a GUI control is ready to be rendered. When I say ready, I mean that all of the properties applied have been set and calculated.
Is there a recommended way of knowing when a GUI control is done updating?
Background
We are developing an application for a unique XR device. We have a GUI panel (advancedDynamicTexture mesh) that we are rendering in the scene at a very specific position. Its vital that the GUI be sized perfectly in the 3D scene.
The process we are currently using involves creating a fullscreen advancedDynamicTexture and a mesh advancedDynamicTexture. We add all of our controls to the fullscreen adt which uses a variety of control types and sizes itself. Once we think the controls have been calculated and ready to be rendered, we take the size of our root control and use its size to calculate the size of the mesh adt. This has been working quite well. Its allowing us to perfectly position the mesh adt in the scene without blocking raycasts in places where the texture was transparent.
We are finding that we are moving the controls to the mesh adt too early sometimes. For example, a recent panel we implemented appeared to be working well until we noticed that the text on a button was changing as soon as we interacted with the button on the mesh adt. After looking at the code for TextBlock we realized that setting the fontWeight marks the control as dirty and takes another cycle before it is rendered propertly.
We were having a similar problem with a GUI panel that used a ScrollViewer. We have an onAfterDrawObservable
callback that we use to allow the ScrollViewer to shrink in height if it doesn’t need the full height of its parent. We were moving the control from the fullscreen adt to the mesh adt before that callback to adapt the ScollViewer’s height has occurred.
To solve that problem, we added a promise to let us know when the ScrollViewer’s height had been adapted and after that we moved the control to the mesh adt and it worked as expected.
That solution took quite a bit of effort and is somewhat brittle if the UI structure changes much. So we are hoping to find a better method for determining when we should move the control from the fullscreen adt to the mesh adt.
It seems that the isDirty
property may be useful, but that also seems like an easy way to get into an infinite loop. I’m also not sure how the isDirty
property works for child components. It would be preferred if we were able to identify that a control and its children are ready as opposed to keep track of every single control in the GUI.
Sorry, I don’t have a playground example to showcase, but if you need more context I will have our lead engineer jump in and answer the questions I cannot.
@carolhmj, Does this fall into your territory?
Thank you in advance!