MovableComponent


public final class MovableComponent implements Component


This Component can be attached to a single instance of an Entity. When attached, this Component will enable the user to translate the Entity by pointing and dragging on it.

This component cannot be attached to an AnchorEntity or to the ActivitySpace. Calling Entity.addComponent to an Entity with these types will return false.

NOTE: This Component is currently unsupported on GltfModelEntity.

Summary

Public methods

final void

Adds a listener to the set of active listeners for the move events.

final void
addMoveListener(
    @NonNull Executor executor,
    @NonNull EntityMoveListener entityMoveListener
)

Adds a listener to the set of active listeners for the move events.

static final @NonNull MovableComponent
createAnchorable(
    @NonNull Session session,
    @NonNull Set<@NonNull AnchorPlacement> anchorPlacement,
    boolean disposeParentOnReAnchor
)

Public factory function for creating a MovableComponent.

static final @NonNull MovableComponent
createCustomMovable(
    @NonNull Session session,
    boolean scaleInZ,
    Executor executor,
    @NonNull EntityMoveListener entityMoveListener
)

Public factory function for creating a MovableComponent.

static final @NonNull MovableComponent
createSystemMovable(@NonNull Session session, boolean scaleInZ)

Public factory function for creating a MovableComponent.

final @NonNull FloatSize3d

The size of the move affordance in meters.

boolean

Called by an Entity when it attempts to add this Component to itself.

void

Called by an Entity when it attempts to detach this Component from itself.

final void

Removes a listener from the set of active listeners for the move events.

final void

The size of the move affordance in meters.

Public methods

addMoveListener

Added in 1.0.0-alpha05
public final void addMoveListener(@NonNull EntityMoveListener entityMoveListener)

Adds a listener to the set of active listeners for the move events. The listener will be invoked regardless of whether the Entity is being moved by the system or the user.

The listener is invoked on the main thread.

Parameters
@NonNull EntityMoveListener entityMoveListener

The move event listener to set.

addMoveListener

Added in 1.0.0-alpha05
public final void addMoveListener(
    @NonNull Executor executor,
    @NonNull EntityMoveListener entityMoveListener
)

Adds a listener to the set of active listeners for the move events. The listener will be invoked regardless of whether the Entity is being moved by the system or the user.

The listener is invoked on the provided Executor. If the app intends to modify the UI elements/views during the callback, the app should provide the thread executor that is appropriate for the UI operations. For example, if the app is using the main thread to render the UI, the app should provide the main thread (Looper.getMainLooper()) executor. If the app is using a separate thread to render the UI, the app should provide the executor for that thread.

Parameters
@NonNull Executor executor

The executor to run the listener on.

@NonNull EntityMoveListener entityMoveListener

The move event listener to set.

createAnchorable

Added in 1.0.0-alpha05
public static final @NonNull MovableComponent createAnchorable(
    @NonNull Session session,
    @NonNull Set<@NonNull AnchorPlacement> anchorPlacement,
    boolean disposeParentOnReAnchor
)

Public factory function for creating a MovableComponent.

This Component can be attached to a single instance of an Entity. When attached, this Component will enable the user to translate the Entity by pointing and dragging on it.

When created with this function the MovableComponent will move and potentially Anchor the Entity. When anchored a new AnchorEntity will be created and set as the parent of the Entity. If the entity is moved off of a created AnchorEntity it will be reparented to the ActivitySpace. An EntityMoveListener can be attached to receive callbacks when the Entity is being moved and to see if it was reparented to an AnchorEntity.

This component cannot be attached to an AnchorEntity or to the ActivitySpace. Calling Entity.addComponent to an Entity with these types will return false.

Parameters
@NonNull Session session

The Session instance.

@NonNull Set<@NonNull AnchorPlacement> anchorPlacement

A Set containing different AnchorPlacement for how to anchor the Entity with a MovableComponent. When empty this Entity will not be anchored.

boolean disposeParentOnReAnchor

