Class WDynamicLabel
java.lang.Object
io.github.cottonmc.cotton.gui.widget.WWidget
io.github.cottonmc.cotton.gui.widget.WDynamicLabel
Dynamic labels are labels that pull their text from a
Supplier<String>
.
They can be used for automatically getting data from a block entity or another data source.
Translating strings in dynamic labels should be done using
I18n.translate(String, Object...)
.
-
Field Summary
Modifier and TypeFieldDescriptionprotected HorizontalAlignment
protected int
protected int
static final int
The default text color for dark mode labels.static final int
The default text color for light mode labels.protected boolean
protected VerticalAlignment
-
Constructor Summary
ConstructorDescriptionWDynamicLabel
(Supplier<String> text) Constructs a new dynamic label with the default text color.WDynamicLabel
(Supplier<String> text, int color) Constructs a new dynamic label. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks 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.Gets the horizontal text alignment of this label.boolean
Checks whether shadows should be drawn for this label.Gets the vertical text alignment of this label.void
paint
(DrawContext context, int x, int y, int mouseX, int mouseY) Paints this widget.setAlignment
(HorizontalAlignment align) Sets the horizontal text alignment 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.void
setSize
(int x, int y) Sets the size of this widget.Sets the text of this label.Sets the vertical text alignment of this label.Methods inherited from class io.github.cottonmc.cotton.gui.widget.WWidget
addNarrations, addPainters, addTooltip, canFocus, canHover, getAbsoluteX, getAbsoluteY, getFocusModel, getHeight, getHost, getParent, getWidth, getX, getY, hit, hoveredProperty, isActivationKey, isFocused, isHovered, isNarratable, isWithinBounds, onCharTyped, onClick, onFocusGained, onFocusLost, onHidden, onKeyPressed, onKeyReleased, onMouseDown, onMouseDrag, onMouseMove, onMouseScroll, onMouseUp, onShown, releaseFocus, renderTooltip, requestFocus, setHost, setHovered, setLocation, setParent, shouldRenderInDarkMode, tick, validate
-
Field Details
-
text
-
alignment
-
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
-
WDynamicLabel
Constructs a new dynamic label.- Parameters:
text
- the text of the labelcolor
- the color of the label
-
WDynamicLabel
Constructs a new dynamic label with the default text color.- Parameters:
text
- the text of the label
-
-
Method Details
-
paint
Description copied from class:WWidget
Paints this widget. -
canResize
public boolean canResize()Description copied from class:WWidget
Checks whether this widget can be resized usingWWidget.setSize(int, int)
. -
setSize
public void setSize(int x, int y) Description copied from class:WWidget
Sets the size of this widget.Overriding methods may restrict one of the dimensions to be a constant value, for example
super.setSize(x, 20)
. -
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
-
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:
true
shadows should be drawn,false
otherwise- Since:
- 11.1.0
-
setDrawShadows
Sets whether shadows should be drawn for this label.- Parameters:
drawShadows
-true
if shadows should be drawn,false
otherwise- Returns:
- this label
- Since:
- 11.1.0
-
setText
Sets the text of this label.- Parameters:
text
- the new text- Returns:
- this label
-
getAlignment
Gets the horizontal text alignment of this label.- Returns:
- the alignment
- Since:
- 11.1.0
-
setAlignment
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:
- 11.1.0
-
setVerticalAlignment
Sets the vertical text alignment of this label.- Parameters:
align
- the new text alignment- Returns:
- this label
- Since:
- 11.1.0
-