Skip to main content

Button

UIKit has multiple button components: RectangleButton, CapsuleButton, and RoundButton. Each button extends an underlying BaseButton component. So, they share a lot of functionality. For example, each button has a style dropdown to easily swap between visual styles. Another example is any button can be turned into a toggle. This means that, when triggered, it will "stay on".

Here is visual reference for each button:

RectangleButton



CapsuleButton



RoundButton



Style Dropdown

Component Breakdown

Here is the component panel for a RectangleButton



Render OrderSets the renderOrder of the visual components of the element.
SizeSets the size of the element. X is width, Y is height and Z is the depth of the underlying collider.
InactiveMakes the element impossible to interact with. Think "grayed out".
Play AudioTurns on the built-in audio cues for the element.
StyleDropdown selects between the multiple visual styles available for the element.
Has ShadowTurns on the built in shadow for this element.
Shadow Position Offset(shows if Has Shadow is checked) The offset position for the shadow.
ToggleableSets this element to have a toggle behavior. When triggered this element will stay on.
Default To On(shows if Toggleable is checked) Sets the default state of the toggleable element to "on".
Add CallbacksAdds the editor hooks for the event callbacks to the element.
On Trigger Up CallbacksA callback for when the element finishes a trigger lifecycle.
On Trigger Down CallbacksA callback for when the element starts a trigger lifecycle.
On Value Changed CallbacksA callback for when the element's value changes.
On Finished CallbacksA callback for when the element interaction and changes are all finished.

Code Example

import { RectangleButton } from 'SpectaclesUIKit.lspkg/Scripts/Components/Button/RectangleButton';

/**
* A simple programmatic button example
*/

@component
export class ExampleButtonScript extends BaseScriptComponent {
onAwake() {
// create new button
const button = this.sceneObject.createComponent(
RectangleButton.getTypeName()
);

// update button settings
button.size = new vec3(10, 4, 1);

// call initialize to finish button internal setup
button.initialize();

// attach events
button.onTriggerUp.add(() => {
print('Button fully triggered!');
});
}
}
Was this page helpful?
Yes
No