scoop:scoop.ui.component:0.1.0
src/navigation_menu/chevron.scoop
Selected production source · src/navigation_menu/chevron.scoop
1
package scoop.ui.component3
import scoop.graphics.*4
import scoop.surface.*5
import scoop.ui.*7
internal class NavChevronProps(8
val opened: Boolean,9
val enabled: Boolean,10
val size: Double,11
val color: Color,12
val transition: AnimationSpec?,13
val vertical: Boolean14
)16
internal class NavChevron(17
private val props: Props<NavChevronProps>,18
scope: ComponentScope19
): Element<Unit>(scope) {20
private var progress: Animatable<Double>? = None21
private var chevron: Path? = None22
private var visible = false23
public override fun onMount() {24
progress =25
Some(26
scope.animation(27
if (props.value.opened)28
1.029
else30
0.031
)32
)33
chevron =34
Some(35
scope.resource {36
path {37
moveTo(Point(6.0, 9.0));38
lineTo(Point(12.0, 15.0));39
lineTo(Point(18.0, 9.0))40
}41
}42
)43
}44
public override fun update(): UiInvalidation {45
changeProgress(46
progress!!,47
if (props.value.opened)48
1.049
else50
0.0,51
if (props.value.enabled)52
props.value.transition53
else54
None55
)56
return UiInvalidation.Layout57
}58
public override fun measure(context: MeasureContext, constraints: Constraints): LayoutResult<59
Unit60
> =61
LayoutResult(62
LayoutMetrics(constraints.constrain(Size(props.value.size, props.value.size))),63
Unit64
)65
public override fun scene(context: SceneContext, measured: Unit) {66
val input = props.value67
val bounds = Rect(0.0, 0.0, context.size.width, context.size.height)68
val turn =69
progress!!.value *70
3.141592653589793 +71
if (!input.vertical)72
0.073
else74
if (context.layoutDirection == LayoutDirection.Rtl)75
1.570796326794896676
else77
-1.570796326794896678
context.draw {79
paint ->80
visible = loadingVisible(paint.canvas, bounds, input.color.alpha)81
if (visible)82
paint.canvas.withState {83
canvas ->84
canvas.scale(bounds.width / 24.0, bounds.height / 24.0)85
canvas.translate(12.0, 12.0);86
canvas.rotate(turn);87
canvas.translate(-12.0, -12.0)88
canvas.drawPath(chevron!!, Paint(input.color, PaintingStyle.Stroke, 2.0))89
}90
}91
loadingParticipation(context, progress!!, visible)92
}93
}