Search Unity

Binding the text of a label

Discussion in 'UIElements' started by JurjenBiewenga, Feb 22, 2019.

  1. JurjenBiewenga

    JurjenBiewenga

    Joined:
    Mar 28, 2018
    Posts:
    1
    Hey!

    I figured out how to do data binding to PropertyFields however it does not appear to be possible when you just want to display some dynamic text. Is this currently possible/planned?
     
  2. patrickf

    patrickf

    Unity Technologies

    Joined:
    Oct 24, 2016
    Posts:
    37
    Hi!
    There is no built-in way to do this. You can either use a TextField, make it read-only (
    isReadOnly=true
    ) and use USS to style it as a
    TextElement
    , or you can derive your own class from
    BaseField<string>
     
  3. Erothez

    Erothez

    Joined:
    May 27, 2015
    Posts:
    14
    Using `isReadOnly=true` doesn't seem to be working in 2019.1.4f1?

    Is there a way to set this from UXML as `readonly="true"` like the docs state doesn't seem to work.

    Currently working around it with some USS and other properties (focusable, pickingmode etc.) but feels hacky.

    Edit: Correction, doesn't accept keyboard input, but does allow selection and deletion...
     
    Last edited: May 27, 2019
  4. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    155
    Try "readonly=true" instead?

    FYI, the Label will be bindable in 2019.3.
     
  5. patrickf

    patrickf

    Unity Technologies

    Joined:
    Oct 24, 2016
    Posts:
    37
    From what I see the field was present in 2019.1.0b1

    In C#: ve.isReadOnly=true;
    In UXML <TextField readonly="true" />
     
  6. Erothez

    Erothez

    Joined:
    May 27, 2015
    Posts:
    14
    Yeah, the properties isReadOnly and readonly are there and have some of the associated behaviours but it doesn't fully work.

    - doesn't accept keyboard input, but does allow selection and deletion of content (defeating the purpose of it)
    - doesn't "fade out" in the expected style of IMGUI readonly stuff

    Submitted a bug[1158450], once ripped it out into smaller repro project, not a major issue as can workaround, but weird behaviour means had to turn it off for now.