scoop:scoop.ui.style:0.1.0
src/theme/interaction_effects.scoop
Selected production source · src/theme/interaction_effects.scoop
1
package scoop.ui.style3
import scoop.graphics.*5
internal fun surfaceShadows(part: SurfacePart, visual: InteractionVisual): Array<BoxShadow> {6
val hovered = part.hoverShadows ?: return part.shadows7
if (!visual.enabled) return part.shadows8
val amount = themeProgress(visual.hoverProgress, visual.hovered) *9
(1.0 - themeProgress(visual.pressProgress, visual.pressed))10
if (amount == 0.0) return part.shadows11
if (amount == 1.0) return hovered12
return Array<BoxShadow>(part.shadows.size + hovered.size) { index ->13
val normal = index < part.shadows.size14
val shadow = if (normal) part.shadows[index] else hovered[index - part.shadows.size]15
val alpha = if (normal) 1.0 - amount else amount16
BoxShadow(17
shadow.offset, shadow.sigmaX, shadow.sigmaY,18
shadow.color.withAlpha(shadow.color.alpha * alpha)19
)20
}21
}23
internal fun markerFocusOutset(24
size: Double,25
appearance: MarkerAppearance,26
focus: OutlineStyle,27
validation: OutlineStyle,28
corners: StyleValue<Corners> = StyleValue.Inherit29
): Double {30
val base = outlineOutset(focus, validation)31
val layer = appearance.stateLayer ?: return base32
themeLength(layer.size)33
val focusOutset = when (corners) {34
case Inherit -> focus.outset35
case Set(_) -> 0.036
}37
return themeMax(base, themeMax(0.0, (layer.size - size) / 2.0) + focusOutset)38
}40
private 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.043
)45
internal fun markerFocusOutline(46
outline: RoundedOutline,47
appearance: MarkerAppearance,48
visual: InteractionVisual,49
corners: StyleValue<Corners> = StyleValue.Inherit50
): RoundedOutline {51
val layer = appearance.stateLayer ?: return outline52
val inheritedCorners = when (corners) {53
case Inherit -> true54
case Set(_) -> false55
}56
if (visual.invalid || !inheritedCorners) return outline57
val circle = markerLayerCircle(outline.bounds, layer)58
return roundTheme(circle.bounds, circle.radius)59
}61
internal fun markerLayerGeometry(62
bounds: Rect,63
appearance: MarkerAppearance,64
visual: InteractionVisual,65
selection: Double,66
validation: OutlineStyle67
): MarkerStateLayerGeometry? {68
val layer = appearance.stateLayer ?: return None69
if (!visual.enabled) return None70
val color = mixThemeColor(71
layer.empty.resolve(visual),72
layer.selected.resolve(visual),73
selection74
)75
if (color.alpha == 0.0) return None76
val error = validation.borderColor ?: validation.color77
return Some(78
MarkerStateLayerGeometry(79
markerLayerCircle(bounds, layer),80
if (visual.invalid) error.withAlpha(error.alpha * color.alpha) else color81
)82
)83
}