Menus with keyboard and gamepad
This tutorial takes about fifteen minutes. You need Turian and the .NET SDK installed, and you should have finished the getting-started tutorial first. You will build a main menu from a .ui document and a C# controller. The menu uses the Game UI brick, so the navigation that makes it work with a keyboard and a gamepad comes for free. For the reference, see Game UI.
1. Create the project
From a terminal, create a project and add the UI brick:
turian-cli new MenuDemo
turian-cli brick add org.mass4.turian.ui --project MenuDemo
turian-studio --project MenuDemo
A new project only ships the renderer, so the UI brick is added explicitly. The brick add command reports Installed org.mass4.turian.ui followed by the version it installed when it succeeds.
2. Write the menu document
Create Assets/UI/menu.ui:
<?xml version="1.0" encoding="utf-8"?>
<UI xmlns="https://turian.dev/ui" controller="Usercode.MainMenu" initial-focus="play" cancel="OnBack">
<Style src="Assets/UI/theme.pss" />
<VisualElement name="root" class="screen">
<Label class="title">Main Menu</Label>
<Button name="play" class="menu-button" click="OnPlay">Play</Button>
<Button name="options" class="menu-button" click="OnOptions">Options</Button>
<Button name="continue" class="menu-button" enabled="false">Continue</Button>
<Button name="quit" class="menu-button" click="OnQuit">Quit</Button>
<Label name="status" class="status" binding-text="{Status}" />
</VisualElement>
</UI>
Each Button raises its click handler with the mouse, and also when it has keyboard or gamepad focus and you press Submit. initial-focus="play" gives the keyboard and gamepad a starting point, and cancel="OnBack" names the handler for Cancel. The Continue button is disabled with enabled="false", so navigation skips it.
Create Assets/UI/theme.pss next to it. The stylesheet uses PSS syntax, which is property = value;:
$bg = #12151d;
$surface = #1f2430;
$surface-2 = #2a3140;
$accent = #4a90e2;
$ink = #e8eaed;
$ink-muted = #9aa0a6;
.screen {
flex-direction = column;
align-items = center;
justify-content = center;
gap = 16;
padding = 24;
background-color = $bg;
}
.title { color = $ink; font-size = 32; }
.status { color = $ink-muted; font-size = 14; }
.menu-button {
width = 280;
height = 48;
color = $ink;
font-size = 18;
background-color = $surface-2;
border-radius = 8;
align-items = center;
justify-content = center;
}
.menu-button:hover { background-color = $accent; }
.menu-button:focus { outline-color = #62e6ff; outline-width = 3; outline-offset = 2; }
.menu-button:disabled { background-color = $surface; color = $ink-muted; }
The :focus state styles the control that keyboard and gamepad navigation currently selects, so players can see where they are.
3. Write the controller
Create Assets/MainMenu.cs. Public properties are bound into the document, and public parameterless void methods are the event handlers:
namespace Usercode;
using Turian.Engine.UI;
public sealed class MainMenu : UiController
{
/// <summary>Bound to the status label in menu.ui.</summary>
public string Status { get; private set; } = "Use the mouse, Tab, the arrow keys or a gamepad.";
public void OnPlay() => Status = "Play pressed.";
public void OnOptions() => Status = "Options pressed.";
public void OnBack() => Status = "Back pressed.";
public void OnQuit() => Application.Quit();
}
Application.Quit() asks the game to end its loop. In Studio's Play Mode the request does nothing, so Quit only has an effect in a standalone build.
4. Put the menu in the scene
In the Scene Tree, add an empty node and name it Menu. Select it, click Add Component in the Inspector and choose UI → UI Document. Set its Document field to Assets/UI/menu.ui. The default mode is a screen-space overlay, so the menu draws over the scene.
5. Use the mouse
Press F5. The menu is drawn over the scene, and Play has the focus outline. Click Options: the status line changes to "Options pressed." Click Play: it changes to "Play pressed."

Press F5 again to stop. Play Mode runs on a copy of the scene, so your authored scene is unchanged.
6. Use the keyboard
Click inside the Game view so it receives the keyboard, then:
- Tab and Shift+Tab move the focus in document order.
- The arrow keys move the focus to the nearest button in that direction.
- Enter or Space clicks the focused button.
Tab through the menu and press Enter on Options: the status line updates, and the focus stays on that button. The disabled Continue button is skipped.
In Studio, Escape gives the keyboard back to Studio, as described in the getting-started tutorial, so test Cancel with a gamepad or in a standalone build.
7. Use a gamepad
Studio's Play Mode does not receive gamepad input yet, so test this step in a standalone build. Export the game, or choose Project → Build & Run, which opens the game in its own window:
turian-cli export MenuDemo
With a gamepad connected, the D-pad or the left stick moves the focus, the bottom face button (A on an Xbox layout) submits, and the right face button (B) cancels. Cancel should set the status line to "Back pressed." while the menu has focus. Choose Quit to close the game.
Next steps
- Input covers the input system the UI brick reads from.
- Game UI lists every element, styling property and binding mode.
- Each control also accepts
focus-left,focus-right,focus-up,focus-down,focus-nextandfocus-previous, which name the element to focus next. Use them when automatic navigation picks the wrong neighbour, for example<Button name="play" focus-down="options" click="OnPlay">Play</Button>. - Save and resume adds a score that survives a restart.