Skip to content

Tutorial: Toolbar

What you’ll build: a horizontal toolbar with a brand on the left, spacing in the middle, and two action buttons on the right.

┌──────────────────────────────────────────────────────────┐
│ My App [Settings] [Login] │
└──────────────────────────────────────────────────────────┘

What you’ll learn:

  • Row layout with mixed-size children
  • The “spacer” pattern — WidthFill() between siblings
  • Cross-axis centering for differently-sized buttons
  • Padding on the container

Build it

  1. Create a UI GameObject (GameObject → UI → Image, then remove the Image if you want a transparent toolbar).
  2. Add the AutoLayout component. Set:
    • Layout Type: Row
    • Width: Fill
    • Height: 48
    • Padding: 12 horizontal, 0 vertical
    • Gap: 8
    • Cross Axis Align: Center
  3. Add three children inside it:
    • Brand — Text “My App”, Width: TextSize, Height: TextSize
    • Spacer — empty GameObject with AutoLayout, Width: Fill
    • Settings button — see below
    • Login button — see below

For each button: a child GameObject with AutoLayout (Hug width, Hug height, Padding 12,8), an Image for background, and a TextMeshProUGUI child.

The Inspector is fine for one-off toolbars. The code approach pays off when you have many.

Try this next

Right-to-left support. Set .RTL() on the toolbar — the buttons end up on the left for Arabic/Hebrew layouts, no other changes needed.

Sticky shadow. Wrap the toolbar in a Column and add a thin Row beneath with a darker color — that’s your “shadow” / divider line.

Mobile breakpoint. Use .If(Screen.width < 600, b => b.Padding(8, 0)) to tighten the padding on narrow viewports.

Action overflow. When you have more buttons than fit, replace the trailing buttons with a Dropdown “More ⋮” menu.

See also

Docs for AutoLayout PRO v1.0.0 Changelog