scoop:scoop.ui.style:0.1.0
src/style.scoop
Selected production source · src/style.scoop
1
package scoop.ui.style3
import scoop.graphics.*5
/** A shadow of the filled outer box, independent of its background and content. */6
public struct BoxShadow(val offset: Point, val sigmaX: Double, val sigmaY: Double, val color: Color)8
/** Ordered processing of the actual content alpha and color. Sigma is in local logical units. */9
public enum ContentEffect {10
Blur(val sigmaX: Double, val sigmaY: Double),11
DropShadow(val offset: Point, val sigmaX: Double, val sigmaY: Double, val color: Color),12
Glow(val sigmaX: Double, val sigmaY: Double, val color: Color)13
}15
/** Reusable resource-free drawing inputs. Empty styles retain the same styled content identity. */16
public class Style internal constructor(17
public val background: Paint? = None,18
public val border: Border? = None,19
public val corners: Corners = Corners.all(0.0),20
public val boxShadows: Array<BoxShadow> = [],21
public val contentEffects: Array<ContentEffect> = [],22
public val clipContent: Boolean = false23
) {24
public fun copy(configure: StyleBuilder.() -> Unit = {}): Style =25
configureStyle(this, configure)26
}28
/** Inherit is distinct from explicitly setting an optional property to None. */29
public enum StyleValue<T> {30
Inherit, Set(T)31
}33
public class StyleOverride internal constructor(34
public val background: StyleValue<Paint?> = StyleValue.Inherit,35
public val border: StyleValue<Border?> = StyleValue.Inherit,36
public val corners: StyleValue<Corners> = StyleValue.Inherit,37
public val boxShadows: StyleValue<Array<BoxShadow>> = StyleValue.Inherit,38
public val contentEffects: StyleValue<Array<ContentEffect>> = StyleValue.Inherit,39
public val clipContent: StyleValue<Boolean> = StyleValue.Inherit40
) {41
public fun copy(configure: StyleOverrideBuilder.() -> Unit = {}): StyleOverride =42
configureStyleOverride(this, configure)44
public fun then(next: StyleOverride): StyleOverride =45
StyleOverride(46
background.then(next.background),47
border.then(next.border),48
corners.then(next.corners),49
boxShadows.then(next.boxShadows),50
contentEffects.then(next.contentEffects),51
clipContent.then(next.clipContent)52
)54
public fun resolve(inherited: Style): Style =55
Style(56
background.resolve(inherited.background),57
border.resolve(inherited.border),58
corners.resolve(inherited.corners),59
boxShadows.resolve(inherited.boxShadows),60
contentEffects.resolve(inherited.contentEffects),61
clipContent.resolve(inherited.clipContent)62
)63
}65
public fun <T> StyleValue<T>.then(next: StyleValue<T>): StyleValue<T> =66
when (next) {67
case Inherit -> this;68
case Set(_) -> next69
}71
public fun <T> StyleValue<T>.resolve(inherited: T): T =72
when (this) {73
case Inherit -> inherited74
case Set(val value) -> value75
}