UNPKG

@itwin/measure-tools-react

Version:
154 lines 7.1 kB
import type { Id64String } from "@itwin/core-bentley"; import type { Vector3d, XAndY, XYAndZ } from "@itwin/core-geometry"; import { Point2d, Point3d } from "@itwin/core-geometry"; import { ColorDef } from "@itwin/core-common"; import type { BeButtonEvent, CanvasDecoration, DecorateContext } from "@itwin/core-frontend"; import type { TextOffsetProps, TextStyleProps } from "./GraphicStyle.js"; import { StyleSet } from "./GraphicStyle.js"; /** * TextEntry for the TextMarker * Title is in bold and the text is on the right with no style modifier */ export interface TextEntry { label: string; value: string; } /** Optional hilite properties that can be attached to a TextMarker and apply different styling. */ export interface TextHiliteProps { /** Is this control hilited or not. */ isHilited: boolean; /** Optional scale factor applied when hiliting. */ scaleFactor?: number; /** Optional hilite color. */ color?: string; } declare enum Visibility { /** TextMarker is always visible. */ Visible = 0, /** TextMarker is visible unless it's wider than maxWorldWidth. */ CollapseOversized = 1, /** TextMarker is not displayed. */ Hidden = 2 } /** * A TextMarker is used to display text that follows a fixed location in world space. * @beta */ export declare class TextMarker implements CanvasDecoration { /** Expose the visibility enum. */ static readonly Visibility: typeof Visibility; private static readonly _titleTextSpacing; /** Text lines to be displayed. */ textLines: string[] | TextEntry[]; /** The font for the text. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/font. */ textFont: string; /** Height of a text line, in percentage. Behaves like CSS's line-height property. */ textLineHeight: number; /** Fill style for text. See the `textColor` setter. */ private _textFillStyle; private _textFillAlpha; /** Unit text direction. Used to calculate the angle of the text. If undefined, text is billboarded to always face the camera. */ textDirection?: Vector3d; private _textAngle; /** Location of the center of the text in world coordinates */ worldLocation: Point3d; private _viewPosition; /** Offset from the center of the text in view coordinates (in pixels or percentage of text size). */ offset?: TextOffsetProps; /** Padding around the text, in pixels. */ boxPadding: number; /** When radius is positive, creates rounded corners. */ boxCornerRadius: number; /** Width of the black border around the box, in pixels. NOTE: only displayed if the box is visible. */ boxBorderWidth: number; private _boxBorderColor?; /** Size of the box in pixels. Set by the last successful call to drawDecoration. */ private _boxSize; get boxSize(): Point2d; /** Fill style for background box. See the `boxColor` setter. When no fill style is provided, the box isn't displayed. */ private _boxFillColor?; private _boxFillStyle?; private _boxFillAlpha; /** Outline of the box. Used for picking. */ private _boxOutline?; /** If text marker was styled from a graphical style that specifie an icon, it will create an element to position during render. */ private _iconHtmlElement?; private _iconPosition; private _iconOffset; private _currViewport?; private _currPixelSize; private _flashViewports; hiliteProps?: TextHiliteProps; /** Whether this marker can be picked/consume mouse events. False by default. */ pickable: boolean; /** Transient ID if the text marker should behave like other decoration graphics that can be hilited/flashed. If valid and pickable set to true: * 1. Will flash when hovered over. * 2. When mouse button is pressed, it will add/remove the ID to the viewport's imodel selection set based * on the current select tool's selection mode. * * This is separate from the other hilite options and is meant to conform to any pickable graphics the text marker may be associated with. Do not combine * both techniques, this will override the other. */ transientHiliteId?: Id64String; /** See `setMouseButtonHandler` */ private _onMouseButtonHandler?; /** See `setMouseEnterHandler` */ private _onMouseEnterHandler?; /** See `setMouseLeaveHandler` */ private _onMouseLeaveHandler?; /** Whether this marker is visible. Visible by default. */ visibility: Visibility; /** See `Visibility.CollapseOversized` */ maxWorldWidth: number; /** Constructor */ constructor(textLines: string[] | TextEntry[], worldLocation: XYAndZ, textDirection?: Vector3d); static createStyled(textLines: string[] | TextEntry[], worldLocation: XYAndZ, style: TextStyleProps, textDirection?: Vector3d): TextMarker; /** Creates a TextMarker with the appropriate styling and offset parameters for a Hover box. */ static createHoverBox(textLines: string[] | TextEntry[], worldLocation: XYAndZ, styleSet?: StyleSet): TextMarker; applyStyle(style?: TextStyleProps): void; private createIcon; private positionIconHtml; private moveIconHtml; /** * Assigns a handler to the onMouseButton event. * NOTE: called two times per click event (down/up). Handle appropriately. */ setMouseButtonHandler(handler?: (ev: BeButtonEvent) => boolean): void; /** Assigns a handler to the onMouseEnter event. */ setMouseEnterHandler(handler?: (ev: BeButtonEvent) => void): void; /** Assigns a handler to the onMouseLeave event. */ setMouseLeaveHandler(handler?: () => void): void; private setPosition; private isCollapsed; private calculateAngle; /** Adds this decoration to the supplied DecorateContext. */ addDecoration(context: DecorateContext): void; /** Returns (a reference to) the current position of the decoration in view coordinates (pixels). * It's the result of worldToView of the wordLocation and does not account for offset. */ get position(): XAndY; /** Returns the central position of the TextMarker in view coordinates, including computed offset. */ get computedPosition(): Point2d; /** Sets the `textFillStyle` attribute based on a ColorDef's RGBA. */ set textColor(v: ColorDef); /** Sets the `backgroundFillStyle` attribute based on a ColorDef's RGBA. */ set boxColor(v: ColorDef | undefined); private isStringArray; /** Creates the closed polygon for picking. */ private updateBoxOutline; drawDecoration(ctx: CanvasRenderingContext2D): void; private drawRect; onMouseEnter(ev: BeButtonEvent): void; onMouseLeave(): void; onMouseButton(ev: BeButtonEvent): boolean; pick(pt: XAndY): boolean; private handleTransientSelection; private getLineHeight; private getBoxWidth; private getBoxHeight; private getXOffsetFromCenterInPixels; private getYOffsetFromCenterInPixels; private getSelectionModeIfSelectToolIsActive; } export {}; //# sourceMappingURL=TextMarker.d.ts.map