Skip to content

Alignable ​

com.jsmacrosce.jsmacros.client.api.classes.render.components.Alignable

Since1.8.4

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 ​

align(String horizontal, String vertical): B extends Alignable<B>Since1.8.4#
Aligns this element horizontally and vertically within its parent, with zero offset on both axes.

Parameters:

  • horizontal: the horizontal alignment to use
  • vertical: 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 use
  • horizontalOffset: the horizontal offset to use
  • vertical: the vertical alignment to use
  • verticalOffset: the vertical offset to use
Returns: self for chaining.

See:

align(Alignable<?> other, String horizontal, String vertical): B extends Alignable<B>Since1.8.4#
Aligns this element horizontally and vertically against other, with zero offset on both axes.

Parameters:

  • other: the element to align to
  • horizontal: the horizontal alignment to use
  • vertical: 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 to
  • horizontal: the horizontal alignment to use
  • horizontalOffset: the horizontal offset to use
  • vertical: the vertical alignment to use
  • verticalOffset: the vertical offset to use
Returns: self for chaining.

See:

alignHorizontally ​

alignHorizontally(Alignable<?> other, String alignment): B extends Alignable<B>Since1.8.4#
Aligns this element horizontally against other with zero offset.

Parameters:

  • other: the element to align to
  • alignment: 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 to
  • alignment: the alignment to use
  • offset: the offset to use
Returns: self for chaining.
alignHorizontally(String alignment): B extends Alignable<B>Since1.8.4#
Aligns this element horizontally within its parent with zero offset.

Parameters:

  • alignment: the alignment to use
Returns: self for chaining.

See:

alignHorizontally(String alignment, int offset): B extends Alignable<B>Since1.8.4#
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 use
  • offset: the offset to use
Returns: self for chaining.

alignVertically ​

alignVertically(Alignable<?> other, String alignment): B extends Alignable<B>Since1.8.4#
Aligns this element vertically against other with zero offset.

Parameters:

  • other: the element to align to
  • alignment: 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 to
  • alignment: the alignment to use
  • offset: the offset to use
Returns: self for chaining.
alignVertically(String alignment): B extends Alignable<B>Since1.8.4#
Aligns this element vertically within its parent with zero offset.

Parameters:

  • alignment: the alignment to use
Returns: self for chaining.

See:

alignVertically(String alignment, int offset): B extends Alignable<B>Since1.8.4#
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 use
  • offset: the offset to use
Returns: self for chaining.

getParentHeight ​

getParentHeight(): intSince1.8.4#
Returns the height used as the reference by parent-relative alignment.
Returns: the height of the parent element.

getParentWidth ​

getParentWidth(): intSince1.8.4#
Returns the width used as the reference by parent-relative alignment.
Returns: the width of the parent element.

getScaledBottom ​

getScaledBottom(): intSince1.8.4#
Returns the bottom edge, calculated as the top edge plus the scaled height.
Returns: the position of the scaled element's bottom side.

getScaledHeight ​

getScaledHeight(): intSince1.8.4#
Returns this element's height after scaling, truncated to an integer; alignment uses this height.
Returns: the scaled height of the element.

getScaledLeft ​

getScaledLeft(): intSince1.8.4#
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 ​

getScaledRight(): intSince1.8.4#
Returns the right edge, calculated as the left edge plus the scaled width.
Returns: the position of the scaled element's right side.

getScaledTop ​

getScaledTop(): intSince1.8.4#
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 ​

getScaledWidth(): intSince1.8.4#
Returns the element's width after scaling, truncated to an integer; alignment uses this width.
Returns: the scaled width of the element.

moveTo ​

moveTo(int x, int y): B extends Alignable<B>Since1.8.4#
Sets this element's position. Implementations determine how its dimensions are preserved; the single-axis helpers use this method while retaining the other axis.

Parameters:

  • x: the new x position
  • y: the new y position
Returns: self for chaining.

moveToX ​

moveToX(int x): B extends Alignable<B>Since1.8.4#
Moves this element to x, retaining its current top coordinate.

Parameters:

  • x: the new x position
Returns: self for chaining.

moveToY ​

moveToY(int y): B extends Alignable<B>Since1.8.4#
Moves this element to y, retaining its current left coordinate.

Parameters:

  • y: the new y position
Returns: self for chaining.

parsePercentage ​

static parsePercentage(String string): intSince1.8.4#
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.