Skip to content

Commit

Permalink
Add option for WLabel to have shadows
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusElg committed Aug 3, 2024
1 parent 951c759 commit 462fbe8
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ public WLabel(Text text) {
public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) {
int yOffset = TextAlignment.getTextOffsetY(verticalAlignment, height, 1);

ScreenDrawing.drawString(context, text.asOrderedText(), horizontalAlignment, x, y + yOffset, this.getWidth(), shouldRenderInDarkMode() ? darkmodeColor : color);
if (areShadowsDrawn()) {
ScreenDrawing.drawStringWithShadow(context, text.asOrderedText(), horizontalAlignment, x, y + yOffset, this.getWidth(), shouldRenderInDarkMode() ? darkmodeColor : color);
} else {
ScreenDrawing.drawString(context, text.asOrderedText(), horizontalAlignment, x, y + yOffset, this.getWidth(), shouldRenderInDarkMode() ? darkmodeColor : color);
}

Style hoveredTextStyle = getTextStyleAt(mouseX, mouseY);
ScreenDrawing.drawTextHover(context, hoveredTextStyle, x + mouseX, y + mouseY);
Expand Down Expand Up @@ -176,6 +180,28 @@ public WLabel setColor(int color, int darkmodeColor) {
return this;
}

/**
* Checks whether shadows should be drawn for this label.
*
* @return {@code true} shadows should be drawn, {@code false} otherwise
* @since 11.0.1
*/
public boolean areShadowsDrawn() {
return drawShadows;
}

/**
* Sets whether shadows should be drawn for this labbel.
*
* @param drawShadows {@code true} if shadows should be drawn, {@code false} otherwise
* @return this label
* @since 11.0.1
*/
public WLabel setDrawShadows(boolean drawShadows) {
this.drawShadows = drawShadows;
return this;
}

/**
* Gets the text of this label.
*
Expand Down

0 comments on commit 462fbe8

Please sign in to comment.