scoop:scoop.ui.component:0.1.0
src/tabs/indicator.scoop
Selected production source · src/tabs/indicator.scoop
1
package scoop.ui.component3
import scoop.graphics.*4
import scoop.ui.*5
import scoop.ui.style.*7
internal class TabIndicatorProps(8
val selected: Boolean,9
val axis: FlexAxis,10
val theme: Theme,11
val enabled: Boolean12
)14
internal class TabIndicator(15
private val props: Props<TabIndicatorProps>,16
scope: ComponentScope17
): Element<Unit>(scope) {18
private var presence: Presence? = None19
public override fun onMount() {20
presence = Some(scope.presence(props.value.selected))21
}22
public override fun update(): UiInvalidation {23
val input = props.value24
val motion = input.theme.tokens.motion25
val transition = motion.resolve(motion.selection)26
presence!!.update(input.selected, Some(PresenceOptions(transition, transition)))27
return UiInvalidation.Layout28
}29
public override fun measure(context: MeasureContext, constraints: Constraints): LayoutResult<30
Unit31
> {32
val measured = context.measureChild(0L, constraints)33
context.placeChild(0L, Point(0.0, 0.0))34
return LayoutResult(measured, Unit)35
}36
public override fun scene(context: SceneContext, measured: Unit) {37
context.children()38
val input = props.value39
val progress = presence!!.snapshot.progress40
if (progress <= 0.0)41
return42
val density = input.theme.tokens.typography.action.fontSize / 14.043
val color = input.theme.tokens.palette.background.foreground44
val opacity =45
if (input.enabled)46
1.047
else48
input.theme.tokens.disabledOpacity49
val bounds =50
if (input.axis == FlexAxis.Horizontal)51
Rect(0.0, context.size.height + 3.0 * density, context.size.width, 2.0 * density)52
else53
Rect(54
if (context.layoutDirection == LayoutDirection.Ltr)55
context.size.width + 3.0 * density56
else57
-5.0 * density,58
0.0,59
2.0 * density,60
context.size.height61
)62
context.draw {63
paint -> paint.canvas.drawRect(64
bounds,65
Paint(color.withAlpha(color.alpha * progress * opacity))66
)67
}68
}69
}