UI Toolbox logoUI Toolbox

FlipView

FlipView in UIToolbox shows one page at a time. Each child is a page. It can also show several pages side by side, such as three cards of a character select.

<tb:FlipView name="tour" loop="true" transition="Fade" transition-duration="400" auto-advance="5" style="height: 220px;">
    <ui:VisualElement><ui:Label text="Welcome" /></ui:VisualElement>
    <ui:VisualElement><ui:Label text="Swipe" /></ui:VisualElement>
    <ui:VisualElement><ui:Button text="Start" /></ui:VisualElement>
</tb:FlipView>
var flip = root.Q<FlipView>("tour");
flip.SelectionChanged += (old, now) => Debug.Log($"page {old} > {now}");
flip.AddPage(new Label("One more"));
flip.GoTo(0);

// A transition of your own; the view clears translate, scale, rotate and opacity after the change
flip.CustomTransition = (from, to, t, direction) =>
{
    from.style.opacity = 1 - t;
    to.style.scale = new Scale(Vector2.one * (0.7f + 0.3f * t));
};
Member Description
Pages, PageCount, SelectedIndex (selected-index), SelectedPage The pages and the shown page. Setting SelectedIndex changes the page with no transition.
Next(), Previous(), GoTo(index, animate) Change the page.
ItemsPerView (items-per-view) The number of pages that show side by side. Default 1.
Spacing (spacing) The space in pixels between two pages when the view shows several pages. Default 0.
Alignment (alignment) Where the selected page stands when the view shows several pages: Start (default) or Center.
StepSize (step-size) How far one step goes when the view shows several pages: Item (default, one page) or Page (all the shown pages).
Loop (loop) Next on the last page goes to the first, and Previous on the first goes to the last.
Vertical (vertical) The pages go up and down: a drag up shows the next page, Slide moves the pages up or down, and Up and Down change the page. The arrows move to the top and the bottom, and the dots stand in a column on the right.
Transition (transition), TransitionDuration (transition-duration) Slide (default), Fade or None, and the length in milliseconds (300).
CustomTransition Action<from, to, t, direction> that replaces Transition. t goes from 0 to 1; direction is +1 for next and -1 for previous. For a slide of your own, read Vertical to choose the axis.
ShowArrows (show-arrows), ShowIndicators (show-indicators) The previous and next buttons and the dots. On by default.
AutoAdvance (auto-advance) Seconds between automatic page changes. 0 (default) turns it off. It always wraps to the first page.
AddPage(page), Refresh() AddPage adds a page and updates the dots. Call Refresh after you add or remove pages with Add or Remove while the view is in a panel.
IsTransitioning, SelectionChanged(old, now) True during a change or a drag. The event is sent after the change ends.

Several items per view

<tb:FlipView name="heroes" items-per-view="3" spacing="12" alignment="Center" style="height: 160px;">
    <ui:VisualElement class="hero-card"><ui:Label text="Knight" /></ui:VisualElement>
    <ui:VisualElement class="hero-card"><ui:Label text="Mage" /></ui:VisualElement>
    <ui:VisualElement class="hero-card"><ui:Label text="Rogue" /></ui:VisualElement>
    <ui:VisualElement class="hero-card"><ui:Label text="Cleric" /></ui:VisualElement>
</tb:FlipView>
var heroes = root.Q<FlipView>("heroes");
heroes.SelectionChanged += (old, now) => showHero(heroes.SelectedPage);

Set ItemsPerView above 1. Each page gets an equal part of the view (of the height when vertical), less the Spacing between the pages. The view sets the width of each page (the height when vertical) and its translate.

Tips

Styling

Class Element
tb-flip-view The view (flex column, grows). tb-flip-view--dragging is added during a drag.
tb-flip-view--vertical A vertical view: a flex row, the arrows at the top and the bottom center turned 90 degrees, and the dots in a column on the right.
tb-flip-view__stage, tb-flip-view__viewport The area of the pages and the arrows, and the clipped page area (surface-alt background, medium radius, accent border on focus).
tb-flip-view__page Each page: absolute, fills the viewport, hidden. --shown shows it; the selected page and the page coming in have it (with several items per view, the pages inside the view). --current marks the selected page.
tb-flip-view__arrow, --previous, --next The round previous and next buttons over the page (overlay background, accent on hover, faded when disabled).
tb-flip-view__indicators, tb-flip-view__dot, tb-flip-view__dot--selected The row of dots, a dot (8 px, border color), and the dot of the selected page (accent).