Search Unity

Resolved UIBuilder: Easy customisation of standard templates

Discussion in 'UI Toolkit' started by Sengaya, Aug 26, 2022.

  1. Sengaya

    Sengaya

    Joined:
    Nov 21, 2018
    Posts:
    9
    Will there be a convenient way to customize the ui builder standard templates other than creating a selector for every tiny piece i want to change?

    For example when styling a toggle element i have to add the selector ".unity-toggle__label" by hand to have access to its values in the inspector.

    Please at least let us add it to the selectors by double-clicking or even better: give us full access to override the classes as it is possible with the parent element also (as you can see in the attached screenshots).

    Maybe i am missing something, but if there is no other way then it is really inconvenient to style standard elements.

    Thanks a lot :)
     

    Attached Files:

  2. martinpa_unity

    martinpa_unity

    Unity Technologies

    Joined:
    Oct 18, 2017
    Posts:
    480
    Hi!

    For built-in control, the reason we disable most of the children is that they are created and added through code and there isn't a way to modify them through Uxml, as we have no control over when they are created/added/removed from the hierarchy.

    Using selectors is the way to go to change the styling of those elements. Depending on where you put the selector and what is the matching rule of the selector, you could end up changing a single element or changing all of them. For example, if you need to change the "default" styling for a Toggle and you want it to apply to your whole panel, you could define that selector once in your theme and then it will apply to all Toggles.

    Using selectors will also keep the cascading nature of UI Toolkit, so if another matching selector is more specific, it will be used instead.

    You should be able to add a selector for ".unity-toggle__label" from the matching selector section even if the element is disabled for editing. So I would say for the 711 screenshot, that is definitely a bug, can you report it?

    To style standard controls in general, a Theme Style Sheet is probably the way to go, as you will be able to do it in one place and then then reuse it across multiple UI hierarchies. That being said, the Theme workflows are currently extremely limited.

    Granted, some of the built-in controls make it a little difficult to easily style them and we will need to improve on that.
    Hope this helps!
     
  3. Sengaya

    Sengaya

    Joined:
    Nov 21, 2018
    Posts:
    9
    Thank you very much for your extensive answer martin, i will report the issue in the next days. A fix for that particular issue would make it at least a lot easier to create the selector.

    I will look into the use of a theme style sheet, that sound like a good idea. Looking forward to your improvements on that topic :)
     
    martinpa_unity likes this.