scoop:scoop.ui.style:0.1.0
src/theme/token_builders.scoop
Selected production source · src/theme/token_builders.scoop
1
package scoop.ui.style3
import scoop.graphics.*4
import scoop.graphics.text.*5
import scoop.surface.AnimationSpec7
/** Constructs a complete description and applies configuration once. */8
public fun themeTypography(9
body: TextStyle,10
caption: TextStyle,11
action: TextStyle,12
configure: ThemeTypographyBuilder.() -> Unit = {}13
): ThemeTypography = configureThemeTypography(14
ThemeTypography(body = body, caption = caption, action = action, input = body),15
configure16
)18
internal fun configureThemeTypography(19
initial: ThemeTypography,20
configure: ThemeTypographyBuilder.() -> Unit21
): ThemeTypography {22
val builder = ThemeTypographyBuilder(initial)23
builder.configure()24
return builder.snapshot()25
}27
/** Mutable configuration initialized from a complete immutable value. */28
public class ThemeTypographyBuilder internal constructor(initial: ThemeTypography) {29
public var body: TextStyle = initial.body30
public var caption: TextStyle = initial.caption31
public var action: TextStyle = initial.action32
public var input: TextStyle = initial.input34
public fun body(configure: TextStyleBuilder.() -> Unit): Unit {35
body = body.copy(configure)36
}38
public fun caption(configure: TextStyleBuilder.() -> Unit): Unit {39
caption = caption.copy(configure)40
}42
public fun action(configure: TextStyleBuilder.() -> Unit): Unit {43
action = action.copy(configure)44
}46
public fun input(configure: TextStyleBuilder.() -> Unit): Unit {47
input = input.copy(configure)48
}50
internal fun snapshot(): ThemeTypography = ThemeTypography(51
body = body,52
caption = caption,53
action = action,54
input = input55
)56
}58
/** Constructs a complete description and applies configuration once. */59
public fun themeEffects(configure: ThemeEffectsBuilder.() -> Unit = {}): ThemeEffects =60
configureThemeEffects(ThemeEffects(), configure)62
internal fun configureThemeEffects(63
initial: ThemeEffects,64
configure: ThemeEffectsBuilder.() -> Unit65
): ThemeEffects {66
val builder = ThemeEffectsBuilder(initial)67
builder.configure()68
return builder.snapshot()69
}71
/** Mutable configuration initialized from a complete immutable value. */72
public class ThemeEffectsBuilder internal constructor(initial: ThemeEffects) {73
public var raised: Array<BoxShadow> = initial.raised74
public var floating: Array<BoxShadow> = initial.floating75
public var emphasis: Array<ContentEffect> = initial.emphasis77
internal fun snapshot(): ThemeEffects = ThemeEffects(78
raised = raised,79
floating = floating,80
emphasis = emphasis81
)82
}84
/** Constructs a complete description and applies configuration once. */85
public fun themeMotion(configure: ThemeMotionBuilder.() -> Unit = {}): ThemeMotion =86
configureThemeMotion(ThemeMotion(), configure)88
internal fun configureThemeMotion(89
initial: ThemeMotion,90
configure: ThemeMotionBuilder.() -> Unit91
): ThemeMotion {92
val builder = ThemeMotionBuilder(initial)93
builder.configure()94
return builder.snapshot()95
}97
/** Mutable configuration initialized from a complete immutable value. */98
public class ThemeMotionBuilder internal constructor(initial: ThemeMotion) {99
public var preference: MotionPreference = initial.preference100
public var hover: AnimationSpec? = initial.hover101
public var press: AnimationSpec? = initial.press102
public var selection: AnimationSpec? = initial.selection104
internal fun snapshot(): ThemeMotion = ThemeMotion(105
preference = preference,106
hover = hover,107
press = press,108
selection = selection109
)110
}112
/** Constructs a complete description and applies configuration once. */113
public fun themeTokens(114
palette: ThemePalette,115
typography: ThemeTypography,116
spacing: ThemeSpacing,117
corners: ThemeCorners,118
validation: OutlineStyle,119
configure: ThemeTokensBuilder.() -> Unit = {}120
): ThemeTokens = configureThemeTokens(121
ThemeTokens(122
palette = palette,123
typography = typography,124
spacing = spacing,125
corners = corners,126
validation = validation127
),128
configure129
)131
internal fun configureThemeTokens(132
initial: ThemeTokens,133
configure: ThemeTokensBuilder.() -> Unit134
): ThemeTokens {135
val builder = ThemeTokensBuilder(initial)136
builder.configure()137
return builder.snapshot()138
}140
/** Mutable configuration initialized from a complete immutable value. */141
public class ThemeTokensBuilder internal constructor(initial: ThemeTokens) {142
public var mode: ThemeMode = initial.mode143
public var palette: ThemePalette = initial.palette144
public var typography: ThemeTypography = initial.typography145
public var spacing: ThemeSpacing = initial.spacing146
public var motion: ThemeMotion = initial.motion147
public var corners: ThemeCorners = initial.corners148
public var validation: OutlineStyle = initial.validation149
public var effects: ThemeEffects = initial.effects150
public var disabledOpacity: Double = initial.disabledOpacity151
public var textField: TextFieldTreatment = initial.textField153
public fun palette(configure: ThemePaletteBuilder.() -> Unit): Unit {154
palette = palette.copy(configure)155
}157
public fun typography(configure: ThemeTypographyBuilder.() -> Unit): Unit {158
typography = typography.copy(configure)159
}161
public fun motion(configure: ThemeMotionBuilder.() -> Unit): Unit {162
motion = motion.copy(configure)163
}165
public fun effects(configure: ThemeEffectsBuilder.() -> Unit): Unit {166
effects = effects.copy(configure)167
}169
internal fun snapshot(): ThemeTokens = ThemeTokens(170
mode = mode,171
palette = palette,172
typography = typography,173
spacing = spacing,174
motion = motion,175
corners = corners,176
validation = validation,177
effects = effects,178
disabledOpacity = disabledOpacity,179
textField = textField180
)181
}