@dcl/react-ecs
Version:
Decentraland ECS
52 lines (51 loc) • 1.82 kB
TypeScript
import { type Entity, type IEngine, type PointerEventsSystem } from '@dcl/ecs';
import type { ReactEcs } from './react-ecs';
/**
* @public
*/
export type UiComponent = () => ReactEcs.JSX.ReactNode;
/**
* @public
*/
export type UiRendererOptions = {
virtualWidth: number;
virtualHeight: number;
};
/**
* @public
*/
export interface ReactBasedUiSystem {
/**
* Destroy all UI entities and unregister related systems.
*/
destroy(): void;
/**
* Set the main UI renderer. Optional virtual size defines the global UI scale factor.
*/
setUiRenderer(ui: UiComponent, options?: UiRendererOptions): void;
/**
* Add a UI renderer associated with an entity. The UI will be automatically cleaned up
* when the entity is removed from the engine.
*
* If a renderer is already associated with the given entity, it will be replaced.
*
* This allows dynamically adding UI Renderers that are rendered alongside the main
* UI set via setUiRenderer().
*
* @param entity - The entity to associate with this UI renderer. When the entity is removed,
* the UI renderer is automatically cleaned up.
* @param ui - The UI component to render
* @param options - Optional virtual size used for UI scale factor when main UI has none
*/
addUiRenderer(entity: Entity, ui: UiComponent, options?: UiRendererOptions): void;
/**
* Remove a previously added UI renderer by its associated entity.
* It does not affect the main UI renderer.
* @param entity - The entity whose UI renderer should be removed
*/
removeUiRenderer(entity: Entity): void;
}
/**
* @public
*/
export declare function createReactBasedUiSystem(engine: IEngine, pointerSystem: PointerEventsSystem): ReactBasedUiSystem;