mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
Initial commit
This commit is contained in:
commit
cb002f4f27
50 changed files with 4666 additions and 0 deletions
60
docs/tut/crash-course/2-creation.md
Normal file
60
docs/tut/crash-course/2-creation.md
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
# Creating UI Elements
|
||||
|
||||
Instances are created using [`create()`](../../api/creation.md#create).
|
||||
|
||||
```lua
|
||||
local vide = require(path_to_vide)
|
||||
local create = vide.create
|
||||
```
|
||||
|
||||
`create()` returns a constructor for a given class which then takes a table of
|
||||
properties to assign when creating a new instance for that class.
|
||||
|
||||
```lua
|
||||
local frame = create "Frame" {
|
||||
Name = "Background",
|
||||
Position = UDim2.fromScale(0.5, 0.5)
|
||||
}
|
||||
```
|
||||
|
||||
String keys are assigned as properties and integer keys are assigned as child
|
||||
instances.
|
||||
|
||||
```lua
|
||||
create "ScreenGui" {
|
||||
Parent = game.StarterGui,
|
||||
|
||||
create "Frame" {
|
||||
AnchorPoint = Vector2.new(0.5, 0.5),
|
||||
Position = UDim2.fromScale(0.5, 0.5),
|
||||
Size = UDim2.fromScale(0.4, 0.7),
|
||||
|
||||
create "TextLabel" {
|
||||
Text = "hi"
|
||||
},
|
||||
|
||||
create"TextLabel" {
|
||||
Text = "bye"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
To connect to an event, just set the event property name to a function.
|
||||
|
||||
All event arguments are passed into the function.
|
||||
|
||||
```lua
|
||||
create "TextButton" {
|
||||
Activated = function()
|
||||
print "clicked!"
|
||||
end
|
||||
}
|
||||
```
|
||||
|
||||
In short:
|
||||
|
||||
- String keys = properties
|
||||
- Function values = events
|
||||
- Non-function values = property values
|
||||
- Numeric keys = children
|
||||
Loading…
Add table
Add a link
Reference in a new issue