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. |
- A drag of more than 8 pixels moves the pages with the pointer. A release past 30% of the width (the height when vertical), or a fast flick, changes the page; a shorter drag goes back. A vertical view ignores sideways drags, and a horizontal view ignores drags up and down.
- A click on a button in a page stays a click: the view takes the pointer only when a drag starts.
- The view takes focus. Left and Right (Up and Down when vertical), Home and End change the page. The gamepad directions change it too. The other arrow keys move the focus as usual.
- The automatic timer waits while the pointer is over the view or a drag is in progress, and starts again after each change.
- A new change ends the change in progress at once.
- The pages get the
tb-flip-view__pageclass when the view is attached, or onAddPageorRefresh. The sheet hides the pages that do not have--shown.
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.
AlignmentStart:SelectedIndexis the first shown page. The last position still fills the view, so 5 pages in a view of 3 have the positions 0, 1 and 2.AlignmentCenter:SelectedIndexis the page in the middle, and each page can be selected. The first and the last page have an empty place beside them.- A click on a page beside the selected one selects it, with a slide. A click on the selected page changes nothing. With
StepSizePage, the view goes to the position of the clicked page. StepSizeItem: the arrows, the keys, the gamepad directions, a drag and the timer move one page.StepSizePage: they move as many pages as the view shows. 7 pages in a view of 3 have the positions 0, 3 and 4: the last position still fills the view.- There is one dot for each position, not for each page.
GoToandSelectedIndextake a page index and go to the position of that page. SelectedPageand the classtb-flip-view__page--currentgive the selected page. The pages inside the view have--shown.- The change is always a slide.
FadeandCustomTransitionwork only with one page per view.Nonechanges at once. - With
Loop, the arrows, the keys and the timer go from the last position to the first: the pages slide back over all the pages. A drag stops at the ends.
Tips
- For a character select, use
alignment="Center"with an odditems-per-view, and style.tb-flip-view__page--current(a border or a largerscale) so that the user sees the selected card. - For a shelf of cards that moves a whole row at a time, use
alignment="Start"withstep-size="Page". - Give the view a height. The pages take the height of the view (the width when vertical).
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). |