Scoop API

scoop:scoop.ui.style:0.1.0

src/theme/interaction_effects.scoop

Selected production source · src/theme/interaction_effects.scoop

1package scoop.ui.style
3import scoop.graphics.*
5internal fun surfaceShadows(part: SurfacePart, visual: InteractionVisual): Array<BoxShadow> {
6 val hovered = part.hoverShadows ?: return part.shadows
7 if (!visual.enabled) return part.shadows
8 val amount = themeProgress(visual.hoverProgress, visual.hovered) *
9 (1.0 - themeProgress(visual.pressProgress, visual.pressed))
10 if (amount == 0.0) return part.shadows
11 if (amount == 1.0) return hovered
12 return Array<BoxShadow>(part.shadows.size + hovered.size) { index ->
13 val normal = index < part.shadows.size
14 val shadow = if (normal) part.shadows[index] else hovered[index - part.shadows.size]
15 val alpha = if (normal) 1.0 - amount else amount
16 BoxShadow(
17 shadow.offset, shadow.sigmaX, shadow.sigmaY,
18 shadow.color.withAlpha(shadow.color.alpha * alpha)
19 )
20 }
23internal fun markerFocusOutset(
24 size: Double,
25 appearance: MarkerAppearance,
26 focus: OutlineStyle,
27 validation: OutlineStyle,
28 corners: StyleValue<Corners> = StyleValue.Inherit
29): Double {
30 val base = outlineOutset(focus, validation)
31 val layer = appearance.stateLayer ?: return base
32 themeLength(layer.size)
33 val focusOutset = when (corners) {
34 case Inherit -> focus.outset
35 case Set(_) -> 0.0
36 }
37 return themeMax(base, themeMax(0.0, (layer.size - size) / 2.0) + focusOutset)
40private fun markerLayerCircle(bounds: Rect, layer: MarkerStateLayer): Circle = Circle(
41 Point(bounds.x + bounds.width / 2.0, bounds.y + bounds.height / 2.0),
42 themeMax(layer.size, themeMax(bounds.width, bounds.height)) / 2.0
45internal fun markerFocusOutline(
46 outline: RoundedOutline,
47 appearance: MarkerAppearance,
48 visual: InteractionVisual,
49 corners: StyleValue<Corners> = StyleValue.Inherit
50): RoundedOutline {
51 val layer = appearance.stateLayer ?: return outline
52 val inheritedCorners = when (corners) {
53 case Inherit -> true
54 case Set(_) -> false
55 }
56 if (visual.invalid || !inheritedCorners) return outline
57 val circle = markerLayerCircle(outline.bounds, layer)
58 return roundTheme(circle.bounds, circle.radius)
61internal fun markerLayerGeometry(
62 bounds: Rect,
63 appearance: MarkerAppearance,
64 visual: InteractionVisual,
65 selection: Double,
66 validation: OutlineStyle
67): MarkerStateLayerGeometry? {
68 val layer = appearance.stateLayer ?: return None
69 if (!visual.enabled) return None
70 val color = mixThemeColor(
71 layer.empty.resolve(visual),
72 layer.selected.resolve(visual),
73 selection
74 )
75 if (color.alpha == 0.0) return None
76 val error = validation.borderColor ?: validation.color
77 return Some(
78 MarkerStateLayerGeometry(
79 markerLayerCircle(bounds, layer),
80 if (visual.invalid) error.withAlpha(error.alpha * color.alpha) else color
81 )
82 )