Skip to main content

Class: Scrollbar

Defined in: packages/blockly/core/scrollbar.ts:33

Class for a pure SVG scrollbar. This technique offers a scrollbar that is guaranteed to work, but may not look or behave like the system's scrollbars.

Properties index

PropertyDescription
scrollbarThicknessWidth of vertical scrollbar or height of horizontal scrollbar in CSS pixels. Scrollbars should be larger on touch devices.
lengthAttribute_The DOM attribute that controls the length of the scrollbar. Different for horizontal and vertical scrollbars.
positionAttribute_The DOM attribute that controls the position of the scrollbar. Different for horizontal and vertical scrollbars.
onMouseDownBarWrapper_Handler for mouse down events on the background of the scrollbar.
onMouseDownHandleWrapper_Handler for mouse down events on the handle of the scrollbar.
onMouseUpWrapper_Handler for mouse move events during scrollbar drags.
onMouseMoveWrapper_Handler for mouse up events to end scrollbar drags.

Methods index

MethodDescription
disposeDispose of this scrollbar. Remove DOM elements, event listeners, and theme subscriptions.
setHandlePositionSet the offset of the scrollbar's handle from the scrollbar's position, and change the SVG attribute accordingly.
resizeRecalculate the scrollbar's location and its length.
resizeViewHorizontalRecalculate a horizontal scrollbar's location on the screen and path length. This should be called when the layout or size of the window has changed.
resizeContentHorizontalRecalculate a horizontal scrollbar's location within its path and length. This should be called when the contents of the workspace have changed.
resizeViewVerticalRecalculate a vertical scrollbar's location on the screen and path length. This should be called when the layout or size of the window has changed.
resizeContentVerticalRecalculate a vertical scrollbar's location within its path and length. This should be called when the contents of the workspace have changed.
isVisibleIs the scrollbar visible. Non-paired scrollbars disappear when they aren't needed.
setContainerVisibleSet whether the scrollbar's container is visible and update display accordingly if visibility has changed.
setVisibleSet whether the scrollbar is visible. Only applies to non-paired scrollbars.
updateDisplay_Update visibility of scrollbar based on whether it thinks it should be visible and whether its containing workspace is visible. We cannot rely on the containing workspace being hidden to hide us because it is not necessarily our parent in the DOM.
setSet the scrollbar handle's position.
setOriginRecord the origin of the workspace that the scrollbar is in, in pixels relative to the injection div origin. This is for times when the scrollbar is used in an object whose origin isn't the same as the main workspace (e.g. in a flyout.)

Constructors

Constructor

new Scrollbar(
workspace,
horizontal,
opt_pair?,
opt_class?,
opt_margin?
): Scrollbar;

Defined in: packages/blockly/core/scrollbar.ts:157

Parameters

ParameterTypeDescription
workspaceWorkspaceSvgWorkspace to bind the scrollbar to.
horizontalbooleanTrue if horizontal, false if vertical.
opt_pair?booleanTrue if scrollbar is part of a horiz/vert pair.
opt_class?stringA class to be applied to this scrollbar.
opt_margin?numberThe margin to apply to this scrollbar.

Returns

Scrollbar

Properties

scrollbarThickness

static scrollbarThickness: number;

Defined in: packages/blockly/core/scrollbar.ts:38

Width of vertical scrollbar or height of horizontal scrollbar in CSS pixels. Scrollbars should be larger on touch devices.


lengthAttribute_

lengthAttribute_: string;

Defined in: packages/blockly/core/scrollbar.ts:130

The DOM attribute that controls the length of the scrollbar. Different for horizontal and vertical scrollbars.


positionAttribute_

positionAttribute_: string;

Defined in: packages/blockly/core/scrollbar.ts:136

The DOM attribute that controls the position of the scrollbar. Different for horizontal and vertical scrollbars.


onMouseDownBarWrapper_

onMouseDownBarWrapper_: Data;

Defined in: packages/blockly/core/scrollbar.ts:139

Handler for mouse down events on the background of the scrollbar.


onMouseDownHandleWrapper_

onMouseDownHandleWrapper_: Data;

Defined in: packages/blockly/core/scrollbar.ts:142

Handler for mouse down events on the handle of the scrollbar.


onMouseUpWrapper_

onMouseUpWrapper_: Data | null = null;

Defined in: packages/blockly/core/scrollbar.ts:145

Handler for mouse move events during scrollbar drags.


onMouseMoveWrapper_

onMouseMoveWrapper_: Data | null = null;

