Link Search Menu Expand Document

View

The View class acts as base for anything visual in an alloapp.

It manages a tree of sub-views; its bounds (transform and size) and a connection to a low-level entity.

Constructor

 view = View(bounds)

Arguments

Name Type Description
bounds Bounds The View’s Bounds component

Returns

Nothing


Methods

View:awake ()

awake() is called when entity exists and is bound to this view.

Arguments

None

Returns

Nothing


View:sleep ()

sleep() is called when the entity for the view stops existing

Arguments

None

Returns

Nothing


View:isAwake ()

does the entity for this view exist and is bound to this view?

Arguments

None

Returns

Nothing


View:doWhenAwake (todo)

schedule something to do once the entity exists for this view. If it does, do the thing immediately.

Arguments

Name Type Description
todo function The function to run

Returns

Nothing


View:setGrabbable (grabbable, grabOptions)

If this is set to true, user can grab and move this view using the grip button.

Arguments

Name Type Description
grabbable Boolean Set to true to enable the View to be grabbed.
grabOptions table A table of options for the grabbable component. See Components > grabbable

Returns

Nothing


View:setPointable (pointable)

If this is set to true, the user’s cursor can land on this view, and you can receive pointer events. (See onPointerChanged and friends)

Arguments

Name Type Description
pointable Boolean Set to true to enable the View to receive pointer events.

Returns

Nothing


View:transformFromParent ()

The mat4 describing the transform from the parent view’s location to this view’s location, i e the location in the local coordinate system of the parent view.

Arguments

None

Returns

Nothing


View:transformFromWorld ()

The mat4 describing the transform in world coordinates, i e exactly where the view is in the world instead of where it is relative to its parent.

Arguments

None

Returns

Nothing


View:convertPointFromView (point, other)

Converts point from other view to this view If other is nil then the point is assumed to be in world space

Arguments

Name Type Description
point Point A point in the coordinate system of other
other View The view to convert the point from

Returns

Nothing


View:specification ()

The specification is used to describe the entity tree.

It is required to represent this view inside the Alloverse. In a subclass, call this implementation and then add/modify your own components.

Arguments

None

Returns

Nothing


View:updateComponents (changes)

Asks the backend to update components on the server.

Use this to update things you’ve specified in :specification() but now want to change.

Arguments

Name Type Description
changes table A table with the desired changes, for example: {transform={…}, collider={…}}

Returns

Nothing


View:markAsDirty (components)

Mark one or more Components as needing to have their server-side value updated ASAP

Arguments

Name Type Description  
components string {string} either a string with one component to update, or a list if string components

Returns

Nothing


View:setBounds (bounds)

Sets the View’s bounds (pose and size) in the world.

Note that simply changing a View’s Bounds won’t affect its size or position in the world until this method is run.

Arguments

Name Type Description
bounds Bounds the Bounds with which to define the Size and Pose of the parent View in the world.

Returns

Nothing


View:addSubview (subview)

Adds a View as a child component to the given View.

Arguments

Name Type Description
subview View The View to be added

Returns

Nothing


View:removeFromSuperview ()

Detaches the View from its parent

Arguments

None

Returns

Nothing


View:findView (vid)

Finds and returns a subview of the given view ID.

Arguments

Name Type Description
vid string The viewId of the View to be searched for.

Returns

Type Description
View The subview corresponding to the view ID. If no view was found, nil is returned.

View:playSound (asset, playOptions)

Plays the given sound asset ASAP.

You can use playOptions to set things like loop_count, volume, length, offset etc…

Arguments

Name Type Description
asset Asset The asset to play
playOptions table A table with valid keys for the “sound_effect” component

Returns

Nothing


View:askToFocus (avatar)

Ask the client that uses the given avatar to focus this view to take text input.

In other words: display the keyboard for that avatar.

Arguments

Name Type Description
avatar ???  

Returns

Nothing


View:defocus ()

Dismiss the keyboard for the user that has currently keyboard-focused this view.

Arguments

None

Returns

Nothing


View:onGrabStarted (hand)

Callback called when a user grabs this view in order to move it.

The server will then update self.entity.components.transform to match where the user wants to move it continuously. There is no callback for when the entity is moved.

Arguments

Name Type Description
hand Entity The hand entity that started the grab

Returns

Nothing


View:onGrabEnded (hand)

Callback called when a user lets go of and no longer wants to move it.

Arguments

Name Type Description
hand Entity The hand entity that released the grab.

Returns

Nothing


View:onPointerChanged (pointer)

Callback for when a hand is interacting with a view.

NOTE: You must set view:setPointable(true), or the user’s cursor will just fall right through this view!

This is a catch-all callback; there is also onPointerEntered, onPointerMoved, onPointerExited, onTouchDown and onTouchUp if you want to react only to specific events.

Arguments

Name Type Description
pointer table A table with keys (see below).

The pointer table’s keys are as follows:

  • hand: The hand entity that is doing the pointing
  • state: “hovering”, “outside” or “touching”
  • touching: bool, whether the hand is currently doing a poke on this view
  • pointedFrom: a vec3 in world coordinate space with the coordinates of the finger tip of the hand pointing at this view.
  • pointedTo: the point on this view that is being pointed at (again, in world coordinates). |

Returns

Nothing


View:onPointerEntered (pointer)

Callback for when a hand’s pointer ray entered this view.

The state in pointer is now “hovering”

Arguments

Name Type Description
pointer table see onPointerChanged.

Returns

Nothing


View:onPointerMoved (pointer)

Callback for when a hand’s pointer moved within this view.

The pointedFrom and pointedTo in pointer now likely have new values.

Arguments

Name Type Description
pointer table see onPointerChanged.

Returns

Nothing


View:onPointerExited (pointer)

Callback for when the hand’s pointer is no longer pointing within this view.

The state in pointer is now “outside”

Arguments

Name Type Description
pointer table see onPointerChanged.

Returns

Nothing


View:onTouchDown (pointer)

Callback for when the hand’s pointer is poking/touching this view The state in pointer is now “touching”

Arguments

Name Type Description
pointer table see onPointerChanged.

Returns

Nothing


View:onTouchUp (pointer)

Callback for when the hand’s pointer stopped poking/touching this view.

This is a great time to invoke an action based on the touch. For example, if you’re implementing a button, this is where you’d trigger whatever you’re trying to trigger.

NOTE: If pointer.state is now “outside”, the user released the trigger button outside of this view, and you should NOT perform an action, but cancel it instead.

Arguments

Name Type Description
pointer table see onPointerChanged.

Returns

Nothing


View:onInteraction (inter, body, sender)

an interaction message was sent to this specific view.

See Interactions

Arguments

Name Type Description
inter ???  
body ???  
sender ???  

Returns

Nothing


View:onFileDropped (filename, asset_id)

Callback called when a file is dropped on the view

Arguments

Name Type Description
filename string The name of the dropped file
asset_id string The id of the asset dropped on you

Returns

Nothing


View:addPropertyAnimation (anim)

Add an animation of a property of a component to this view For example, you might want to add a one-second animation of transform.matrix.rotation.x from 0 to 6.28, repeating.

Arguments

Name Type Description
anim PropertyAnimation The animation to add to this view.

Returns

Nothing