Search Unity

Feedback make public TextElement.MeasureVisualElementTextSize()

Discussion in 'UI Toolkit' started by Devi-User, Jun 3, 2019.

  1. Devi-User

    Devi-User

    Joined:
    Apr 30, 2016
    Posts:
    61
    This is a very useful method that I would like to use not only for objects inherited from TextElement, but also for specifying the size of my TextField. Unfortunately, the method contains elements that are also hidden under internal, and I can not just copy it. This is a very good method that allows you to find the size of the text and it seems I have not found a universal way to do it in a different way.
     
  2. AlexandreT-unity

    AlexandreT-unity

    Unity Technologies

    Joined:
    Feb 1, 2018
    Posts:
    376
    Hi Devi-User, we'll consider adding an API for that, thanks for your feedback!
     
    Devi-User likes this.
  3. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    780
    Hello,

    Actually there is a public API to get text measurement via the TextElement : https://docs.unity3d.com/2019.3/Doc...e/UIElements.TextElement.MeasureTextSize.html

    The main caveat is that the element must have received its styles in order for this to return valid information.
    One can register for
    GeometryChangedEvent
    onto it to make sure correct information is available.

    As Alexandre mentioned, we will look for ways to make this immediate in the future.

    Thanks
     
  4. alancomerhof

    alancomerhof

    Joined:
    Jan 12, 2020
    Posts:
    1
    I can measure the text, but trying to write to the Label.style property is just ignored. The debugger shows "Could not find a member 'fontSize' for 'label.style'