Scoop API

scoop:scoop.ui.component:0.1.0

src/scroll/placement.scoop

Selected production source · src/scroll/placement.scoop

1package scoop.ui.component
3import scoop.graphics.*
4import scoop.ui.*
6/** Fixed reservation is independent of overflow and transient feedback. */
7internal fun scrollbarGutter(
8 axes: ScrollAxes,
9 visibility: ScrollbarVisibility,
10 thickness: Double,
11 placement: ScrollbarPlacement
12): Size =
13 if (placement == ScrollbarPlacement.Gutter && visibility != ScrollbarVisibility.Hidden)
14 Size(
15 if (axes.vertical)
16 thickness
17 else
18 0.0,
19 if (axes.horizontal)
20 thickness
21 else
22 0.0
23 )
24 else
25 Size(0.0, 0.0)
27internal 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 width
33 else
34 0.0,
35 0.0,
36 outer.width - width,
37 outer.height - height
38 )
41/** Only body overflow creates an Auto bar; reveal margins never create another bar. */
42internal fun scrollbarPadding(
43 viewport: Size,
44 content: Size,
45 axes: ScrollAxes,
46 visibility: ScrollbarVisibility,
47 thickness: Double,
48 placement: ScrollbarPlacement,
49 direction: LayoutDirection
50): 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 else
57 0.0
58 val horizontal =
59 if (axes.horizontal && showScrollbar(visibility, content.width - viewport.width))
60 upperBound(thickness, viewport.height)
61 else
62 0.0
63 return ScrollPadding(
64 left =
65 if (direction == LayoutDirection.Rtl)
66 vertical
67 else
68 0.0,
69 right =
70 if (direction == LayoutDirection.Ltr)
71 vertical
72 else
73 0.0,
74 bottom = horizontal
75 )