-
Notifications
You must be signed in to change notification settings - Fork 49
Labels and texts
Labels are the simplest widget. They display a single line of text.
There are two types of labels in LibGui: WLabel
s and WDynamicLabel
s.
WLabel
has a normal Text
object which can be manipulated with setters. WDynamicLabel
pulls its text as a string each time it renders, so it's useful for rapidly updating data.
A WLabel
can be made from any kind of Text
, like Text.translatable
or Text.literal
.
Example:
WLabel label = new WLabel(Text.translatable("block.minecraft.stone"));
root.add(label, 0, 0, 4, 1);
The text of a label is on the left side by default. You can use WLabel.setHorizontalAlignment()
to change the alignment to CENTER
or RIGHT
.
label.setHorizontalAlignment(HorizontalAlignment.CENTER);
The color of a label changes depending on the darkmode setting of LibGui. You can tweak your labels light and dark colors using WLabel.setColor()
and WLabel.setDarkmodeColor()
. The darkmode color can be disabled using WLabel.disableDarkmode()
.
label.setColor(0xFF0000).setDarkmodeColor(0x0000FF);
Dynamic labels (WDynamicLabel
) gets its text from a Supplier<String>
each time it renders.
Translations in dynamic labels should be done with Minecraft's I18n
class.
// A label that shows the time:
WDynamicLabel label = new WDynamicLabel(() -> I18n.translate("text.my_mod.time", System.currentTimeMillis()));
en_us.json
:
{
"text.my_mod.time": "Time: %d"
}