ixLabel

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("ixLabel")
label:SetText("hello world")
label:SetFont("ixMenuButtonHugeFont")
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

ixLabel:CalculateAlignment(width, height, textWidth, textHeight)

Internal

This is an internal function! You are able to use it, but you risk unintended side effects if used incorrectly.

View source »

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

ixLabel:DrawKernedText(width, height)

Internal

This is an internal function! You are able to use it, but you risk unintended side effects if used incorrectly.

View source »

Draws the current text with the current kerning.

Parameters

  • width number

    Width of the panel

  • height number

    Height of the panel

ixLabel:DrawText(width, height)

Internal

This is an internal function! You are able to use it, but you risk unintended side effects if used incorrectly.

View source »

Draws the current text.

Parameters

  • width number

    Width of the panel

  • height number

    Height of the panel

ixLabel:GetBackgroundColor()

View source »

Returns the current background color for this panel.

Returns

  • color

    Current background color

ixLabel:GetContentAlignment()

View source »

Returns the current content alignment for this panel.

Returns

  • number

    Current content alignment

ixLabel:GetContentSize(bCalculate)

View source »

Returns the size of the text, taking into account the current kerning.

Parameters

  • bCalculate boolean 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

ixLabel:GetFont()

View source »

Returns the current font for this panel.

Returns

ixLabel:GetKerning()

View source »

Returns the current kerning for this panel.

Returns

  • number

    Current kerning

ixLabel:GetPadding()

View source »

Returns how much padding this panel has around its text.

Returns

  • number

    Current padding

ixLabel: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

ixLabel:GetText()

View source »

Returns the current text for this panel.

Returns

ixLabel:GetTextColor()

View source »

Returns the current text color for this panel.

Returns

  • color

    Current text color

ixLabel:SetBackgroundColor(color)

View source »

Sets the color of the background to draw behind the text.

Parameters

  • color color

    New color to use

ixLabel: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

ixLabel: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

ixLabel:SetFont(font)

View source »

Sets the font used to draw the text.

Parameters

  • font string

    Name of the font to use

ixLabel: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

ixLabel: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

ixLabel: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 boolean

    Whether or not to scale

ixLabel:SetText(text)

View source »

Sets the text for this label to display.

Parameters

ixLabel:SetTextColor(color)

View source »

Sets the color of the text to use when drawing.

Parameters

  • color color

    New color to use

ixLabel: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.