Defined in: packages/blockly/core/scrollbar.ts:148

Handler for mouse up events to end scrollbar drags.

Methods

dispose()

dispose(): void;

Defined in: packages/blockly/core/scrollbar.ts:258

Dispose of this scrollbar. Remove DOM elements, event listeners, and theme subscriptions.

Returns

void


setHandlePosition()

setHandlePosition(newPosition): void;

Defined in: packages/blockly/core/scrollbar.ts:322

Set the offset of the scrollbar's handle from the scrollbar's position, and change the SVG attribute accordingly.

Parameters

ParameterTypeDescription
newPositionnumberThe new scrollbar handle offset in CSS pixels.

Returns

void


resize()

resize(opt_metrics?): void;

Defined in: packages/blockly/core/scrollbar.ts:373

Recalculate the scrollbar's location and its length.

Parameters

ParameterTypeDescription
opt_metrics?MetricsA data structure of from the describing all the required dimensions. If not provided, it will be fetched from the host object.

Returns

void


resizeViewHorizontal()

resizeViewHorizontal(hostMetrics): void;

Defined in: packages/blockly/core/scrollbar.ts:445

Recalculate a horizontal scrollbar's location on the screen and path length. This should be called when the layout or size of the window has changed.

Parameters

ParameterTypeDescription
hostMetricsMetricsA data structure describing all the required dimensions, possibly fetched from the host object.

Returns

void


resizeContentHorizontal()

resizeContentHorizontal(hostMetrics): void;

Defined in: packages/blockly/core/scrollbar.ts:479

Recalculate a horizontal scrollbar's location within its path and length. This should be called when the contents of the workspace have changed.

Parameters

ParameterTypeDescription
hostMetricsMetricsA data structure describing all the required dimensions, possibly fetched from the host object.

Returns

void


resizeViewVertical()

resizeViewVertical(hostMetrics): void;

Defined in: packages/blockly/core/scrollbar.ts:548

Recalculate a vertical scrollbar's location on the screen and path length. This should be called when the layout or size of the window has changed.

Parameters

ParameterTypeDescription
hostMetricsMetricsA data structure describing all the required dimensions, possibly fetched from the host object.

Returns

void


resizeContentVertical()

resizeContentVertical(hostMetrics): void;

Defined in: packages/blockly/core/scrollbar.ts:578

Recalculate a vertical scrollbar's location within its path and length. This should be called when the contents of the workspace have changed.

Parameters

ParameterTypeDescription
hostMetricsMetricsA data structure describing all the required dimensions, possibly fetched from the host object.

Returns

void


isVisible()

isVisible(): boolean;

Defined in: packages/blockly/core/scrollbar.ts:633

Is the scrollbar visible. Non-paired scrollbars disappear when they aren't needed.

Returns

boolean

True if visible.


setContainerVisible()

setContainerVisible(visible): void;

Defined in: packages/blockly/core/scrollbar.ts:643

Set whether the scrollbar's container is visible and update display accordingly if visibility has changed.

Parameters

ParameterTypeDescription
visiblebooleanWhether the container is visible

Returns

void


setVisible()

setVisible(visible): void;

Defined in: packages/blockly/core/scrollbar.ts:658

Set whether the scrollbar is visible. Only applies to non-paired scrollbars.

Parameters

ParameterTypeDescription
visiblebooleanTrue if visible.

Returns

void


updateDisplay_()

updateDisplay_(): void;

Defined in: packages/blockly/core/scrollbar.ts:690

Update visibility of scrollbar based on whether it thinks it should be visible and whether its containing workspace is visible. We cannot rely on the containing workspace being hidden to hide us because it is not necessarily our parent in the DOM.

Returns

void


set()

set(value, updateMetrics?): void;

Defined in: packages/blockly/core/scrollbar.ts:855

Set the scrollbar handle's position.

Parameters

ParameterTypeDescription
valuenumberThe content displacement, relative to the view in pixels.
updateMetrics?booleanWhether to update metrics on this set call. Defaults to true.

Returns

void


setOrigin()

setOrigin(x, y): void;

Defined in: packages/blockly/core/scrollbar.ts:871

Record the origin of the workspace that the scrollbar is in, in pixels relative to the injection div origin. This is for times when the scrollbar is used in an object whose origin isn't the same as the main workspace (e.g. in a flyout.)

Parameters

ParameterTypeDescription
xnumberThe x coordinate of the scrollbar's origin, in CSS pixels.
ynumberThe y coordinate of the scrollbar's origin, in CSS pixels.

Returns

void