UNPKG

@itwin/measure-tools-react

Version:
106 lines 6.49 kB
import type { XAndY } from "@itwin/core-geometry"; import { RelativePosition } from "@itwin/appui-abstract"; import type { ItemProps } from "@itwin/appui-react"; import { ActionButtonItemDef } from "@itwin/appui-react"; import type { Measurement } from "../api/Measurement.js"; /** Props for MeasurementActionItemDef, when the toolbar button is clicked, it passes the measurement that your execute function will handle. */ export interface MeasurementActionItemProps extends ItemProps { /** Non-localized id to identify the item */ id: string; /** Do something with the measurement * @param arg The measurement the toolbar was displayed for. */ execute: (arg: Measurement[]) => void; } /** Toolbar button action item. Encapsulates all the properties to display a button in the toolbar and execute some logic when pressed. */ export declare class MeasurementActionItemDef extends ActionButtonItemDef { private _id; /** Constructs a new measurement action item definition. */ constructor(props: MeasurementActionItemProps); /** Gets the non-localized id to identify the item */ get id(): string; /** Gets the measurement that the toolbar was opened for. */ get measurements(): Measurement[] | undefined; /** Sets the measurement. */ set measurements(measurements: Measurement[] | undefined); /** Executes user callback and closes toolbar. */ execute(): void; } /** Common measurement action items. */ export declare class MeasurementActionDefinitions { /** Creates a new delete action item. This drops the measurement from the decorator. */ static get deleteAction(): MeasurementActionItemDef; /** Creates a new open properties action item. This opens the property grid to display measurement properties. */ static get openPropertiesAction(): MeasurementActionItemDef; /** Creates a new unlock action item. This sets the isLocked property to false and causes the meaurement to be redrawn. */ static get unlockAction(): MeasurementActionItemDef; /** Creates a new lock action item. This sets the isLocked property to true and causes the measurement to be redrawn. */ static get lockAction(): MeasurementActionItemDef; static get hideMeasurements(): MeasurementActionItemDef; static get displayMeasurements(): MeasurementActionItemDef; static get displayMeasurementLabels(): MeasurementActionItemDef; static get hideMeasurementLabels(): MeasurementActionItemDef; static get displayMeasurementAxes(): MeasurementActionItemDef; static get hideMeasurementAxes(): MeasurementActionItemDef; } /** Callback that can add or modify the current list of measurement actions for the popup toolbar. * @param measurements the measurement(s) the toolbar is opening for. * @param actionItemList the current list of actions which you can add or modify. */ export type MeasurementActionProvider = (measurements: Measurement[], actionItemList: MeasurementActionItemDef[]) => void; /** Determines whether or not a toolbar will be opened for the given measurement. * @param measurements the measurement(s) the toolbar has been requested for. * @returns true if the toolbar should open for the measurement, false if it should not. */ export type MeasurementToolbarFilterHandler = (measurements: Measurement[]) => boolean; /** Action provider entry. */ export interface ActionProviderEntry { /** Sort priority, higher values mean the provider is called first. */ priority: number; /** Action provider. */ provider: MeasurementActionProvider; } /** Manager for an action toolbar for measurements. The measurement decorator will respond to pick button events and open the toolbar. */ export declare class MeasurementActionToolbar { private static _actionProviders; private static _filterHandler?; private static _counter; private static _lastPopupId?; private static _fadeoutPopId?; /** Gets if the toolbar is currently opened. */ static get isOpened(): boolean; /** Gets the filter handler if one was set. If a measurement is rejected by the filter, the toolbar will NOT open for it. */ static get filterHandler(): MeasurementToolbarFilterHandler | undefined; /** Sets the filter handler. If a measurement is rejected by the filter, the toolbar will NOT open for it. */ static set filterHandler(handler: MeasurementToolbarFilterHandler | undefined); /** Gets a readonly list of currently registered action providers. */ static get actionProviders(): ReadonlyArray<ActionProviderEntry>; /** Opens the measurement toolbar for a list of measurements. * @param measurements array of Measurement the actions are for. First one is always the one that initiated the event. * @param screenPoint Where on the screen the toolbar is to be positioned (e.g. cursor point) * @param offset Optional offset from the position. Default is (0,0) * @param relativePosition Optional direction the toolbar will open from. Default is Top (so will be above and centered from point + offset). * @returns true if the toolbar was opened, false if otherwise (e.g. no action items to view). */ static openToolbar(measurements: Measurement[], screenPoint: XAndY, offset?: XAndY, relativePosition?: RelativePosition): boolean; /** Closes the measurement toolbar. * @param fadeOut Optionally animate the toolbar fading out. Default is false. */ static closeToolbar(fadeOut?: boolean): void; /** Adds an action item provider. Action providers have a priority, and the list is sorted from highest priority to lowest. * @param provider The action provider to add. * @param providerPriority Optionally provide a sort priority (higher values are called first) */ static addActionProvider(provider: MeasurementActionProvider, providerPriority?: number): void; /** Remove a specific action item provider. If all are removed, the toolbar will not open. * @param provider The action provider to drop. */ static dropActionProvider(provider: MeasurementActionProvider): void; /** Remove all action item providers. */ static clearActionProviders(): void; /** Sets a default provider (which can be later cleared). This sets lock/unlock, delete, and open properties action buttons. */ static setDefaultActionProvider(): void; private static buildActionList; private static buildToolbar; } //# sourceMappingURL=MeasurementActionToolbar.d.ts.map