Skip to main content

Abstract Class: Icon

Defined in: packages/blockly/core/icons/icon.ts:34

The abstract icon class. Icons are visual elements that live in the top-start corner of the block. Usually they provide more "meta" information about a block (such as warnings or comments) as opposed to fields, which provide "actual" information, related to how a block functions.

Extended by

Implements

Properties index

PropertyDescription
offsetInBlockThe position of this icon relative to its blocks top-start, in workspace units.
workspaceLocationThe position of this icon in workspace coordinates.
svgRootThe root svg element visually representing this icon.
tooltipThe tooltip for this icon.
sourceBlock-

Methods index

MethodDescription
getTypeReturns the IconType representing the type of the icon. This value should also be used to register the icon via Blockly.icons.registry.register.
initViewCreates the SVG elements for the icon that will live on the block.
disposeDisposes of any elements of the icon.
getWeightReturns the "weight" of the icon, which determines the static order which icons should be rendered in. More positive numbers are rendered farther toward the end of the block.
getSizeReturns the dimensions of the icon for use in rendering.
setTooltipSets the tooltip for this icon to the given value. Null to show the tooltip of the block.
getTooltipReturns the tooltip for this icon.
applyColourUpdates the icon's color when the block's color changes..
updateEditableUpdates the icon's editability when the block's editability changes.
updateCollapsedUpdates the icon's collapsed-ness/view when the block's collapsed-ness changes.
hideForInsertionMarkerHides the icon when it is part of an insertion marker.
isShownWhenCollapsedReturns whether this icon is shown when the block is collapsed. Used to allow renderers to account for padding.
setOffsetInBlockNotifies the icon where it is relative to its block's top-start, in workspace units.
onLocationChangeNotifies the icon that it has changed locations.
onClickNotifies the icon that it has been clicked.
isClickableInFlyoutCheck whether the icon should be clickable while the block is in a flyout. The default is that icons are clickable in all flyouts (auto-closing or not). Subclasses may override this function to change this behavior.
getFocusableElementSee IFocusableNode.getFocusableElement.
getFocusableTreeSee IFocusableNode.getFocusableTree.
onNodeFocusSee IFocusableNode.onNodeFocus.
onNodeBlurSee IFocusableNode.onNodeBlur.
canBeFocusedSee IFocusableNode.canBeFocused.
performActionHandles the user acting on this icon via keyboard navigation. Performs the same action as a click would, and focuses this icon's bubble if it has one.
getSourceBlockReturns the block that this icon is attached to.
showContextMenuShow the context menu for this object.
recomputeAriaContextRecomputes the ARIA label and role for this icon. This is automatically called during initialization, but implementations may find it useful to call this if the icon's label should be changed.
getAriaLabelReturns the ARIA label to use for this icon (defaults to null). Note that this method will only be called during initialization by default, so dynamic changes to the icon's ARIA label need to be applied by calling recomputeAriaContext.

Constructors

Constructor

new Icon(sourceBlock): Icon;

Defined in: packages/blockly/core/icons/icon.ts:53

Parameters

ParameterType
sourceBlockBlock

Returns

Icon

Properties

offsetInBlock

protected offsetInBlock: Coordinate;

Defined in: packages/blockly/core/icons/icon.ts:39

The position of this icon relative to its blocks top-start, in workspace units.


workspaceLocation

protected workspaceLocation: Coordinate;

Defined in: packages/blockly/core/icons/icon.ts:42

The position of this icon in workspace coordinates.


svgRoot

protected svgRoot: SVGGElement | null = null;

Defined in: packages/blockly/core/icons/icon.ts:45

The root svg element visually representing this icon.


tooltip

protected tooltip: TipInfo;

Defined in: packages/blockly/core/icons/icon.ts:48

The tooltip for this icon.


sourceBlock

protected sourceBlock: Block;

Defined in: packages/blockly/core/icons/icon.ts:53

Methods

getType()

getType(): IconType<IIcon>;

Defined in: packages/blockly/core/icons/icon.ts:58

Returns

IconType<IIcon>

the IconType representing the type of the icon. This value should also be used to register the icon via Blockly.icons.registry.register.

Implementation of

IIcon.getType


initView()

initView(pointerdownListener): void;

Defined in: packages/blockly/core/icons/icon.ts:62

Creates the SVG elements for the icon that will live on the block.

Parameters

ParameterTypeDescription
pointerdownListener(e) => voidAn event listener that must be attached to the root SVG element by the implementation of initView. Used by Blockly's gesture system to properly handle clicks and drags.

Returns

void

Implementation of

IIcon.initView


dispose()

dispose(): void;

Defined in: packages/blockly/core/icons/icon.ts:83

Disposes of any elements of the icon.

Returns

void

Remarks

In particular, if this icon is currently showing a bubble, this should be used to hide it.

Implementation of

IIcon.dispose


getWeight()

getWeight(): number;

Defined in: packages/blockly/core/icons/icon.ts:92

Returns

number

the "weight" of the icon, which determines the static order which icons should be rendered in. More positive numbers are rendered farther toward the end of the block.

Implementation of

IIcon.getWeight


getSize()

getSize(): Size;

Defined in: packages/blockly/core/icons/icon.ts:96

Returns

Size

The dimensions of the icon for use in rendering.

Implementation of

IIcon.getSize


setTooltip()

setTooltip(tip): void;

Defined in: packages/blockly/core/icons/icon.ts:104

Sets the tooltip for this icon to the given value. Null to show the tooltip of the block.

