UNPKG

@itwin/frontend-devtools

Version:

Debug menu and supporting UI widgets

64 lines 2.4 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Tools */ import { IModelApp, Tool } from "@itwin/core-frontend"; import { parseToggle } from "./parseToggle"; /** Augments tooltips with detailed information useful for debugging. * @internal */ class DebugToolTipProvider { static _instance; async augmentToolTip(hit, tooltipPromise) { // discard and overwrite await tooltipPromise; const keys = ["sourceId", "modelId", "subCategoryId", "tileId", "geometryClass"]; let html = ""; for (const key of keys) { const value = hit[key]; if (undefined === value) continue; html = `${html + key}: ${value.toString()}<br>`; } const div = document.createElement("div"); div.innerHTML = html; return div; } static setEnabled(enabled) { if (undefined === enabled) enabled = undefined === this._instance; if (enabled) { if (undefined === this._instance) { this._instance = new DebugToolTipProvider(); IModelApp.viewManager.addToolTipProvider(this._instance); } } else if (undefined !== this._instance) { IModelApp.viewManager.dropToolTipProvider(this._instance); this._instance = undefined; } } } /** Replaces the default tooltips displayed when mousing over elements to instead display information useful for debugging, including * element, model, subcategory, and tile Ids as well as geometry class. * @beta */ export class ToggleToolTipsTool extends Tool { static toolId = "ToggleToolTips"; static get minArgs() { return 0; } static get maxArgs() { return 1; } async run(enable) { DebugToolTipProvider.setEnabled(enable); return true; } async parseAndRun(...args) { const enable = parseToggle(args[0]); if (typeof enable !== "string") await this.run(enable); return true; } } //# sourceMappingURL=ToolTipProvider.js.map