Construct a new UI component
Component configuration
ProtectedelementProtectedconfigPrivatelastPrivatelastProtectedattachAttach event listeners to the component. Use this.addEventListener() for automatic cleanup!
Called automatically after render().
ProtectedonCalled when theme changes. Override for theme-specific logic (e.g., canvas colors).
New theme
ProtectedonCalled before disposal. Override for custom cleanup logic.
Called automatically by dispose().
ProtectedaddAdd an event listener with automatic cleanup tracking. Prevents memory leaks - all listeners removed on dispose()!
IMPORTANT: Use arrow functions for event handlers to maintain component context:
private handleClick = (ev: MouseEvent) => {
// 'this' refers to component instance
this.someMethod();
};
protected attachEventListeners(): void {
this.addEventListener(this.element, 'click', this.handleClick);
}
ProtectedaddAdd a generic event listener (for non-standard events)
Event target
Event type (string for custom events)
Event listener function
Optionaloptions: AddEventListenerOptions
Optional event listener options
ProtectedremoveRemove a specific event listener.
Event target
Event type
Show the component (add to DOM and apply visible class).
Hide the component (remove visible class, keep in DOM).
Toggle visibility.
Check if component is visible.
True if visible
Get the root element of this component.
Root element
Dispose the component - cleanup all resources. NO MORE MEMORY LEAKS!
Automatically:
ProtectedgetGet the base CSS class name for this component. Used for BEM-style naming.
Base CSS class name (e.g., 'luxar-error-dialog')
ProtectedrenderRender the component DOM structure. Should return a root element with appropriate class names. NO INLINE STYLES - use CSS classes only!
Root element for this component
Update the scale bar based on current camera state. Called per-frame from the animation loop.
Privateget
Abstract base class for UI components
All UI components should extend this class to get automatic event listener cleanup and theme subscription.
Example