UI Toolbox logoUI Toolbox
Support

Timeline

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

Dialogue, camera, music and event tracks with clips and a red playheadDialogue, camera, music and event tracks with clips and a red playhead

Video tutorial: Timeline. All videos: Video tutorials.

<tb:Timeline
    name="edit"
    duration="60"
    time-format="0.#'s'"
    style="height: 150px;">
    <tb:TimelineTrack text="Video">
        <tb:TimelineItem text="Intro" start="0" duration="8" />
        <tb:TimelineItem
            text="Scene A"
            start="8"
            duration="17"
            color="#3CB371" />
    </tb:TimelineTrack>
    <tb:TimelineTrack text="Events">
        <!-- no duration: a marker -->
        <tb:TimelineItem text="Cut" start="8" />
    </tb:TimelineTrack>
</tb:Timeline>
var timeline = root.Q<Timeline>("edit");
timeline.GetTrack("Events").AddMarker("Fade", 25);
timeline.ItemReached += item =>
    Debug.Log($"{item.Text} at {item.Start}");
timeline.SelectionChanged += range => Debug.Log(range);
timeline.Play();
Member Description
TimelineItem.Text (text), 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.
--tb-item-color In the style of an item: the fill of an item with a clear Color, for example .tb-timeline__item.build { --tb-item-color: var(--tb-color-success); }. The order is Color, then --tb-item-color, then the color of the track.
TimelineItem.End, IsMarker, DisplayColor, Track, Timeline The end time, the marker test, the drawn color, and the parents.
TimelineTrack.Text (text), Color (color), Items, AddItem, AddMarker The header text, the item color (clear takes the theme chart color --tb-chart-1 to --tb-chart-8 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), ViewDuration (view-duration, 0), TimeFormat (time-format, "0.##"), FormatTime The length of the ruler, the initial duration shown, 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), TrackAt(worldPosition) The ruler tick times now shown, the time at a panel position, and the track there (null outside the shown tracks). A drop or a double-click on a lane uses them to add an item where the pointer is.
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.
ItemEdited, TimelineEdit, TimelineEditKind Sent after each edit by the user: a move (Move), a resize (Resize) or a removal (Remove). The TimelineEdit holds the Timeline, the Item and the Kind, and the track, the place in the track, the start and the duration before the edit (OldTrack, OldIndex, OldStart, OldDuration) and after it (NewTrack, NewIndex, NewStart, NewDuration; a removal gives a null NewTrack and a NewIndex of -1). Undo() and Redo() put the item in either place, so an editor keeps the edits for its undo history.
DeleteSelectedItem Removes the selected item, as Delete and Backspace do with EditItems, and sends ItemEdited. Returns false when no item is selected.
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}";

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

In the examples

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 (--tb-chart-text, white by default, ellipsis).
tb-timeline__overlay The grid lines, the range fill and the playhead, over the ruler and the lanes.

The DirectorDemo scene uses a timeline with edit-items as the script of a video, on six tracks: the playhead follows a VideoView, and a drag on the ruler seeks the video. A palette adds items by a click or a drop (TimeAt), a double-click on an empty lane adds one there (TrackAt), a PropertyGrid edits the selected item, and ItemEdited feeds an undo history. See Video director.