Scoop API

scoop:scoop.ui.component:0.1.0

src/text_field/chrome.scoop

Selected production source · src/text_field/chrome.scoop

1package scoop.ui.component
3import scoop.graphics.*
4import scoop.ui.style.*
6public enum TextFieldChrome {
7 Framed, Bare
8}
10internal fun textFieldOptions(
11 input: TextFieldInput,
12 theme: Theme,
13 visual: InteractionVisual
14): SurfaceOptions {
15 var surface = input.style.options(visual)
16 if (theme.tokens.textField == TextFieldTreatment.Outlined && surface.validation == None) {
17 val error = theme.tokens.palette.destructive.background
18 surface = surface
19 .copy {
20 validation = Some(
21 OutlineStyle(
22 error, if (visual.focusVisible || theme.preferences.highContrast)
23 2.0
24 else
25 1.0,
26 0.0, Some(error)
27 )
28 )
29 }
30 }
31 if (!input.options.multiline || surface.padding != None) return surface
32 val density = theme.tokens.typography.body.fontSize / 14.0
33 val padding = theme.surfaceMetrics(SurfaceVisual(SurfaceKind.Plain, visual), surface).padding
34 return surface
35 .copy {
36 this.padding = Some(
37 Insets(
38 lowerBound(10.0 * density, padding.left),
39 lowerBound(8.0 * density, padding.top),
40 lowerBound(10.0 * density, padding.right),
41 lowerBound(8.0 * density, padding.bottom)
42 )
43 )
44 }
47internal fun bareTextFieldMetrics(base: SurfaceMetrics): SurfaceMetrics {
48 val border = base.borderInsets.totals()
49 return SurfaceMetrics(
50 Size(
51 lowerBound(base.suggestedSize.width - border.width, 0.0),
52 lowerBound(base.suggestedSize.height - border.height, 0.0)
53 ),
54 Size(
55 lowerBound(base.minimumSize.width - border.width, 0.0),
56 lowerBound(base.minimumSize.height - border.height, 0.0)
57 ),
58 base.padding,
59 Insets(),
60 CornerRadii(),
61 0.0
62 )
65internal fun bareTextFieldGeometry(
66 base: SurfaceGeometry,
67 metrics: SurfaceMetrics
68): SurfaceGeometry {
69 val outline = RoundedOutline(base.bounds)
70 val inset = metrics.padding
71 return SurfaceGeometry(
72 base.bounds,
73 outline,
74 outline,
75 outline.inset(inset.left, inset.top, inset.right, inset.bottom).bounds,
76 None,
77 base.style.copy { this.corners = Corners.Physical(CornerRadii()) },
78 1.0
79 )