Resizing a buttons to text, then resizing panel to size of buttons

Hi

I have a dialog system where you make choices.

  • Those choices are buttons (with regular text component)
  • There are a variable number of choices/buttons (2-5). Unused buttons are disabled as required.
  • The buttons are in a panel with a vertical layout group.
  • The panel has a texture (speed bubble)

What I would like

  • Have each button expand to the width of the largest text.
  • Have the panel expand to the width of the buttons (so there is no extra space as shown in the screen shot below)
  • Resize the panels height based on the number of buttons

I want to avoid this (extra white space after the longest line):

9876807--1424319--upload_2024-6-6_12-49-46.png

I’m unsure how to do this.

One attempt

  • Vertical Layout Group on Panel. Expand Width not checked.
  • Content Size Fitter on Panel set to Preferred.
  • Each Btn has a Layout controller with the min width set.

Is anyone able to point me in the right direction here?

Thanks

9876807--1424319--upload_2024-6-6_12-49-46.png

TMP_Text.GetPreferredValues(str)