Class Label
Used to place text.
Class Label
| label:new () | Constructor. |
| label:setText (text) | Changes the label's text. |
Class 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 themaxTextparameter 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 to10000, but at the moment you want to display0, so you do:local label = ui.Label { text = '0', maxText = '10000' }NOTE: I encourage you to use a monospace font, otherwise
maxTextmight not guarantee it occupies the maximum area. For example, for some fonts the string11111may be shorter than9999.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.falseby default. NOTE: if you want to changetextdinamically don't just assigntextto 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
textproperty. It re-places the block in its enclosing cell also. This function is supposed to be used together with theelideproperty. So use only ifelideistrueand you want to modify the label's text while still be elided. If it's not the case just changetext:self.text = 'new_text_here'.See elide.lua for the example.
Parameters:
- text a string. New label's text.