A Boolean, which if set to true, when an Entity is moved off of an AnchorEntity that was created by the underlying MovableComponent, and the AnchorEntity has no other children, the AnchorEntity will be disposed, and the underlying Anchor will be detached.

Returns
@NonNull MovableComponent

MovableComponent instance.

Throws
kotlin.IllegalArgumentException

if created with an Empty Set of for anchorPlacement

createCustomMovable

Added in 1.0.0-alpha05
public static final @NonNull MovableComponent createCustomMovable(
    @NonNull Session session,
    boolean scaleInZ,
    Executor executor,
    @NonNull EntityMoveListener entityMoveListener
)

Public factory function for creating a MovableComponent.

This Component can be attached to a single instance of an Entity. When attached, this Component will enable the user to translate the Entity by pointing and dragging on it.

When created with this function the MovableComponent will not move or rescale the Entity but it could be done using the EntityMoveListener.onMoveUpdate callback.

This component cannot be attached to an AnchorEntity or to the ActivitySpace. Calling Entity.addComponent to an Entity with these types will return false.

Parameters
@NonNull Session session

The Session instance.

boolean scaleInZ

A Boolean which tells the system to update the scale of the Entity as the user moves it closer and further away. This is mostly useful for Panel auto-rescaling with distance.

Executor executor

The executor to run the listener on. If set to null, the listener will be invoked on the main thread.

@NonNull EntityMoveListener entityMoveListener

A move event listener for the event. The application should set the entity position and scale as desired using Entity.setPose and Entity.setScale in the EntityMoveListener.onMoveUpdate callback. To have the system do this movement use createSystemMovable or createAnchorable.

Returns
@NonNull MovableComponent

MovableComponent instance.

createSystemMovable

Added in 1.0.0-alpha05
public static final @NonNull MovableComponent createSystemMovable(@NonNull Session session, boolean scaleInZ)

Public factory function for creating a MovableComponent.

This Component can be attached to a single instance of an Entity. When attached, this Component will enable the user to translate the Entity by pointing and dragging on it.

When created with this function the MovableComponent will move and rescale the Entity. EntityMoveListener can be attached to received callbacks when the Entity is being moved.

This component cannot be attached to an AnchorEntity or to the ActivitySpace. Calling Entity.addComponent to an Entity with these types will return false.

Parameters
@NonNull Session session

The Session instance.

boolean scaleInZ

A Boolean which tells the system to update the scale of the Entity as the user moves it closer and further away. This is mostly useful for Panel auto-rescaling with distance.

Returns
@NonNull MovableComponent

MovableComponent instance.

getSize

Added in 1.0.0-alpha05
public final @NonNull FloatSize3d getSize()

The size of the move affordance in meters. This property determines the size of the bounding box that is used to draw the draggable move affordances around the Entity. This property can be modified if the move affordance needs to be larger or smaller than the Entity itself.

onAttach

Added in 1.0.0-alpha05
public boolean onAttach(@NonNull Entity entity)

Called by an Entity when it attempts to add this Component to itself.

This method is restricted because it is only called from Entity.addComponent.

Parameters
@NonNull Entity entity

Entity to which this Component was attached.

Returns
boolean

True if the Component was attached to the given Entity. False if the Entity did not support having this Component attached.

onDetach

Added in 1.0.0-alpha05
public void onDetach(@NonNull Entity entity)

Called by an Entity when it attempts to detach this Component from itself.

This method is restricted because it is only called from Entity.removeComponent.

Parameters
@NonNull Entity entity

Entity from which this Component was detached.

removeMoveListener

Added in 1.0.0-alpha05
public final void removeMoveListener(@NonNull EntityMoveListener entityMoveListener)

Removes a listener from the set of active listeners for the move events.

Parameters
@NonNull EntityMoveListener entityMoveListener

The move event listener to remove.

setSize

Added in 1.0.0-alpha05
public final void setSize(@NonNull FloatSize3d size)

The size of the move affordance in meters. This property determines the size of the bounding box that is used to draw the draggable move affordances around the Entity. This property can be modified if the move affordance needs to be larger or smaller than the Entity itself.