PointerCaptureComponent


public final class PointerCaptureComponent implements Component


Provides pointer capture capabilities for a given Entity.

To enable pointer capture, the task must be in full space, the entity must be visible, and the PointerCaptureComponent must be attached to the entity.

Only one PointerCaptureComponent can be attached to an entity at a given time. If a second one tries to attach to an entity, it will fail.

Summary

Nested types

Defines the possible states of a PointerCaptureComponent.

Public methods

static final @NonNull PointerCaptureComponent
create(
    @NonNull Session session,
    @NonNull Executor executor,
    @NonNull Consumer<@NonNull PointerCaptureComponent.PointerCaptureState> stateListener,
    @NonNull Consumer<@NonNull InputEvent> inputListener
)

Creates a new instance of PointerCaptureComponent.

boolean

Called by the framework when this component is being added to an Entity.

void

Called by the framework when this component is being removed from an Entity.

Public methods

create

Added in 1.0.0-alpha14
public static final @NonNull PointerCaptureComponent create(
    @NonNull Session session,
    @NonNull Executor executor,
    @NonNull Consumer<@NonNull PointerCaptureComponent.PointerCaptureState> stateListener,
    @NonNull Consumer<@NonNull InputEvent> inputListener
)

Creates a new instance of PointerCaptureComponent.

Parameters
@NonNull Session session

The active Session for the scene.

@NonNull Executor executor

The Executor on which the listener callbacks will be invoked.

@NonNull Consumer<@NonNull PointerCaptureComponent.PointerCaptureState> stateListener

A Consumer to receive updates when the pointer capture state changes (e.g., from active to paused).

@NonNull Consumer<@NonNull InputEvent> inputListener

A Consumer to receive all InputEvents while pointer capture is active for the attached entity.

onAttach

public boolean onAttach(@NonNull Entity entity)

Called by the framework when this component is being added to an Entity.

This method is triggered when Entity.addComponent is invoked. It should not be called directly by applications. Implementations should override this method to perform setup logic or to validate if the component is compatible with the provided entity.

Parameters
@NonNull Entity entity

The Entity to which this component is being attached.

Returns
boolean

true if the component was successfully attached; false if the entity does not support this component or if attachment failed.

onDetach

public void onDetach(@NonNull Entity entity)

Called by the framework when this component is being removed from an Entity.

This method is triggered when Entity.removeComponent is invoked. It should not be called directly by applications. Implementations should override this method to release resources or undo any changes made during onAttach.

Parameters
@NonNull Entity entity

The Entity from which this component is being detached.