scoop:scoop.ui.component:0.1.0
src/scroll/placement.scoop
Selected production source · src/scroll/placement.scoop
1
package scoop.ui.component3
import scoop.graphics.*4
import scoop.ui.*6
/** Fixed reservation is independent of overflow and transient feedback. */7
internal fun scrollbarGutter(8
axes: ScrollAxes,9
visibility: ScrollbarVisibility,10
thickness: Double,11
placement: ScrollbarPlacement12
): Size =13
if (placement == ScrollbarPlacement.Gutter && visibility != ScrollbarVisibility.Hidden)14
Size(15
if (axes.vertical)16
thickness17
else18
0.0,19
if (axes.horizontal)20
thickness21
else22
0.023
)24
else25
Size(0.0, 0.0)27
internal fun scrollbarViewport(outer: Size, gutter: Size, direction: LayoutDirection): Rect {28
val width = upperBound(gutter.width, outer.width)29
val height = upperBound(gutter.height, outer.height)30
return Rect(31
if (direction == LayoutDirection.Rtl)32
width33
else34
0.0,35
0.0,36
outer.width - width,37
outer.height - height38
)39
}41
/** Only body overflow creates an Auto bar; reveal margins never create another bar. */42
internal fun scrollbarPadding(43
viewport: Size,44
content: Size,45
axes: ScrollAxes,46
visibility: ScrollbarVisibility,47
thickness: Double,48
placement: ScrollbarPlacement,49
direction: LayoutDirection50
): ScrollPadding {51
if (placement != ScrollbarPlacement.Overlay || viewport.width == 0.0 || viewport.height == 0.0)52
return ScrollPadding()53
val vertical =54
if (axes.vertical && showScrollbar(visibility, content.height - viewport.height))55
upperBound(thickness, viewport.width)56
else57
0.058
val horizontal =59
if (axes.horizontal && showScrollbar(visibility, content.width - viewport.width))60
upperBound(thickness, viewport.height)61
else62
0.063
return ScrollPadding(64
left =65
if (direction == LayoutDirection.Rtl)66
vertical67
else68
0.0,69
right =70
if (direction == LayoutDirection.Ltr)71
vertical72
else73
0.0,74
bottom = horizontal75
)76
}