Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Scaling Elements

Discussion in 'UI Toolkit' started by IkigaiMonkey, Jan 6, 2020.

  1. IkigaiMonkey

    IkigaiMonkey

    Joined:
    Sep 22, 2012
    Posts:
    18
    Hi,
    I'm sure this is basic and I tried googling, etc. I'm having issues scaling the Visual Elements to fit the container or a % of the container.

    In css you can do width: 100%; and in flexbox the elements autosize to the parent by default afaik, but is there any way to do this in uss ? the only thing I could do is to put fixed pixel sizes so far.

    Thanks a lot
     
  2. Wobbers

    Wobbers

    Joined:
    Dec 31, 2017
    Posts:
    55
    In the UI Builder when you enter a number value, the "-" on the right changes to "px". When you click that, you can change it to "%" and i think some others as well.
     
  3. jonathanma_unity

    jonathanma_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    229
    Hi, this is just to confirm that uss support percentage (as of 2019.3) and flex just like css.

    In your case maybe your styles are not applied properly, you can use the UIElements debugger to validate.
     
  4. IkigaiMonkey

    IkigaiMonkey

    Joined:
    Sep 22, 2012
    Posts:
    18
    Thanks for the answer. The uss looks to be applied, since I change other properties like background-color and they work.

    I tried by checking with the debugger, but looks like width is not applied. The debugger still shows the selector being applied by the uss file, and the width propery I put, but looks like it's being ignored.

    If I use "%" instead of "px" in the debugger window override, it works, however it looks to be totally ignoring the width property in uss (even if I change the px values in the uss it doesn't work).

    My guess is that something else is overriding the value? but I can't see anything in the debugger.
     
  5. jonathanma_unity

    jonathanma_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    229
    Yes this is most likely what is happening.
    Another selector that is more specific is overriding the with value you set in USS.

    You should be able to see it in the debugger, if not that might be a bug but it's hard to tell without the project...