UNPKG

uicore-ts

Version:

UICore is a library to build native-like user interfaces using pure Typescript. No HTML is needed at all. Components are described as TS classes and all user interactions are handled explicitly. This library is strongly inspired by the UIKit framework tha

95 lines (94 loc) 3.65 kB
import { UIView } from "./UIView"; /** * UITooltip * * Framework-level mouse-following tooltip singleton. * * The default implementation uses a plain HTML element for its content — * no UIView layout system involved. This keeps the base tooltip simple and * allocation-free. * * To use a UIView-based content view instead (e.g. for complex layouts), * override createContentView() to return a UIView subclass. The sizing and * positioning logic in calculateAndSetViewFrame works identically for both * cases since it only calls intrinsicContentHeight/Width on the content view. * * Subclass to provide app-level styling: * - Override createContentView() to return a custom UIView (optional) * - Override applyStyles() to style the default plain-HTML content * - Set UITooltip.sharedInstance to your instance at app startup * * Usage: * UITooltip.sharedInstance.attach(someView, "Tooltip text") * UITooltip.sharedInstance.detach(someView) */ export declare class UITooltip { static sharedInstance: UITooltip; offsetX: number; offsetY: number; maxWidth: number; /** * The view that is measured and positioned by calculateAndSetViewFrame. * In the default implementation this is a lightweight UIView wrapper around * a plain HTML label element. Subclasses may replace it with any UIView. */ readonly contentView: UIView; private _isVisible; private _mouseX; private _mouseY; private _isInitialized; /** The plain HTML label element used by the default implementation. */ protected _labelElement?: HTMLElement; private _attachedHandlers; constructor(); /** * Creates the content view and optionally a plain HTML label element. * * Default: returns a UIView containing a single <span> whose text is set * directly via innerHTML. The label element is returned so that setText() * can update it without going through the UIView system. * * Override to return a UIView-layout-based content view. In that case, * return labelElement: undefined — setText() will call the UIView's own * text-setting mechanism instead (override setText() too if needed). */ protected createContentView(): { contentView: UIView; labelElement?: HTMLElement; }; /** * Apply styles to the default plain-HTML content view. * Only called when using the default createContentView() implementation. * Override alongside createContentView() if you provide a UIView-based * content view that handles its own styling. */ protected applyStyles(): void; /** * Sets the tooltip text. Override if using a UIView-based content view * that exposes its own text-setting API. */ setText(text: string): void; /** * Returns the display size for the content view given the current text. * * For UIView-based content: delegates to intrinsicContentHeight/Width. * For plain-HTML content: measures the label element directly. * * Two passes: * 1. Height at maxWidth — determines how the text wraps * 2. Width at that height — finds the minimum width that fits the * wrapped text, so short text doesn't leave empty space on the right */ protected measureContentSize(): { width: number; height: number; }; private _measureHTMLLabelSize; private get core(); private _recalculateFrame; private _ensureInitialized; show(text: string): void; hide(): void; attach(view: UIView, text: string): void; detach(view: UIView): void; }