UI Toolbox logoUI Toolbox
Support

ScreenStack

A ScreenStack holds the screens of a menu as a stack. Only the top screen shows and takes input. A button pushes a screen on top of it and the new screen slides in; Back removes the top screen and the screen below comes back, with the focus where the user left it. Use it for a game menu that goes deeper, such as Main, Options, then Audio, Video or Controls.

The Options screen of a game menu, with Back in the headerThe Options screen of a game menu, with Back in the header

How to build a menu with screens:

  1. Add a ScreenStack and put a StackScreen in it for each screen. The first one is the root.
  2. Give each screen a screen-id and a title.
  3. In the click of a button, call Push with the id of the screen to open.
<tb:ScreenStack name="menu">
    <tb:StackScreen screen-id="main" title="Main">
        <ui:Button name="optionsButton" text="Options" />
    </tb:StackScreen>
    <tb:StackScreen screen-id="options" title="Options">
        <ui:Button name="audioButton" text="Audio" />
    </tb:StackScreen>
    <tb:StackScreen screen-id="audio" title="Audio" />
</tb:ScreenStack>
var menu = root.Q<ScreenStack>("menu");
root.Q<Button>("optionsButton").clicked += () => menu.Push("options");
root.Q<Button>("audioButton").clicked += () => menu.Push("audio");

B on a gamepad, Escape on a keyboard and the Back button of the header (a click or a tap) all call Pop. The d-pad, the left stick, the arrow keys and Tab only move the focus. They never close a screen.

Member Description
Push(screen) Puts a screen on top. The screen can be any VisualElement. The screen below keeps its place and its focus.
Push(screenId) Puts the screen with this screen-id on top and returns true. Returns false when no screen has the id.
Pop() Removes the top screen and returns true. At the root it does nothing and returns false.
PopTo(screen) and PopTo(screenId) Pops until this screen is on top. Returns false when the screen is not in the stack.
PopToRoot() Pops until only the root is left.
Replace(screen) Swaps the top screen for another one, with no Back step for the old one.
Count The number of screens in the stack, the root included.
Top The screen on top, or null when the stack is empty.
Root The first screen.
ScreenAt(index) The screen at an index of the stack, from the root.
IsAnimating true while a screen moves.
Pushed Raised after a screen was pushed, with the screen.
Popped Raised after a screen was popped, with the screen that went away.
BackAtRoot Raised when the user presses Back and only the root is left.
Transition (transition) Slide (the default), Fade or None.
TransitionDuration (transition-duration) The time of a move in milliseconds. Default 250. 0 turns the move off.
ShowHeader (show-header) Shows a header with the Back button and the title of the top screen. On by default.
ReduceMotion (reduce-motion) Turns the move off for this stack. Windows animations that are off do the same.
BackButton The Back button of the header.
StackScreen.ScreenId (screen-id) The name that Push(screenId) looks for.
StackScreen.Title (title) The text in the header while the screen is on top. A key of ToolboxText shows its translation.

Tips:

Styling

Class Element
tb-screen-stack The stack.
tb-screen-stack__header The row with the Back button and the title.
tb-screen-stack__back The Back button.
tb-screen-stack__title The title.
tb-screen-stack__screens The element that holds the screens.
tb-screen-stack--slide and tb-screen-stack--fade On the stack, for the transition.
tb-screen-stack--animating On the stack while a screen moves.
tb-screen A screen.
tb-screen--hidden A screen that is not on top. It is not displayed.
tb-screen--above and tb-screen--below The start and end poses of a screen in a move.

To change a move, set transition-duration, transition-timing-function or the poses of tb-screen--above and tb-screen--below in your own style sheet.