Blockly. MetricsManager
The manager for all workspace metrics calculations.
Constructor
MetricsManager
new MetricsManager(workspace)
Parameter |
|
---|---|
workspace |
The workspace to calculate metrics for. Value must not be null. |
- Implements
- Blockly.IMetricsManager
Property
workspace_
non-null Blockly.WorkspaceSvg
The workspace to calculate metrics for.
Methods
getAbsoluteMetrics
getAbsoluteMetrics() returns Blockly.MetricsManager.AbsoluteMetrics
Gets the absolute left and absolute top in pixel coordinates. This is where the visible workspace starts in relation to the SVG container.
- Implements
- Blockly.IMetricsManager#getAbsoluteMetrics
- Returns
-
non-null Blockly.MetricsManager.AbsoluteMetrics
The absolute metrics for the workspace.
getComputedFixedEdges_
getComputedFixedEdges_(opt_viewMetrics) returns Blockly.MetricsManager.FixedEdges
Computes the fixed edges of the scroll area.
Parameter |
|
---|---|
opt_viewMetrics |
Optional Blockly.MetricsManager.ContainerRegion The view metrics if they have been previously computed. Passing in null may cause the view metrics to be computed again, if it is needed. Value must not be null. |
- Returns
-
non-null Blockly.MetricsManager.FixedEdges
The fixed edges of the scroll area.
getContentMetrics
getContentMetrics(opt_getWorkspaceCoordinates) returns Blockly.MetricsManager.ContainerRegion
Gets content metrics in either pixel or workspace coordinates. The content area is a rectangle around all the top bounded elements on the workspace (workspace comments and blocks).
Parameter |
|
---|---|
opt_getWorkspaceCoordinates |
Optional boolean True to get the content metrics in workspace coordinates, false to get them in pixel coordinates. |
- Implements
- Blockly.IMetricsManager#getContentMetrics
- Returns
-
non-null Blockly.MetricsManager.ContainerRegion
The metrics for the content container.
getDimensionsPx_
getDimensionsPx_(elem) returns Blockly.utils.Size
Gets the dimensions of the given workspace component, in pixel coordinates.
Parameter |
|
---|---|
elem |
(nullable Blockly.IToolbox or nullable Blockly.IFlyout) The element to get the dimensions of, or null. It should be a toolbox or flyout, and should implement getWidth() and getHeight(). |
- Returns
-
non-null Blockly.utils.Size
An object containing width and height attributes, which will both be zero if elem did not exist.
getFlyoutMetrics
getFlyoutMetrics(opt_own) returns Blockly.MetricsManager.ToolboxMetrics
Gets the width and the height of the flyout on the workspace in pixel coordinates. Returns 0 for the width and height if the workspace has a category toolbox instead of a simple toolbox.
Parameter |
|
---|---|
opt_own |
Optional boolean Whether to only return the workspace's own flyout. |
- Implements
- Blockly.IMetricsManager#getFlyoutMetrics
- Returns
-
non-null Blockly.MetricsManager.ToolboxMetrics
The width and height of the flyout.
getMetrics
getMetrics() returns Blockly.utils.Metrics
Returns an object with all the metrics required to size scrollbars for a top level workspace. The following properties are computed: Coordinate system: pixel coordinates, -left, -up, +right, +down .viewHeight: Height of the visible portion of the workspace. .viewWidth: Width of the visible portion of the workspace. .contentHeight: Height of the content. .contentWidth: Width of the content. .scrollHeight: Height of the scroll area. .scrollWidth: Width of the scroll area. .svgHeight: Height of the Blockly div (the view + the toolbox, simple or otherwise), .svgWidth: Width of the Blockly div (the view + the toolbox, simple or otherwise), .viewTop: Top-edge of the visible portion of the workspace, relative to the workspace origin. .viewLeft: Left-edge of the visible portion of the workspace, relative to the workspace origin. .contentTop: Top-edge of the content, relative to the workspace origin. .contentLeft: Left-edge of the content relative to the workspace origin. .scrollTop: Top-edge of the scroll area, relative to the workspace origin. .scrollLeft: Left-edge of the scroll area relative to the workspace origin. .absoluteTop: Top-edge of the visible portion of the workspace, relative to the blocklyDiv. .absoluteLeft: Left-edge of the visible portion of the workspace, relative to the blocklyDiv. .toolboxWidth: Width of the toolbox, if it exists. Otherwise zero. .toolboxHeight: Height of the toolbox, if it exists. Otherwise zero. .flyoutWidth: Width of the flyout if it is always open. Otherwise zero. .flyoutHeight: Height of the flyout if it is always open. Otherwise zero. .toolboxPosition: Top, bottom, left or right. Use TOOLBOX_AT constants to compare.
- Implements
- Blockly.IMetricsManager#getMetrics
- Returns
-
non-null Blockly.utils.Metrics
Contains size and position metrics of a top level workspace.
getPaddedContent_
getPaddedContent_(viewMetrics, contentMetrics) returns Object
Returns the content area with added padding.
Parameter |
|
---|---|
viewMetrics |
Blockly.MetricsManager.ContainerRegion The view metrics. Value must not be null. |
contentMetrics |
Blockly.MetricsManager.ContainerRegion The content metrics. Value must not be null. |
- Returns
-
{top: number, bottom: number, left: number, right: number}
The padded content area.
getScrollMetrics
getScrollMetrics(opt_getWorkspaceCoordinates, opt_viewMetrics, opt_contentMetrics) returns Blockly.MetricsManager.ContainerRegion
Returns the metrics for the scroll area of the workspace.
Parameter |
|
---|---|
opt_getWorkspaceCoordinates |
Optional boolean True to get the scroll metrics in workspace coordinates, false to get them in pixel coordinates. |
opt_viewMetrics |
Optional Blockly.MetricsManager.ContainerRegion The view metrics if they have been previously computed. Passing in null may cause the view metrics to be computed again, if it is needed. Value must not be null. |
opt_contentMetrics |
Optional Blockly.MetricsManager.ContainerRegion The content metrics if they have been previously computed. Passing in null may cause the content metrics to be computed again, if it is needed. Value must not be null. |
- Implements
- Blockly.IMetricsManager#getScrollMetrics
- Returns
-
non-null Blockly.MetricsManager.ContainerRegion
The metrics for the scroll container.
getSvgMetrics
getSvgMetrics() returns Blockly.utils.Size
Gets the width and height of the workspace's parent SVG element in pixel coordinates. This area includes the toolbox and the visible workspace area.
- Implements
- Blockly.IMetricsManager#getSvgMetrics
- Returns
-
non-null Blockly.utils.Size
The width and height of the workspace's parent SVG element.
getToolboxMetrics
getToolboxMetrics() returns Blockly.MetricsManager.ToolboxMetrics
Gets the width, height and position of the toolbox on the workspace in pixel coordinates. Returns 0 for the width and height if the workspace has a simple toolbox instead of a category toolbox. To get the width and height of a simple toolbox @see getFlyoutMetrics.
- Implements
- Blockly.IMetricsManager#getToolboxMetrics
- Returns
-
non-null Blockly.MetricsManager.ToolboxMetrics
The object with the width, height and position of the toolbox.
getUiMetrics
getUiMetrics() returns Blockly.MetricsManager.UiMetrics
Returns common metrics used by UI elements.
- Returns
-
non-null Blockly.MetricsManager.UiMetrics
The UI metrics.
getViewMetrics
getViewMetrics(opt_getWorkspaceCoordinates) returns Blockly.MetricsManager.ContainerRegion
Gets the metrics for the visible workspace in either pixel or workspace coordinates. The visible workspace does not include the toolbox or flyout.
Parameter |
|
---|---|
opt_getWorkspaceCoordinates |
Optional boolean True to get the view metrics in workspace coordinates, false to get them in pixel coordinates. |
- Implements
- Blockly.IMetricsManager#getViewMetrics
- Returns
-
non-null Blockly.MetricsManager.ContainerRegion
The width, height, top and left of the viewport in either workspace coordinates or pixel coordinates.
hasFixedEdges
hasFixedEdges() returns boolean
Returns whether the scroll area has fixed edges.
- Implements
- Blockly.IMetricsManager#hasFixedEdges
- Returns
-
boolean
Whether the scroll area has fixed edges.
Abstract types
AbsoluteMetrics
{left: number, top: number}
Describes where the viewport starts in relation to the workspace SVG.
ContainerRegion
{height: number, width: number, top: number, left: number}
All the measurements needed to describe the size and location of a container.
FixedEdges
{top: (number or undefined), bottom: (number or undefined), left: (number or undefined), right: (number or undefined)}
Describes fixed edges of the workspace.
ToolboxMetrics
{width: number, height: number, position: non-null Blockly.utils.toolbox.Position}
Describes the width, height and location of the toolbox on the main workspace.
UiMetrics
{viewMetrics: non-null Blockly.MetricsManager.ContainerRegion, absoluteMetrics: non-null Blockly.MetricsManager.AbsoluteMetrics, toolboxMetrics: non-null Blockly.MetricsManager.ToolboxMetrics}
Common metrics used for UI elements.