Search Unity

Resolved How to create a customized Toggle?

Discussion in 'UI Toolkit' started by acandael, Jun 23, 2021.

  1. acandael

    acandael

    Joined:
    Apr 7, 2021
    Posts:
    74
    Hello,

    I use UIBuilder. I see a Toggle consists of a Label and a VisualElement containing the checkbox. The width of the Label is set to a minimum of 150px and is not accessible.
    What would be the way to customize it, and create a new type of Toggle, with the Label width that could be modified?

    Thanks a lot!
    Arnaud.
     
  2. Tom-Atom

    Tom-Atom

    Joined:
    Jun 29, 2014
    Posts:
    153
    I wanted to shorten distance between label and Enum / Integer fields. So, I believe it will be the same for Toggle...

    To change style of Label, create new style with selector like this:

    .short-toggle Label {
    width: 50px;
    min-width: 50px;
    }


    Then apply this style to Toggle.
     
    seobyeongky and acandael like this.
  3. acandael

    acandael

    Joined:
    Apr 7, 2021
    Posts:
    74
    Well.. that was easier than I expected! :)
    Wonderful, works perfectly! Thanks a lot!