Clone wiki

FlowGUI / Label

Description

A label is used to display a single line of text.

Functions

  • FG_Label:Create() --Creates a new label
  • SetText() --Set the labels text
  • GetText() --Returns the text of the GUI element
  • SetAutoExpand() --False by default. When set to true, the label automatically expands in its width. When set to false, the text is cut off at the width - offset.
  • SetTextPosition() --Set the text position for this element. Use the predefined text positions for anchoring text. There are 9 fixed text positions that can be used for labels. You can either use the positions name or the number:
    • FG_TextPosition.TopLeft = 0
    • FG_TextPosition.TopCenter = 1
    • FG_TextPosition.TopRight = 2
    • FG_TextPosition.CenterLeft = 3
    • FG_TextPosition.Center = 4
    • FG_TextPosition.CenterRight = 5
    • FG_TextPosition.BottomLeft = 6
    • FG_TextPosition.BottomCenter = 7
    • FG_TextPosition.BottomRight = 8
  • SetDebug(bool false) --False by default. When set to true, a gray rectangle is draw where the label should be.
  • SetMouseHoverEvent(function event) --Stores the function that needs to be executed when the mouse hovers the rectangle of the GUI element.
  • SetMouseDownEvent(function event) --Stores the function that needs to be executed when the mouse hovers and the left mouse button is held down on the rectangle of the GUI element.
  • SetMouseHitEvent(function event) --Stores the function that needs to be executed when the mouse hovers and the left mouse button is hit once on the rectangle of the GUI element.

Examples

This examples creates a simple label with GUI style.

Script.labelStyle = nil --entity "LabelStyle"
Script.label1 = nil

Function Script:Start()
    --retrieve label style
    self.labelStyle = self.labelStyle.script:GetStyle()

    --label 1
    self.label1 = FG_Label:Create()
    self.label1:SetPosition(Vec2(200,60))
    self.label1:SetScale(Vec2(150,50))
    self.label1:SetText("This is a label")
    self.label1:SetGUIStyle(self.labelNormalStyle)
    guiManager:AddElement(self.label1)
end

This examples creates a label that automatically expands the width based ont the given text.

Script.labelStyle = nil --entity "LabelStyle"
Script.label1 = nil

Function Script:Start()
    --retrieve label style
    self.labelStyle = self.labelStyle.script:GetStyle()

    --label 1
    self.label1 = FG_Label:Create()
    self.label1:SetPosition(Vec2(200,60))
    self.label1:SetScale(Vec2(150,50))
    self.label1:SetText("This is a label with auto-expanding enabled, increases the width")
    self.label1:SetGUIStyle(self.labelNormalStyle)
    self.label4:SetAutoExpand(true)
    self.label4:SetDebug(true)
    guiManager:AddElement(self.label1)
end

Updated