Files
blockly/core/interfaces/i_icon.ts
Maribeth Bottorff 88ff901a72 chore: use prettier instead of clang-format (#7014)
* chore: add and configure prettier

* chore: remove clang-format

* chore: remove clang-format config

* chore: lint additional ts files

* chore: fix lint errors in blocks

* chore: add prettier-ignore where needed

* chore: ignore js blocks when formatting

* chore: fix playground html syntax

* chore: fix yaml spacing from merge

* chore: convert text blocks to use arrow functions

* chore: format everything with prettier

* chore: fix lint unused imports in blocks
2023-05-10 16:01:39 -07:00

99 lines
2.8 KiB
TypeScript

/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import type {Coordinate} from '../utils/coordinate.js';
import type {Size} from '../utils/size.js';
export interface IIcon {
/**
* @return the string representing the type of the icon.
* E.g. 'comment', 'warning', etc. This string should also be used when
* registering the icon class.
*/
getType(): string;
/**
* Creates the SVG elements for the icon that will live on the block.
*
* @param pointerdownListener An 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.
*/
initView(pointerdownListener: (e: PointerEvent) => void): void;
/**
* Disposes of any elements of the icon.
*
* @remarks
*
* In particular, if this icon is currently showing a bubble, this should be
* used to hide it.
*/
dispose(): void;
/**
* @return 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.
*/
getWeight(): number;
/** @return The dimensions of the icon for use in rendering. */
getSize(): Size;
/** Notifies the icon that the block's colour has changed. */
applyColour(): void;
/** Notifies the icon that the block's editability has changed. */
updateEditable(): void;
/** Notifies the icon that the block's collapsed-ness has changed. */
updateCollapsed(): void;
/**
* @return Whether this icon is shown when the block is collapsed. Used
* to allow renderers to account for padding.
*/
isShownWhenCollapsed(): boolean;
/**
* Notifies the icon where it is relative to its block's top-start, in
* workspace units.
*/
setOffsetInBlock(offset: Coordinate): void;
/**
* Notifies the icon that it has changed locations.
*
* @param blockOrigin The location of this icon's block's top-start corner
* in workspace coordinates.
*/
onLocationChange(blockOrigin: Coordinate): void;
/**
* Notifies the icon that it has been clicked.
*/
onClick(): void;
}
/** Type guard that checks whether the given object is an IIcon. */
export function isIcon(obj: any): obj is IIcon {
return (
obj.getType !== undefined &&
obj.initView !== undefined &&
obj.dispose !== undefined &&
obj.getWeight !== undefined &&
obj.getSize !== undefined &&
obj.applyColour !== undefined &&
obj.updateEditable !== undefined &&
obj.updateCollapsed !== undefined &&
obj.isShownWhenCollapsed !== undefined &&
obj.setOffsetInBlock !== undefined &&
obj.onLocationChange !== undefined &&
obj.onClick !== undefined
);
}