aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/component/PlainTextComponent.java
blob: 59e82e4e3c0d1d126414a8f00255ba7e8d5d492f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package de.hysky.skyblocker.skyblock.tabhud.widget.component;

import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

/**
 * Component that consists of a line of text.
 */
public class PlainTextComponent extends Component {

    private Text text;

    public PlainTextComponent(Text txt) {
        this.text = txt;

        if (txt == null) {
            this.text = Text.literal("No data").formatted(Formatting.GRAY);
        }

        this.width = PAD_S + txtRend.getWidth(this.text); // looks off without padding
        this.height = txtRend.fontHeight;
    }

    @Override
    public void render(DrawContext context, int x, int y) {
        context.drawText(txtRend, text, x + PAD_S, y, 0xffffffff, false);
    }

}