diff --git a/core/icons/icon.ts b/core/icons/icon.ts index 095f52509..c5979445c 100644 --- a/core/icons/icon.ts +++ b/core/icons/icon.ts @@ -15,6 +15,7 @@ import {Size} from '../utils/size.js'; import {Svg} from '../utils/svg.js'; import type {IconType} from './icon_types.js'; import * as deprecation from '../utils/deprecation.js'; +import * as tooltip from '../tooltip.js'; /** * The abstract icon class. Icons are visual elements that live in the top-start @@ -35,7 +36,12 @@ export abstract class Icon implements IIcon { /** The root svg element visually representing this icon. */ protected svgRoot: SVGGElement | null = null; - constructor(protected sourceBlock: Block) {} + /** The tooltip for this icon. */ + protected tooltip: tooltip.TipInfo; + + constructor(protected sourceBlock: Block) { + this.tooltip = sourceBlock; + } getType(): IconType { throw new Error('Icons must implement getType'); @@ -54,9 +60,12 @@ export abstract class Icon implements IIcon { this, pointerdownListener, ); + (this.svgRoot as any).tooltip = this; + tooltip.bindMouseEvents(this.svgRoot); } dispose(): void { + tooltip.unbindMouseEvents(this.svgRoot); dom.removeNode(this.svgRoot); } @@ -68,6 +77,19 @@ export abstract class Icon implements IIcon { return new Size(0, 0); } + /** + * Sets the tooltip for this icon to the given value. Null to show the + * tooltip of the block. + */ + setTooltip(tip: tooltip.TipInfo | null) { + this.tooltip = tip ?? this.sourceBlock; + } + + /** Returns the tooltip for this icon. */ + getTooltip(): tooltip.TipInfo { + return this.tooltip; + } + applyColour(): void {} updateEditable(): void {}