Class WLabel
java.lang.Object
io.github.cottonmc.cotton.gui.widget.WWidget
io.github.cottonmc.cotton.gui.widget.WLabel
A single-line label widget.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected intstatic final intThe default text color for dark mode labels.static final intThe default text color for light mode labels.protected booleanprotected HorizontalAlignmentprotected net.minecraft.network.chat.Componentprotected VerticalAlignment -
Constructor Summary
ConstructorsConstructorDescriptionWLabel(net.minecraft.network.chat.Component text) Constructs a new label with the default text color.WLabel(net.minecraft.network.chat.Component text, int color) Constructs a new label. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNarrations(net.minecraft.client.gui.narration.NarrationElementOutput builder) Adds the narrations of this widget to a narration builder.booleanChecks whether this widget can be resized usingWWidget.setSize(int, int).Disables separate dark mode coloring by copying the dark color to be the light color.intgetColor()Gets the light mode color of this label.intGets the dark mode color of this label.booleanChecks whether shadows should be drawn for this label.Gets the horizontal text alignment of this label.net.minecraft.network.chat.ComponentgetText()Gets the text of this label.@Nullable net.minecraft.network.chat.StylegetTextStyleAt(int x, int y) Gets the text style at the specific widget-space coordinates.Gets the vertical text alignment of this label.onClick(net.minecraft.client.input.MouseButtonEvent click, boolean doubled) Notifies this widget that the mouse has been pressed and released, both while inside its bounds.voidpaint(net.minecraft.client.gui.GuiGraphicsExtractor context, int x, int y, int mouseX, int mouseY) Paints this widget.setColor(int color) Sets the light mode color of this label.setColor(int color, int darkmodeColor) Sets the light and dark mode colors of this label.setDarkmodeColor(int color) Sets the dark mode color of this label.setDrawShadows(boolean drawShadows) Sets whether shadows should be drawn for this label.Sets the horizontal text alignment of this label.voidsetSize(int x, int y) Sets the size of this widget.setText(net.minecraft.network.chat.Component text) Sets the text of this label.Sets the vertical text alignment of this label.Methods inherited from class WWidget
addPainters, addTooltip, canFocus, canFocusForTextInput, canHover, getAbsoluteX, getAbsoluteY, getFocusModel, getHeight, getHost, getParent, getWidth, getX, getY, hit, hoveredProperty, isActivationKey, isFocused, isHovered, isNarratable, isWithinBounds, onCharTyped, onFocusGained, onFocusLost, onHidden, onKeyPressed, onKeyReleased, onMouseDown, onMouseDrag, onMouseMove, onMouseScroll, onMouseUp, onPreeditUpdated, onShown, releaseFocus, renderTooltip, requestFocus, setHost, setHovered, setLocation, setParent, shouldRenderInDarkMode, tick, validate
-
Field Details
-
text
protected net.minecraft.network.chat.Component text -
horizontalAlignment
-
verticalAlignment
-
color
protected int color -
darkmodeColor
protected int darkmodeColor -
drawShadows
protected boolean drawShadows -
DEFAULT_TEXT_COLOR
public static final int DEFAULT_TEXT_COLORThe default text color for light mode labels.- See Also:
-
DEFAULT_DARKMODE_TEXT_COLOR
public static final int DEFAULT_DARKMODE_TEXT_COLORThe default text color for dark mode labels.- See Also:
-
-
Constructor Details
-
WLabel
public WLabel(net.minecraft.network.chat.Component text, int color) Constructs a new label.- Parameters:
text- the text of the labelcolor- the color of the label
-
WLabel
public WLabel(net.minecraft.network.chat.Component text) Constructs a new label with the default text color.- Parameters:
text- the text of the label- Since:
- 1.8.0
-
-
Method Details
-
paint
@Environment(CLIENT) public void paint(net.minecraft.client.gui.GuiGraphicsExtractor context, int x, int y, int mouseX, int mouseY) Description copied from class:WWidgetPaints this widget. -
onClick
@Environment(CLIENT) public InputResult onClick(net.minecraft.client.input.MouseButtonEvent click, boolean doubled) Description copied from class:WWidgetNotifies this widget that the mouse has been pressed and released, both while inside its bounds.- Overrides:
onClickin classWWidget- Parameters:
click- the click data whose coordinates are in widget space ((0, 0) is the top-left point of this widget)doubled-trueif this is a double click,falseotherwise- Returns:
InputResult.PROCESSEDif the event is handled,InputResult.IGNOREDotherwise.
-
getTextStyleAt
Gets the text style at the specific widget-space coordinates.- Parameters:
x- the X coordinate in widget spacey- the Y coordinate in widget space- Returns:
- the text style at the position, or null if not found
-
canResize
public boolean canResize()Description copied from class:WWidgetChecks whether this widget can be resized usingWWidget.setSize(int, int). -
setSize
-
getDarkmodeColor
public int getDarkmodeColor()Gets the dark mode color of this label.- Returns:
- the color
- Since:
- 2.0.0
-
setDarkmodeColor
Sets the dark mode color of this label.- Parameters:
color- the new color- Returns:
- this label
-
disableDarkmode
Disables separate dark mode coloring by copying the dark color to be the light color.- Returns:
- this label
-
getColor
public int getColor()Gets the light mode color of this label.- Returns:
- the color
-
setColor
Sets the light mode color of this label.- Parameters:
color- the new color- Returns:
- this label
-
setColor
Sets the light and dark mode colors of this label.- Parameters:
color- the new light colordarkmodeColor- the new dark color- Returns:
- this label
-
getDrawShadows
public boolean getDrawShadows()Checks whether shadows should be drawn for this label.- Returns:
trueshadows should be drawn,falseotherwise- Since:
- 11.1.0
-
setDrawShadows
Sets whether shadows should be drawn for this label.- Parameters:
drawShadows-trueif shadows should be drawn,falseotherwise- Returns:
- this label
- Since:
- 11.1.0
-
getText
public net.minecraft.network.chat.Component getText()Gets the text of this label.- Returns:
- the text
-
setText
Sets the text of this label.- Parameters:
text- the new text- Returns:
- this label
-
getHorizontalAlignment
Gets the horizontal text alignment of this label.- Returns:
- the alignment
- Since:
- 2.0.0
-
setHorizontalAlignment
Sets the horizontal text alignment of this label.- Parameters:
align- the new text alignment- Returns:
- this label
-
getVerticalAlignment
Gets the vertical text alignment of this label.- Returns:
- the alignment
- Since:
- 2.0.0
-
setVerticalAlignment
Sets the vertical text alignment of this label.- Parameters:
align- the new text alignment- Returns:
- this label
-
addNarrations
@Environment(CLIENT) public void addNarrations(net.minecraft.client.gui.narration.NarrationElementOutput builder) Description copied from class:WWidgetAdds the narrations of this widget to a narration builder. Narrations will only apply if this widget is narratable.The widget needs to be focusable or hoverable, and also be focused/hovered for narrations to be added.
- Overrides:
addNarrationsin classWWidget- Parameters:
builder- the narration builder, cannot be null
-