Class Label

Used to place text.

Class Label

label:new () Constructor.
label:setText (text) Changes the label's text.


Class Label

Represents a label.
label:new ()

Constructor.

  • text : a string. The text to be displayed.

  • maxText : a string. The text of maximum possible length displayed by this label. Let us explain: as you know the size of a block is calculated once per a call to Block:place, however, it is highly likely you want to change the text "on-the-fly", f.e., when displaying HP or XP of a character, current FPS, or the number of items left in a slot. You don't want to re-place the HUD every time you need to change the text. More over, you don't want the HUD to vary in size if text is changed. That is where the maxText parameter comes to play: it reserves the necessary area on the screen to fit any text there. So suppose you have a label in your HUD that displays XP. You know that the maximum possible XP is limited to 10000, but at the moment you want to display 0, so you do:

    local label = ui.Label {
      text    = '0',
      maxText = '10000'
    }
    

    NOTE: I encourage you to use a monospace font, otherwise maxText might not guarantee it occupies the maximum area. For example, for some fonts the string 11111 may be shorter than 9999.

  • color : a color like in love2d (the table variant). The color of the text.

  • elide : a boolean meaning whether the text is cut when the label doesn't fit its enclosing cell. false by default. NOTE: if you want to change text dinamically don't just assign text to a new value: it won't elide. Instead use the Label:setText member-function.

    ■────────────╮
    │ A veeeery long label  -- elide = false
    ╰────────────╯
    
    ■────────────╮
    │ A veeeer...│          -- elide = true
    ╰────────────╯
    

    See elide.lua for the example.

label:setText (text)
Changes the label's text. NOTE: it doesn't just assign a new value to the text property. It re-places the block in its enclosing cell also. This function is supposed to be used together with the elide property. So use only if elide is true and you want to modify the label's text while still be elided. If it's not the case just change text: self.text = 'new_text_here'.

See elide.lua for the example.

Parameters:

  • text a string. New label's text.
generated by LDoc 1.5.0 Last updated 2026-06-27 06:43:04