UI Toolbox logoUI Toolbox

Timeline

Timeline in UIToolbox shows TimelineTrack rows of TimelineItem spans and markers on a time ruler, with a playhead.

Video tutorial: Timeline. All videos: Video tutorials.

<tb:Timeline name="edit" duration="60" time-format="0.#'s'" style="height: 150px;">
    <tb:TimelineTrack label="Video">
        <tb:TimelineItem label="Intro" start="0" duration="8" />
        <tb:TimelineItem label="Scene A" start="8" duration="17" color="#3CB371" />
    </tb:TimelineTrack>
    <tb:TimelineTrack label="Events">
        <tb:TimelineItem label="Cut" start="8" />   <!-- no duration: a marker -->
    </tb:TimelineTrack>
</tb:Timeline>
var timeline = root.Q<Timeline>("edit");
timeline.GetTrack("Events").AddMarker("Fade", 25);
timeline.ItemReached += item => Debug.Log($"{item.Label} at {item.Start}");
timeline.SelectionChanged += range => Debug.Log(range);
timeline.Play();
Member Description
TimelineItem.Label (label), Start (start), Duration (duration), Color (color) The name, the start time, the length (0 makes a marker), and the fill (clear takes the track color). A change moves the item.
TimelineItem.End, IsMarker, DisplayColor, Track, Timeline The end time, the marker test, the drawn color, and the parents.
TimelineTrack.Label (label), Color (color), Items, AddItem, AddMarker The header text, the item color (clear takes the PieChart.Palette color by position), and the items.
Tracks, Items, AddTrack, GetTrack, Refresh The tracks and all their items. Call Refresh() after you add or remove tracks or items with Add or Remove.
ScrollToTrack Scrolls the tracks so that the track shows. Tracks that do not fit the height scroll up and down under the ruler.
Duration (duration, 60), TimeFormat (time-format, "0.##"), FormatTime The length of the ruler, and the number format of the ruler and the tooltips.
TimeFormatter, TickFormatter Functions that make the text of a time. TimeFormatter is for the tooltips, FormatTime and the ruler; TickFormatter is for the ruler only. Null (the default) uses TimeFormat. See Days and hours.
TickSteps (tick-steps), MajorStep (major-step, 0) The steps that the ruler can use between two ticks, and the step of the major ticks. Without TickSteps the ruler uses round decimal steps (1, 2, 5, 10).
Playhead (playhead), PlayheadMoved The playhead time, from 0 to Duration.
Play, Pause, IsPlaying, PlayingChanged, PlaybackSpeed (playback-speed, 1), Loop (loop) Playback moves the playhead in real time. At the end it stops, or goes back to 0 with Loop. Play at the end starts over. A zoomed view turns the page when the playhead runs off it.
ItemReached Sent during playback when the playhead reaches the start of an item.
Selection, SetSelection, ClearSelection, SelectionChanged The selected range as (start, end), or null.
SelectedItem, SelectItem, ItemSelected The selected item, or null.
ViewStart, ViewEnd, IsZoomed, SetView, ResetView, ViewChanged The shown range. It stays inside 0 to Duration.
TickTimes, TimeAt(worldPosition) The ruler tick times now shown, and the time at a panel position.
Interactive, ZoomPan (zoom-pan) Clicks, drags and keys; the wheel and the pan. On by default.
EditItems (edit-items), ItemChanged Drags move and resize the items. Off by default. ItemChanged is sent once after a drag that changed the start, the length or the track; a change by code does not send it.
Snap (snap, 0), SnapToItems (snap-to-items, true) A dragged edge goes to a multiple of Snap (0 turns the step off). With SnapToItems, an edge within 8 pixels of the playhead or of the edge of another item goes to it first.

Days and hours

The time of a timeline is a number. To show a schedule, let one unit be one hour and give the ruler the steps of a clock.

<tb:Timeline name="week" duration="168" tick-steps="0.5,1,2,3,6,12,24" major-step="24" snap="0.5" edit-items="true" />
string[] days = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
string day(float hours) => days[(int)(hours / 24) % 7];
string clock(float hours) => $"{(int)hours % 24:00}:{(int)(hours * 60) % 60:00}";

week.TimeFormatter = hours => $"{day(hours)} {clock(hours)}";               // tooltips: "Tue 14:30"
week.TickFormatter = hours => hours % 24 == 0 ? day(hours) : clock(hours);  // ruler: "Tue", "06:00", "12:00"
week.SetView(24, 48);   // show Tuesday

Styling

Class Element
tb-timeline The timeline (column, grows; accent border when it has focus). --tb-timeline-playhead, --tb-timeline-selection, --tb-timeline-grid and --tb-timeline-grid-major set the overlay colors. tb-timeline--playing is added during playback.
tb-timeline__ruler The ruler row (surface-alt background).
tb-timeline__header The ruler corner and each track header. They share a width (90 px), so the lanes line up with the ruler.
tb-timeline__ruler-lane The tick area of the ruler. Its text color sets the tick lines.
tb-timeline__tick-label, --major A ruler time (small muted text); a major tick (bold, text color).
tb-timeline__tracks The column of tracks: a vertical ScrollView. The scroll bar rules of the toolbox apply to it.
tb-timeline__track A track row (30 px).
tb-timeline__lane The item area of a track. It clips the items.
tb-timeline__item, --marker, --selected, --dragging A span (the script sets its position and color); a marker (a diamond on its time, name in the tooltip); the selected item (text-color border); the item during a drag (0.8 opacity).
tb-timeline__item-label The name on a span (white, ellipsis).
tb-timeline__overlay The grid lines, the range fill and the playhead, over the ruler and the lanes.