Last updated
Last updated
Now that you know the basics, let’s extend our script by allowing the user to toggle the text. We can do this by adding a control to the menu.
Let’s start by creating a simple checkbox:
Each control has a unique ID, which the UI framework uses to distinguish controls within containers. It’s very important that your control’s ID doesn’t conflict with others, as that could result in a broken state or worse.
To create the ID, call and pass the desired ID.
Then, create the checkbox by calling and passing the ID structure you've created.
By default, controls are typically placed in rows - layouts that stack elements in a specific manner. We provide a simple helper function - .
With the control and row ready, let’s add them to a group.
In this example, we'll use the lua>elements a
group. First, locate that group in the global context:
That's it!
Next, let’s modify our previous script so the text only appears if the checkbox is checked. Wrap your drawing code in an if
statement before rendering the text:
and close it after.
The final script should look something like this:
And here's the result:
Then call its method to include your row:
It is very important to call method if you add multiple controls, so the layout will stack everything correctly.