Blockly. Scrollbar
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.
Constructor
Scrollbar
new Scrollbar(workspace, horizontal, opt_pair, opt_class, opt_margin)
Parameter |
|
---|---|
workspace |
Workspace to bind the scrollbar to. Value must not be null. |
horizontal |
True if horizontal, false if vertical. |
opt_pair |
Optional True if scrollbar is part of a horiz/vert pair. |
opt_class |
Optional A class to be applied to this scrollbar. |
opt_margin |
Optional The margin to apply to this scrollbar. |
Properties
DEFAULT_SCROLLBAR_MARGIN
number
Default margin around the scrollbar (between the scrollbar and the edge of the viewport in pixels).
scrollbarThickness
Width of vertical scrollbar or height of horizontal scrollbar in CSS pixels. Scrollbars should be larger on touch devices.
outerSvg_
non-null Element
position
The upper left corner of the scrollbar's SVG group in CSS pixels relative to the scrollbar's origin. This is usually relative to the injection div origin.
ratio
nullable number
The ratio of handle position offset to workspace content displacement.
svgHandle_
non-null Element
Methods
dispose
dispose()
Dispose of this scrollbar. Unlink from all DOM elements to prevent memory leaks.
getRatio_
getRatio_() returns number
Helper to calculate the ratio of handle position to scrollbar view size.
- Returns
-
number
Ratio.
isVisible
isVisible() returns boolean
Is the scrollbar visible. Non-paired scrollbars disappear when they aren't needed.
- Returns
-
boolean
True if visible.
resize
resize(opt_metrics)
Recalculate the scrollbar's location and its length.
Parameter |
|
---|---|
opt_metrics |
Optional A data structure of from the describing all the required dimensions. If not provided, it will be fetched from the host object. |
resizeContentHorizontal
resizeContentHorizontal(hostMetrics)
Recalculate a horizontal scrollbar's location within its path and length. This should be called when the contents of the workspace have changed.
Parameter |
|
---|---|
hostMetrics |
A data structure describing all the required dimensions, possibly fetched from the host object. Value must not be null. |
resizeContentVertical
resizeContentVertical(hostMetrics)
Recalculate a vertical scrollbar's location within its path and length. This should be called when the contents of the workspace have changed.
Parameter |
|
---|---|
hostMetrics |
A data structure describing all the required dimensions, possibly fetched from the host object. Value must not be null. |
resizeViewHorizontal
resizeViewHorizontal(hostMetrics)
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.
Parameter |
|
---|---|
hostMetrics |
A data structure describing all the required dimensions, possibly fetched from the host object. Value must not be null. |
resizeViewVertical
resizeViewVertical(hostMetrics)
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.
Parameter |
|
---|---|
hostMetrics |
A data structure describing all the required dimensions, possibly fetched from the host object. Value must not be null. |
set
set(value, updateMetrics)
Set the scrollbar handle's position.
Parameter |
|
---|---|
value |
number The content displacement, relative to the view in pixels. |
updateMetrics |
Optional boolean Whether to update metrics on this set call. Defaults to true. |
setContainerVisible
setContainerVisible(visible)
Set whether the scrollbar's container is visible and update display accordingly if visibility has changed.
Parameter |
|
---|---|
visible |
boolean Whether the container is visible |
setHandlePosition
setHandlePosition(newPosition)
Set the offset of the scrollbar's handle from the scrollbar's position, and change the SVG attribute accordingly.
Parameter |
|
---|---|
newPosition |
number The new scrollbar handle offset in CSS pixels. |
setOrigin
setOrigin(x, y)
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.)
Parameter |
|
---|---|
x |
number The x coordinate of the scrollbar's origin, in CSS pixels. |
y |
number The y coordinate of the scrollbar's origin, in CSS pixels. |
setPosition
setPosition(x, y)
Set the position of the scrollbar's SVG group in CSS pixels relative to the scrollbar's origin. This sets the scrollbar's location within the workspace.
Parameter |
|
---|---|
x |
number The new x coordinate. |
y |
number The new y coordinate. |
setVisible
setVisible(visible)
Set whether the scrollbar is visible. Only applies to non-paired scrollbars.
Parameter |
|
---|---|
visible |
boolean True if visible. |
updateDisplay_
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.