@@ -16,6 +16,7 @@ import type {
16
16
} from './useCanvasInteraction' ;
17
17
import type { Rect } from './geometry' ;
18
18
import type { ScrollState } from './utils/scrollState' ;
19
+ import type { ViewRefs } from './Surface' ;
19
20
20
21
import { Surface } from './Surface' ;
21
22
import { View } from './View' ;
@@ -26,6 +27,11 @@ import {
26
27
translateState ,
27
28
} from './utils/scrollState' ;
28
29
import { MOVE_WHEEL_DELTA_THRESHOLD } from './constants' ;
30
+ import { COLORS } from '../content-views/constants' ;
31
+
32
+ const CARET_MARGIN = 3 ;
33
+ const CARET_WIDTH = 5 ;
34
+ const CARET_HEIGHT = 3 ;
29
35
30
36
// TODO VerticalScrollView Draw caret over top+center and/or bottom+center to indicate scrollable content.
31
37
export class VerticalScrollView extends View {
@@ -49,6 +55,49 @@ export class VerticalScrollView extends View {
49
55
return this . _contentView . desiredSize ( ) ;
50
56
}
51
57
58
+ draw ( context : CanvasRenderingContext2D , viewRefs : ViewRefs ) {
59
+ super . draw ( context , viewRefs ) ;
60
+
61
+ const offset = this . _scrollState . offset ;
62
+ const desiredSize = this . _contentView . desiredSize ( ) ;
63
+
64
+ const above = offset ;
65
+ const below = this . frame . size . height - desiredSize . height - offset ;
66
+
67
+ if ( above < 0 || below < 0 ) {
68
+ const { visibleArea} = this ;
69
+ const { x, y} = visibleArea . origin ;
70
+ const { width, height} = visibleArea . size ;
71
+ const horizontalCenter = x + width / 2 ;
72
+
73
+ const halfWidth = CARET_WIDTH ;
74
+
75
+ if ( above < 0 ) {
76
+ const topY = y + CARET_MARGIN ;
77
+
78
+ context . beginPath ( ) ;
79
+ context . moveTo ( horizontalCenter , topY ) ;
80
+ context . lineTo ( horizontalCenter + halfWidth , topY + CARET_HEIGHT ) ;
81
+ context . lineTo ( horizontalCenter - halfWidth , topY + CARET_HEIGHT ) ;
82
+ context . closePath ( ) ;
83
+ context . fillStyle = COLORS . SCROLL_CARET ;
84
+ context . fill ( ) ;
85
+ }
86
+
87
+ if ( below < 0 ) {
88
+ const bottomY = y + height - CARET_MARGIN ;
89
+
90
+ context . beginPath ( ) ;
91
+ context . moveTo ( horizontalCenter , bottomY ) ;
92
+ context . lineTo ( horizontalCenter + halfWidth , bottomY - CARET_HEIGHT ) ;
93
+ context . lineTo ( horizontalCenter - halfWidth , bottomY - CARET_HEIGHT ) ;
94
+ context . closePath ( ) ;
95
+ context . fillStyle = COLORS . SCROLL_CARET ;
96
+ context . fill ( ) ;
97
+ }
98
+ }
99
+ }
100
+
52
101
/**
53
102
* Reference to the content view. This view is also the only view in
54
103
* `this.subviews`.
0 commit comments