Search Unity

How to fit Buttons to text content?

Discussion in 'UI Toolkit' started by Sarkahn, Apr 13, 2020.

  1. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    Hello, I've been trying to figure out how to get this style of layout using UIToolkit:

    5L3MjpFNiG.gif

    Namely, a list of aligned buttons in a container that "automatically" shrink to fit their respective text content, rather than expanding horizontally to fit the width of the whole container. I've tried messing with various combinations of layout options but I can't seem to figure it out. Is there a simple way to make this work? Preferably without resorting to C# code.
     
  2. jonathanma_unity

    jonathanma_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    229
    Hi Sarkahn,

    What you are looking for is the align-items style properties. Set "align-items: center;" on the buttons container.
     
    Sarkahn likes this.
  3. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    Can't believe I missed that, but it works perfectly, thanks!