TimelineScale

class TimelineScale(val duration: Duration, val pixelsPerSecond: Float)(source)

The mapping between composition time and content pixels at one zoom level.

The ruler, the tiles, the playhead and the trim handles all read their geometry from this, so a strip that scrolls cannot drift out of agreement with what is drawn over it.

Content pixels run from zero at the start of the composition to contentWidthPx at its end, which is wider than the viewport at any zoom the whole strip does not fit in. Subtract the scroll offset to reach viewport pixels.

val scale = TimelineZoom.fitting(duration, viewportWidthPx).scaleFor(duration)

Canvas(Modifier.fillMaxSize()) {
val x = scale.xOf(marker) - scrollPx()
if (x in 0f..size.width) {
drawLine(color, Offset(x, 0f), Offset(x, size.height))
}
}

Constructors

Link copied to clipboard
constructor(duration: Duration, pixelsPerSecond: Float)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

How wide the whole timeline is, in content pixels.

Link copied to clipboard

How much composition time the timeline covers.

Link copied to clipboard

How wide one second of that is drawn.

Functions

Link copied to clipboard
fun tickInterval(minSpacingPx: Float): Duration

How far apart ruler ticks should sit, as the smallest step from TICKS that draws at least minSpacingPx apart.

Link copied to clipboard
fun timeAt(contentX: Float): Duration

The composition time drawn at contentX, clamped into Duration.ZERO..duration .

Link copied to clipboard
fun widthOf(span: Duration): Float

How wide span is drawn, in content pixels.

Link copied to clipboard

The same zoom over duration.

Link copied to clipboard
fun withPixelsPerSecond(pixelsPerSecond: Float): TimelineScale

The same timeline drawn at pixelsPerSecond.

Link copied to clipboard
fun xOf(time: Duration): Float

Where time is drawn, in content pixels, clamped into 0f..contentWidthPx .