Label Element
Label
is a basic UI element in Weo, used to display text within a RenderSurface
.
Label Element Element
Constructor
Label.new()
Function
Label.new(RenderSurface, LabelProperties)
- Creates a new
Label
on the givenRenderSurface
.
Parameters:
-
RenderSurface
RenderSurface- The RenderSurface where the Label will be rendered.
-
LabelProperties
table-
A table containing properties for the Label.
-
absolute
table— READONLY: Absolute position and size of the Label. Changing this property has no effect.-
Table containing absolute position and size:
position
Vector2— Absolute position of the Label.size
Vector2— Absolute size of the Label.
-
-
position
UDim2— Position of the Label. -
size
Vector2— READONLY: Size of the Label, determined automatically by theRenderSurface:measure(text)
method. Padding andUDim2.*.Scale
should work as expected. -
text
string— Text content of the Label. -
font
string— Font of the Label. -
fontsize
number— Font size of the Label. -
fontstyle
Enum.FontStyle— Font style of the Label. -
fontweight
number— Font weight of the Label. -
textcolor
number?LinearGradient?RadialGradient?— Text color of the Label. -
zIndex
number?— Z-index of the Label. -
parent
any— Parent container of the Label. -
cursor
string?— Cursor style of the Label. -
opacity
number?— Opacity of the Label. This overwrites thetextcolor
property. Does not applies toGradient
types. -
class
table?— Class of the Label,for theThemeService
.- Table containing class properties:
- This property expects
table<string|nil>|nil
.
- This property expects
- Table containing class properties:
-
padding
table?— Padding of the Frame.- Table containing padding properties:
top
number?— Top padding of the Frame.bottom
number?— Bottom padding of the Frame.left
number?— Left padding of the Frame.right
number?— Right padding of the Frame.
- Table containing padding properties:
-
Methods
(Label):Destroy()
Function
- Destroys the
Label
and all its children.
Calling
:Destroy()
does not set your variable tonil
. The object will no longer be rendered or functional, but the Lua variable holding the reference. You must set object tonil
if you want to allow the object to be garbage collected.
(Label):show()
Function
- Makes the
Label
visible.
(Label):hide()
Function
- Hides the
Label
.
Signals
(Label).MouseHover
Signal
- Fires when the mouse hovers over the Label.
Parameters:
- position Vector2— hover position relative to the window
-
buttons
table— mouse buttons state-
Table containing mouse button states:
left
— Left mouse button state.middle
— Middle mouse button state.right
— Right mouse button state.control
— Control key state.shift
— Shift key state.
-
(Label).MouseButton1Click
Signal
- Fires when the Label is clicked with the left mouse button.
Parameters:
- position Vector2— click position relative to the window
(Label).MouseButton2Click
Signal
- Fires when the Label is clicked with the right mouse button.
Parameters:
- position Vector2— click position relative to the window
(Label).MouseButtonDown
Signal
- Fires when a mouse button is pressed down on the Label.
Parameters:
- position Vector2— mouse position relative to the window
-
buttons
table— mouse buttons state-
Table containing mouse button states:
left
— Left mouse button state.middle
— Middle mouse button state.right
— Right mouse button state.control
— Control key state.shift
— Shift key state.
-
(Label).MouseButtonUp
Signal
- Fires when a mouse button is released on the Label.
Parameters:
- position Vector2— mouse position relative to the window
-
buttons
table— mouse buttons state-
Table containing mouse button states:
left
— Left mouse button state.middle
— Middle mouse button state.right
— Right mouse button state.control
— Control key state.shift
— Shift key state.
-
(Label).MouseWheel
Signal
- Fires when the mouse wheel is scrolled while hovering over the Label.
Parameters:
- delta number— scroll amount
(Label).MouseLeave
Signal
- Fires when the mouse leaves the Label area.
Parameters:
- position Vector2— last mouse position before leaving
-
buttons
table— mouse buttons state-
Table containing mouse button states:
left
— Left mouse button state.middle
— Middle mouse button state.right
— Right mouse button state.control
— Control key state.shift
— Shift key state.
-
(Label).Shown
Signal
- Fires when the Label becomes visible.
(Label).Hidden
Signal
- Fires when the Label is hidden.
(Label).Destroyed
Signal
- Fires when the Label is destroyed.
Example
local label = Label.new(RenderSurface, {
position = UDim2.new(0, 20, 0, 20),
text = "Hello World",
font = "Arial",
fontsize = 16,
fontstyle = Enum.FontStyle.Normal,
fontweight = 400,
textcolor = Color.fromRGBA(255, 255, 255, 255),
zIndex = 1,
parent = FrameInstance,
})
label.MouseButton1Click:Connect(function(p)
print("Label clicked at:", p.x, p.y)
end)
Notes
absolute
andsize
are read-only; useposition
andRenderSurface:measure(text)
to handle layout and sizing.
- First argument of
Label.new()
should be an instance ofRenderSurface
,it's not theparent
of the label. You must setparent
inLabelProperties
.