scoop:scoop.ui.style:0.1.0
src/cache/geometry.scoop
Selected production source · src/cache/geometry.scoop
1
package scoop.ui.style3
import scoop.graphics.*4
import scoop.ui.LayoutDirection6
internal struct OutlineInput(7
val outline: RoundedOutline,8
val insets: Insets,9
val partitions: Boolean10
)12
internal class DecorationPaths(13
val outline: Path,14
val border: Path?,15
val regions: Array<Path>16
) : Closeable {17
public override fun close() {18
var failure = cleanupStyle(None) { outline.close() }19
failure = cleanupStyle(failure) { border?.close() }20
for (region in regions)21
failure = cleanupStyle(failure) { region.close() }22
throwStyle(failure)23
}24
}26
internal class DecorationGeometry : Closeable {27
private var input: OutlineInput? = None28
private var current: DecorationPaths? = None30
fun update(31
bounds: Rect,32
style: Style,33
direction: LayoutDirection = LayoutDirection.Ltr,34
hasBackdrop: Boolean = false35
): DecorationPaths? {36
val edges = physicalEdges(style, direction)37
val insets = edges.insets38
val outline = RoundedOutline(bounds, style.corners.resolve(direction)).normalized()39
val hasBorder = insets.left >40
0.0 ||41
insets.top >42
0.0 ||43
insets.right >44
0.0 ||45
insets.bottom >46
0.047
val background = when (style.background) {48
case Some(_) -> true;49
case None -> false50
}51
if (!background &&52
!hasBackdrop &&53
!hasBorder &&54
style.boxShadows.size ==55
0L &&56
!style.clipContent57
) {58
close()59
return None60
}61
val nextInput = OutlineInput(outline, insets, hasBorder && edges.uniformColor() == None)62
if (input == Some(nextInput)) return current63
val next = decorationPaths(nextInput, edges)64
val previous = current65
current = Some(next)66
input = Some(nextInput)67
previous?.close()68
return Some(next)69
}70
public override fun close() {71
val previous = current72
current = None73
input = None74
previous?.close()75
}76
}78
private fun decorationPaths(input: OutlineInput, edges: BorderEdges): DecorationPaths {79
val outer = input.outline80
val widths = input.insets81
val owned = ArrayList<Path>()82
try {83
val outline = path { addRoundRect(outer.bounds, outer.radii) }84
owned.add(outline)85
val ring = if ((86
widths.left > 0.0 || widths.top > 0.0 || widths.right > 0.0 || widths.bottom > 0.087
) &&88
outer.bounds.width >89
0.0 &&90
outer.bounds.height >91
0.092
) {93
val inner = insetOutline(outer, widths)94
val value = path(FillRule.EvenOdd) {95
addRoundRect(outer.bounds, outer.radii)96
if (inner.bounds.width > 0.0 && inner.bounds.height > 0.0)97
addRoundRect(inner.bounds, inner.radii)98
}99
owned.add(value)100
Some(value)101
} else102
None103
val regions = ArrayList<Path>()104
if (input.partitions)105
for (points in borderRegions(outer.bounds, edges)) {106
val region = path {107
if (points.size > 0L) {108
moveTo(points[0L])109
for (index in 1L..<points.size)110
lineTo(points[index])111
closeContour()112
}113
}114
owned.add(region)115
regions.add(region)116
}117
return DecorationPaths(outline, ring, regions.toArray())118
} catch (error: Throwable) {119
var failure: Throwable? = Some(error)120
for (value in owned)121
failure = cleanupStyle(failure) { value.close() }122
throwStyle(failure)123
throw error124
}125
}