Skip to content

Latest commit

 

History

History
101 lines (74 loc) · 1.89 KB

2.New.md

File metadata and controls

101 lines (74 loc) · 1.89 KB

New

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 = {}
}

Adding Children

You can use the following methods to add children after creating the New object.

  • Push()
  • PushChildren()
  • Call the object again with children = {}

1. Push()

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)    
} )

2. PushChildren()

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",
}

3. Call the object again.

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 = {}
}

Getting the Instance of a New Object.

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