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

Question Button text size in % doesn't work

Discussion in 'UI Toolkit' started by aganm, Jan 12, 2021.

  1. restonic4

    restonic4

    Joined:
    Jun 10, 2022
    Posts:
    1
  2. cnsjjj

    cnsjjj

    Joined:
    Aug 13, 2022
    Posts:
    21
    +1 Any update?
     
  3. waferltd

    waferltd

    Joined:
    Mar 26, 2018
    Posts:
    2
    Why do many Unity features have a gotcha. Is there no QA process at Unity at the moment?
     
  4. roguethink

    roguethink

    Joined:
    Oct 4, 2012
    Posts:
    3
    +1 any update?
     
    GDevTeam likes this.
  5. GDevTeam

    GDevTeam

    Joined:
    Feb 14, 2014
    Posts:
    90
  6. pin72

    pin72

    Joined:
    May 3, 2020
    Posts:
    1
    This actually works really well. Thanks.
     
    GDevTeam likes this.
  7. GDevTeam

    GDevTeam

    Joined:
    Feb 14, 2014
    Posts:
    90
    I also set the Match field to 0.5.
     
  8. curbol

    curbol

    Joined:
    Oct 29, 2015
    Posts:
    7
    +1 This is the #1 biggest issue for me with UITK!
     
  9. neoRiley

    neoRiley

    Joined:
    Dec 12, 2008
    Posts:
    148
    So, after seeing this thread and another about maintaining Aspect Ratio, I experimented with both and came up with a fairly solid solution - AspectRatioPanel.cs:

    AspectRatioPanel.gif

    • Can maintain aspect ratio or allow for resizing with parent or setting the width/height as you normally would
    • Let's you add a Label object
    • Resizes font with parent based on Font Scale setting
    • Attempts to scale border radius with the scale of the panel
    I would love some feedback and improvements on the code. This was my first attempt at extending a VisualElement to this extent and learned a ton.

    AspectRatioPanel.cs GitHub

    [UPDATE 7/12/2023]
    Added the ability to set an aspect ratio, and tie it to the parent's width or height if need be. It will resize with the parent's height or width and maintain the aspect ratio

    [UPDATE 7/12/2023]
    Fixed horizontal sizing with parent.

    [UPDATE 7/13/2023]
    I just realized I hard-coded Position properties to be "Relative". Removed.
    Also, as a tip - if you want button functionality and resizable text using this:
    1. Add Button component
    2. Set it's text to "" (blank)
    3. Add AspectRatioPanel as a child to the button
    4. Uncheck "Maintain Aspect Ratio"
    5. Tick "Add Label"
    6. Set your text and font Scale

    Done.

    [UPDATE 7/16/2023]
    - Fixed recursion error / warning about redrawing the component.
    - Fixed widht/height settings when selecting to MaintainAspectRatio

    2023-07-12_14-48-27.gif

    Have a bandit day!
     
    Last edited: Jul 16, 2023
  10. Xaragame

    Xaragame

    Joined:
    Jul 3, 2022
    Posts:
    3
    UNITY, FOR CHRIST'S SAKE, ADD THIS IN ALREADY, HOW DOES YOUR UI SYSTEM SUCK WORSE THAN ROBLOX
     
  11. CreativePrismStudio

    CreativePrismStudio

    Joined:
    Nov 16, 2017
    Posts:
    7
    +1 for % text size support.

    I found UI Toolkit was super intuitive and thought it was going to save me a lot of time, but now I have to find a workaround for text size...
     
  12. ZOMGbies

    ZOMGbies

    Joined:
    Sep 6, 2015
    Posts:
    6
    ™ ...

    Can you not just like.... force the UGUI/TMP logic for it to have min max? This would seem like a mere oversight if we were still in 2021. But it's closer to 2024 and I don't know how to explain UI tools not being able to handle text.

    Mainly I'm just salty that the new and better way is not necessarily better.
     
  13. TomTheMan59

    TomTheMan59

    Joined:
    Mar 8, 2021
    Posts:
    302
    I don't know why everyone wants this? Am I missing something? All you do is set your reference resolution in the panel settings and you done.
     
  14. dlorre

    dlorre

    Joined:
    Apr 12, 2020
    Posts:
    700
    You want this if you want a responsive display.
     
  15. TomTheMan59

    TomTheMan59

    Joined:
    Mar 8, 2021
    Posts:
    302
    Like I mentioned, reference resolution is exactly the solution for a responsive display. I have my UI setup that way and it works perfectly fine.
     
  16. dlorre

    dlorre

    Joined:
    Apr 12, 2020
    Posts:
    700
    It does not make sense if you want landscape and portrait orientation.
     
  17. TomTheMan59

    TomTheMan59

    Joined:
    Mar 8, 2021
    Posts:
    302
    Fair point.
     
  18. svenneve

    svenneve

    Joined:
    May 14, 2013
    Posts:
    61
    So, we're two years later, and this still doesn't work (among a whole other bunch of basic features)

    I tried using it on a new project and love a lot about it, but I fail to see how UI Toolkit and UI Builder are anywhere but in the bare minimum alpha stage at this point (a tech demo of an idea might be a nice way of putting it), and at the snail pace Unity these days works, I'm guessing UI Toolkit won't be production ready for at least another 5 years.
     
  19. ivank

    ivank

    Joined:
    Nov 16, 2013
    Posts:
    97
    Just one maybe relevant info regarding (rather unbelievable) fact that setting button text size in %, while promised and essential, *still* does not work:
    This message seems to reveal that in Unity 2023.2-3 a substantial change in UI text "engine" is under way, what may explain why Unity has not bothered with this feature so far, and what may provide some hope for the future...well, years perhaps :)
     
    dlorre likes this.
  20. True12Acorns

    True12Acorns

    Joined:
    Jan 31, 2022
    Posts:
    4
  21. wf_tmro

    wf_tmro

    Joined:
    Oct 20, 2022
    Posts:
    1
    I have a compilation error:

    'StyleLength' does not contain a definition for 'Scale' and no accessible extension method 'Scale' accepting a first argument of type 'StyleLength' could be found (are you missing a using directive or an assembly reference?)
     
  22. TerabyteTim

    TerabyteTim

    Joined:
    Oct 20, 2011
    Posts:
    115
    Love that UI Toolkit is now the default recommended UI, but still doesn't have feature parity with Canvas YEARS LATER