Search Unity

NaN values for VisualElement layouts at initialization

Discussion in 'UIElements' started by AegeanSea, May 11, 2019.

  1. AegeanSea

    AegeanSea

    Joined:
    Aug 27, 2017
    Posts:
    2
    Is there a callback or event to detect when a VisualElement finally gets its values for the layout/content rects? I assume these values begin at NaN until the XML view gets inflated and a repaint or layout event happens, but is there a better way to detect this other than to manually poke the values on OnGUI until they come up?

    Also, how does this work with data persistence? On a ScrollView, for example, the documentation seems to indicate that setting viewDataKey means that the scroll offset is to be stored between domain reloads, when does this happen if at initialization the layout values are not known?
     
  2. patrickf

    patrickf

    Unity Technologies

    Joined:
    Oct 24, 2016
    Posts:
    44
    Hi!
    You can register a callback on the GeometryChangedEvent:

    element.RegisterCallback<GeometryChangedEvent>(myCallback);


    As for data persistence, the value stored are simply restored and then the layout is recomputed. In the case of the ScrollView, the scrollbar value is used to compute the pixel offset, so the value itself is not directly affected by the layout. However, if, as a result of the layout or otherwise, the min and max scroll value should change, the actual value would be clamped against these new bounds.
     
  3. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    221
    There is currently a bug where if the value of the scrollview offset is outside the default min/max (the min/max of the ScrollView when it is first constructed), the persisted view data offset will be clamped when it is being restored and the new clamped value will be re-saved. It is know and being fixed.
     
  4. AegeanSea

    AegeanSea

    Joined:
    Aug 27, 2017
    Posts:
    2
    Thank you!