Search Unity

Is there a way to find the amount of space an element should take before rendering?

Discussion in 'UI Toolkit' started by unity_zIYWJyNr2AiCPA, Mar 30, 2020.

  1. unity_zIYWJyNr2AiCPA

    unity_zIYWJyNr2AiCPA

    Joined:
    Jan 5, 2020
    Posts:
    9
    I'm trying to ensure the window I'm creating has enough space for the Element.
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    There's some functions on the TextElement to pre-measure text but nothing "general" for pre-calculating the size of an element. My recommendation is to let the element size itself, detect the completion of the layout by listening for the GeometryChangeEvent, and then reading the final size from element.resolvedStyles.width/height. If you must, you can do this off-screen so the user doesn't see any popping.