Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/browser/ui/scrollbar/horizontalScrollbar.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { StandardWheelEvent } from '../../mouseEvent.js';
7
import { AbstractScrollbar, ISimplifiedPointerEvent, ScrollbarHost } from './abstractScrollbar.js';
8
import { ScrollableElementResolvedOptions } from './scrollableElementOptions.js';
9
import { ARROW_IMG_SIZE } from './scrollbarArrow.js';
10
import { ScrollbarState } from './scrollbarState.js';
11
import { Codicon } from '../../../common/codicons.js';
12
import { INewScrollPosition, Scrollable, ScrollbarVisibility, ScrollEvent } from '../../../common/scrollable.js';
13
14
15
16
17
export class HorizontalScrollbar extends AbstractScrollbar {
18
19
constructor(scrollable: Scrollable, options: ScrollableElementResolvedOptions, host: ScrollbarHost) {
20
const scrollDimensions = scrollable.getScrollDimensions();
21
const scrollPosition = scrollable.getCurrentScrollPosition();
22
super({
23
lazyRender: options.lazyRender,
24
host: host,
25
scrollbarState: new ScrollbarState(
26
(options.horizontalHasArrows ? options.arrowSize : 0),
27
(options.horizontal === ScrollbarVisibility.Hidden ? 0 : options.horizontalScrollbarSize),
28
(options.vertical === ScrollbarVisibility.Hidden ? 0 : options.verticalScrollbarSize),
29
scrollDimensions.width,
30
scrollDimensions.scrollWidth,
31
scrollPosition.scrollLeft
32
),
33
visibility: options.horizontal,
34
extraScrollbarClassName: 'horizontal',
35
scrollable: scrollable,
36
scrollByPage: options.scrollByPage
37
});
38
39
if (options.horizontalHasArrows) {
40
const arrowDelta = (options.arrowSize - ARROW_IMG_SIZE) / 2;
41
const scrollbarDelta = (options.horizontalScrollbarSize - ARROW_IMG_SIZE) / 2;
42
43
this._createArrow({
44
className: 'scra',
45
icon: Codicon.scrollbarButtonLeft,
46
top: scrollbarDelta,
47
left: arrowDelta,
48
bottom: undefined,
49
right: undefined,
50
bgWidth: options.arrowSize,
51
bgHeight: options.horizontalScrollbarSize,
52
onActivate: () => this._host.onMouseWheel(new StandardWheelEvent(null, 1, 0)),
53
});
54
55
this._createArrow({
56
className: 'scra',
57
icon: Codicon.scrollbarButtonRight,
58
top: scrollbarDelta,
59
left: undefined,
60
bottom: undefined,
61
right: arrowDelta,
62
bgWidth: options.arrowSize,
63
bgHeight: options.horizontalScrollbarSize,
64
onActivate: () => this._host.onMouseWheel(new StandardWheelEvent(null, -1, 0)),
65
});
66
}
67
68
this._createSlider(Math.floor((options.horizontalScrollbarSize - options.horizontalSliderSize) / 2), 0, undefined, options.horizontalSliderSize);
69
}
70
71
protected _updateSlider(sliderSize: number, sliderPosition: number): void {
72
this.slider.setWidth(sliderSize);
73
this.slider.setLeft(sliderPosition);
74
}
75
76
protected _renderDomNode(largeSize: number, smallSize: number): void {
77
this.domNode.setWidth(largeSize);
78
this.domNode.setHeight(smallSize);
79
this.domNode.setLeft(0);
80
this.domNode.setBottom(0);
81
}
82
83
public onDidScroll(e: ScrollEvent): boolean {
84
this._shouldRender = this._onElementScrollSize(e.scrollWidth) || this._shouldRender;
85
this._shouldRender = this._onElementScrollPosition(e.scrollLeft) || this._shouldRender;
86
this._shouldRender = this._onElementSize(e.width) || this._shouldRender;
87
return this._shouldRender;
88
}
89
90
protected _pointerDownRelativePosition(offsetX: number, offsetY: number): number {
91
return offsetX;
92
}
93
94
protected _sliderPointerPosition(e: ISimplifiedPointerEvent): number {
95
return e.pageX;
96
}
97
98
protected _sliderOrthogonalPointerPosition(e: ISimplifiedPointerEvent): number {
99
return e.pageY;
100
}
101
102
protected _updateScrollbarSize(size: number): void {
103
this.slider.setHeight(size);
104
}
105
106
public writeScrollPosition(target: INewScrollPosition, scrollPosition: number): void {
107
target.scrollLeft = scrollPosition;
108
}
109
110
public updateOptions(options: ScrollableElementResolvedOptions): void {
111
this.updateScrollbarSize(options.horizontal === ScrollbarVisibility.Hidden ? 0 : options.horizontalScrollbarSize);
112
this._scrollbarState.setOppositeScrollbarSize(options.vertical === ScrollbarVisibility.Hidden ? 0 : options.verticalScrollbarSize);
113
this._visibilityController.setVisibility(options.horizontal);
114
this._scrollByPage = options.scrollByPage;
115
}
116
}
117
118