Creating UI objects (or objects in general) has never been easier.
The New
function takes in the class name and returns a New
object. You can call this object to set properties, create connections, and use custom quark properties.
local Quark = require(game.ReplicatedStorage.Quark)
local New = Quark.New
New "TextLabel" {
property = 100,
connection = function(self, ...)
end,
children = {}
}
You can use the following methods to add children after creating the New
object.
- Push()
- PushChildren()
- Call the object again with
children = {}
Takes a single Instance/New object and adds it to the children. (This also adds it into Cleanup).
local MyObject = New "TextLabel" {
-- Defaults hidden for clarity...
}
MyObject:Push( Part )
MyObject:Push( New "UICorner" {
CornerRadius = UDim.new(0, 10)
} )
Takes a table of Instances/New objects and adds all of them to the children. (Also adds them into Cleanup).
local Frame = New "Frame" {
-- Defaults hidden for clarity...
}
Frame:PushChildren {
New "TextLabel" {},
New "TextButton" {},
}
Just call the object and add the children
Quark property.
local Frame = New "Frame" {
-- Defaults hidden for clarity...
}
Frame {
children = {
-- Add children here
}
}
You can also just call the New
object as many times as you want since it just returns itself.
E.g.
local Frame = New "Frame" {
-- Defaults hidden for clarity...
}
-- EVENTS
{
MouseEnter = function(self, ...)
end,
}
-- CHILDREN
{
children = {}
}
You can get the Object property of a New
object. This is the Instance created when New
is called.
local Frame = New "Frame"
Frame.Object:Destroy() -- Destroy the object
Wow, you can create objects now, this isn't limited to UI either. What about making them reactive?
Chapter 3: Reactivity