Parameters

ParameterType
tipTipInfo | null

Returns

void


getTooltip()

getTooltip(): TipInfo;

Defined in: packages/blockly/core/icons/icon.ts:109

Returns the tooltip for this icon.

Returns

TipInfo


applyColour()

applyColour(): void;

Defined in: packages/blockly/core/icons/icon.ts:113

Updates the icon's color when the block's color changes..

Returns

void

Implementation of

IIcon.applyColour


updateEditable()

updateEditable(): void;

Defined in: packages/blockly/core/icons/icon.ts:115

Updates the icon's editability when the block's editability changes.

Returns

void

Implementation of

IIcon.updateEditable


updateCollapsed()

updateCollapsed(): void;

Defined in: packages/blockly/core/icons/icon.ts:117

Updates the icon's collapsed-ness/view when the block's collapsed-ness changes.

Returns

void

Implementation of

IIcon.updateCollapsed


hideForInsertionMarker()

hideForInsertionMarker(): void;

Defined in: packages/blockly/core/icons/icon.ts:129

Hides the icon when it is part of an insertion marker.

Returns

void

Implementation of

IIcon.hideForInsertionMarker


isShownWhenCollapsed()

isShownWhenCollapsed(): boolean;

Defined in: packages/blockly/core/icons/icon.ts:134

Returns

boolean

Whether this icon is shown when the block is collapsed. Used to allow renderers to account for padding.

Implementation of

IIcon.isShownWhenCollapsed


setOffsetInBlock()

setOffsetInBlock(offset): void;

Defined in: packages/blockly/core/icons/icon.ts:138

Notifies the icon where it is relative to its block's top-start, in workspace units.

Parameters

ParameterType
offsetCoordinate

Returns

void

Implementation of

IIcon.setOffsetInBlock


onLocationChange()

onLocationChange(blockOrigin): void;

Defined in: packages/blockly/core/icons/icon.ts:150

Notifies the icon that it has changed locations.

Parameters

ParameterTypeDescription
blockOriginCoordinateThe location of this icon's block's top-start corner in workspace coordinates.

Returns

void

Implementation of

IIcon.onLocationChange


onClick()

onClick(): void;

Defined in: packages/blockly/core/icons/icon.ts:154

Notifies the icon that it has been clicked.

Returns

void

Implementation of

IIcon.onClick


isClickableInFlyout()

isClickableInFlyout(autoClosingFlyout): boolean;

Defined in: packages/blockly/core/icons/icon.ts:165

Check whether the icon should be clickable while the block is in a flyout. The default is that icons are clickable in all flyouts (auto-closing or not). Subclasses may override this function to change this behavior.

Parameters

ParameterTypeDescription
autoClosingFlyoutbooleantrue if the containing flyout is an auto-closing one.

Returns

boolean

Whether the icon should be clickable while the block is in a flyout.

Implementation of

IIcon.isClickableInFlyout


getFocusableElement()

getFocusableElement(): HTMLElement | SVGElement;

Defined in: packages/blockly/core/icons/icon.ts:170

See IFocusableNode.getFocusableElement.

Returns

HTMLElement | SVGElement

Implementation of

IIcon.getFocusableElement


getFocusableTree()

getFocusableTree(): IFocusableTree;

Defined in: packages/blockly/core/icons/icon.ts:177

See IFocusableNode.getFocusableTree.

Returns

IFocusableTree

Implementation of

IIcon.getFocusableTree


onNodeFocus()

onNodeFocus(): void;

Defined in: packages/blockly/core/icons/icon.ts:182

See IFocusableNode.onNodeFocus.

Returns

void

Implementation of

IIcon.onNodeFocus


onNodeBlur()

onNodeBlur(): void;

Defined in: packages/blockly/core/icons/icon.ts:194

See IFocusableNode.onNodeBlur.

Returns

void

Implementation of

IIcon.onNodeBlur


canBeFocused()

canBeFocused(): boolean;

Defined in: packages/blockly/core/icons/icon.ts:197

See IFocusableNode.canBeFocused.

Returns

boolean

Implementation of

IIcon.canBeFocused


performAction()

performAction(): void;

Defined in: packages/blockly/core/icons/icon.ts:206

Handles the user acting on this icon via keyboard navigation. Performs the same action as a click would, and focuses this icon's bubble if it has one.

Returns

void

Implementation of

IIcon.performAction


getSourceBlock()

getSourceBlock(): Block;

Defined in: packages/blockly/core/icons/icon.ts:222

Returns the block that this icon is attached to.

Returns

Block

The block this icon is attached to.


showContextMenu()

showContextMenu(e): void;

Defined in: packages/blockly/core/icons/icon.ts:226

Show the context menu for this object.

Parameters

ParameterTypeDescription
ePointerEventMouse event.

Returns

void

Implementation of

IContextMenu.showContextMenu


recomputeAriaContext()

protected recomputeAriaContext(): void;

Defined in: packages/blockly/core/icons/icon.ts:235

Recomputes the ARIA label and role for this icon. This is automatically called during initialization, but implementations may find it useful to call this if the icon's label should be changed.

Returns

void


getAriaLabel()

protected getAriaLabel(): string | null;

Defined in: packages/blockly/core/icons/icon.ts:260

Returns the ARIA label to use for this icon (defaults to null). Note that this method will only be called during initialization by default, so dynamic changes to the icon's ARIA label need to be applied by calling recomputeAriaContext.

Returns

string | null

The ARIA label to use for this icon, or null to use a default.