Alignable
com.jsmacrosce.jsmacros.client.api.classes.render.components.Alignable
Provides fluent horizontal and vertical alignment for render elements. Parent-relative methods use the overlay parent, or the window when there is no parent; overloads taking another Alignable position this element against that element. Alignment methods move the element and return its concrete self type.
js
const draw = Hud.createDraw2D();
const panel = draw.addRect(0, 0, 200, 100, Color.argb(0x80, 0, 0, 0));
const label = draw.addText("centred", 0, 0, Color.rgb(0xFF, 0xFF, 0xFF), true);
// the text is put in the middle of the rectangle
label.align(panel, "center", "center");
draw.register();Available in scripts as RenderElements.Alignable.
Type Parameters
B: the builder class
Methods
align
Aligns this element horizontally and vertically within its parent, with zero offset on both axes.
Parameters:
horizontal: the horizontal alignment to usevertical: the vertical alignment to use
Returns: self for chaining.
See:
align(String horizontal, int horizontalOffset, String vertical, int verticalOffset): B extends Alignable<B>Since1.8.4#Aligns this element horizontally and vertically within its parent, applying an independent offset on each axis.
Parameters:
horizontal: the horizontal alignment to usehorizontalOffset: the horizontal offset to usevertical: the vertical alignment to useverticalOffset: the vertical offset to use
Returns: self for chaining.
See:
Aligns this element horizontally and vertically against
other, with zero offset on both axes.Parameters:
other: the element to align tohorizontal: the horizontal alignment to usevertical: the vertical alignment to use
Returns: self for chaining.
See:
align(Alignable<?> other, String horizontal, int horizontalOffset, String vertical, int verticalOffset): B extends Alignable<B>Since1.8.4#Aligns this element horizontally and vertically against
other, applying an independent offset on each axis.Parameters:
other: the element to align tohorizontal: the horizontal alignment to usehorizontalOffset: the horizontal offset to usevertical: the vertical alignment to useverticalOffset: the vertical offset to use
Returns: self for chaining.
See:
alignHorizontally
Aligns this element horizontally against
other with zero offset.Parameters:
other: the element to align toalignment: the alignment to use
Returns: self for chaining.
See:
alignHorizontally(Alignable<?> other, String alignment, int offset): B extends Alignable<B>Since1.8.4#Aligns this element horizontally against
other. The case-insensitive alignment has the form [left|center|right|x%]On[left|center|right|x%]; the first part selects this element's anchor and the second selects the anchor on other. Percentages are whole numbers from 0 to 100. The offset is added to this element's resulting x position. Unlike parent-relative alignment, malformed alignments throw.Parameters:
other: the element to align toalignment: the alignment to useoffset: the offset to use
Returns: self for chaining.
Aligns this element horizontally within its parent with zero offset.
Parameters:
alignment: the alignment to use
Returns: self for chaining.
See:
Aligns this element horizontally within its parent using
left, center, right, or an integer percentage from 0 to 100. Percentages position the element within the remaining parent width after its own width; the offset is added to its x position. Unsupported strings do nothing; a string ending in % with a non-integer number throws NumberFormatException. Out-of-range percentages do nothing.Parameters:
alignment: the alignment to useoffset: the offset to use
Returns: self for chaining.
alignVertically
Aligns this element vertically against
other with zero offset.Parameters:
other: the element to align toalignment: the alignment to use
Returns: self for chaining.
See:
alignVertically(Alignable<?> other, String alignment, int offset): B extends Alignable<B>Since1.8.4#Aligns this element vertically against
other. The case-insensitive alignment has the form [top|center|bottom|y%]On[top|center|bottom|y%]; the first part selects this element's anchor and the second selects the anchor on other. Percentages are whole numbers from 0 to 100. The offset is added to this element's resulting y position. Malformed alignments throw.Parameters:
other: the element to align toalignment: the alignment to useoffset: the offset to use
Returns: self for chaining.
Aligns this element vertically within its parent with zero offset.
Parameters:
alignment: the alignment to use
Returns: self for chaining.
See:
Aligns this element vertically within its parent using
top, center, bottom, or an integer percentage from 0 to 100. Measured against the parent, which is the overlay the element was added to, or the window when it has no parent. top is the parent's top edge, center centres the element in the parent and bottom puts the element's bottom edge on the parent's bottom edge. A percentage is a share of the space the element does not fill, so 0% is at the top and 100% is at the bottom. A percentage positions the element within the space remaining after its height; the offset is added to the resulting y position. Unsupported strings do nothing. A string ending in % with a non-integer number throws NumberFormatException; out-of-range integers are ignored.Parameters:
alignment: the alignment to useoffset: the offset to use
Returns: self for chaining.
getParentHeight
Returns the height used as the reference by parent-relative alignment.
Returns: the height of the parent element.
getParentWidth
Returns the width used as the reference by parent-relative alignment.
Returns: the width of the parent element.
getScaledBottom
Returns the bottom edge, calculated as the top edge plus the scaled height.
Returns: the position of the scaled element's bottom side.
getScaledHeight
Returns this element's height after scaling, truncated to an integer; alignment uses this height.
Returns: the scaled height of the element.
getScaledLeft
Returns this element's left edge, used as its x position by alignment methods.
Returns: the position of the scaled element's left side.
getScaledRight
Returns the right edge, calculated as the left edge plus the scaled width.
Returns: the position of the scaled element's right side.
getScaledTop
Returns this element's top edge, used as its y position by alignment methods.
Returns: the position of the scaled element's top side.
getScaledWidth
Returns the element's width after scaling, truncated to an integer; alignment uses this width.
Returns: the scaled width of the element.
moveTo
moveToX
moveToY
parsePercentage
Parses an integer percentage with a trailing
%. Values outside 0–100 and strings without the suffix return -1; a suffixed non-integer throws NumberFormatException.Parameters:
string: the string to parse
Returns: the percentage as a whole number from 0 to 100, or
-1 if the string has no % on the end or the number in front of it is outside that range.