cityrpLabel
Alternative to DLabel that adds extra functionality.
This panel is meant for drawing single-line text. It can add extra kerning (spaces between letters), and it can forcefully scale the text down to fit the current width, without cutting off any letters. Text scaling is most useful when docking this this panel without knowing what the width could be. For example, text scaling is used for the character name in the character status menu.
local label = vgui.Create("cityrpLabel")
label:SetText("hello world")
label:SetFont("cityrpMenuButtonHugeFont")
label:SetContentAlignment(5)
label:SetTextColor(Color(255, 255, 255, 255))
label:SetBackgroundColor(Color(200, 30, 30, 255))
label:SetPadding(8)
label:SetScaleWidth(true)
label:SizeToContents()
Functions
cityrpLabel:CalculateAlignment(width, height, textWidth, textHeight)
This is an internal function! You are able to use it, but you risk unintended side effects if used incorrectly.
Returns the X and Y location of the text taking into account the text alignment and padding.
Parameters
-
width
number
Width of the panel
-
height
number
Height of the panel
-
textWidth
number
Width of the text
-
textHeight
number
Height of the text
Returns
-
number
X location to draw the text
-
number
Y location to draw the text
cityrpLabel:DrawKernedText(width, height)
This is an internal function! You are able to use it, but you risk unintended side effects if used incorrectly.
Draws the current text with the current kerning.
Parameters
-
width
number
Width of the panel
-
height
number
Height of the panel
cityrpLabel:DrawText(width, height)
This is an internal function! You are able to use it, but you risk unintended side effects if used incorrectly.
Draws the current text.
Parameters
-
width
number
Width of the panel
-
height
number
Height of the panel
cityrpLabel:GetBackgroundColor()
View source »Returns the current background color for this panel.
Returns
-
color
Current background color
cityrpLabel:GetContentAlignment()
View source »Returns the current content alignment for this panel.
Returns
-
number
Current content alignment
cityrpLabel:GetContentSize(bCalculate)
View source »Returns the size of the text, taking into account the current kerning.
Parameters
-
bCalculate
bool
default: false
Whether or not to recalculate the content size instead of using the cached copy
Returns
-
number
Width of the text
-
number
Height of the text
cityrpLabel:GetFont()
View source »Returns the current font for this panel.
Returns
-
string
Name of current font
cityrpLabel:GetKerning()
View source »Returns the current kerning for this panel.
Returns
-
number
Current kerning
cityrpLabel:GetPadding()
View source »Returns how much padding this panel has around its text.
Returns
-
number
Current padding
cityrpLabel:GetScaleWidth()
View source »Returns whether or not this panel will scale its text down to fit its width.
Returns
-
bool
Whether or not this panel will scale its text
cityrpLabel:GetText()
View source »Returns the current text for this panel.
Returns
-
string
Current text
cityrpLabel:GetTextColor()
View source »Returns the current text color for this panel.
Returns
-
color
Current text color
cityrpLabel:SetBackgroundColor(color)
View source »Sets the color of the background to draw behind the text.
Parameters
-
color
Color
New color to use
cityrpLabel:SetContentAlignment(alignment)
View source »Changes how the text is aligned when drawing. Valid content alignment values include numbers 1
through 9
. Each number's
corresponding alignment is based on its position on a numpad. For example, 1
is bottom-left, 5
is centered, 9
is
top-right, etc.
Parameters
-
alignment
number
Alignment to use
cityrpLabel:SetDropShadow(distance, color)
View source »Sets the drop shadow to draw behind the text.
Parameters
-
distance
number
How far away to draw the shadow in pixels. Set to
0
to disable
-
color
Color
optional
Color of the shadow. Defaults to a dimmed version of the text color
cityrpLabel:SetFont(font)
View source »Sets the font used to draw the text.
Parameters
-
font
string
Name of the font to use
cityrpLabel:SetKerning(kerning)
View source »Sets the spacing between each character of the text in pixels. Set to 0
to disable. Kerning is disabled by default.
Parameters
-
kerning
number
How far apart to draw each letter
cityrpLabel:SetPadding(padding)
View source »How much spacing to use around the text when its drawn. This uses uniform padding on the top, left, right, and bottom of this panel.
Parameters
-
padding
number
Padding to use
cityrpLabel:SetScaleWidth(bScale)
View source »Whether or not to scale the width of the text down to fit the width of this panel, if needed.
Parameters
-
bScale
bool
Whether or not to scale
cityrpLabel:SetText(text)
View source »Sets the text for this label to display.
Parameters
-
text
string
Text to display
cityrpLabel:SetTextColor(color)
View source »Sets the color of the text to use when drawing.
Parameters
-
color
Color
New color to use
cityrpLabel:SizeToContents()
View source »Sets the size of the panel to fit the content size with the current padding. The content size is recalculated when this method is called.