# Draw2DElement

`com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement`

**Since:** 1.8.4

Draws a [Draw2D](../Draw2D.md) as a positioned, scaled, and rotated element of another overlay.  
 
 Its nested overlay is transformed as one element; content outside its width or height
 is not clipped. Dimensions default to suppliers that follow the builder's parent.  
 
 ```js
const outer = Hud.createDraw2D();  
const panel = Hud.createDraw2D();  
panel.addText("inside the panel", 5, 5, Color.rgb(0xFF, 0xFF, 0xFF), true);  
// lands at 25, 25 on the outer overlay, and is not clipped to 100 by 50
outer.draw2DBuilder(panel).pos(20, 20).size(100, 50).buildAndAdd();  
outer.register();  
 ```

Available in scripts as `RenderElements.Draw2D`.

## Nested types

- [Builder](Draw2DElement.Builder.md)

## Constructors

### new Draw2DElement {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_constructor-Draw2D-int-int-IntSupplier-IntSupplier-int-float-float-}

```js
new Draw2DElement(Draw2D draw2D, int x, int y, IntSupplier width, IntSupplier height, int zIndex, float scale, float rotation)
```

Creates an element nesting the specified overlay. Rotation is about the positioned
 corner by default; use [setRotateCenter(boolean)](#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_setRotateCenter-boolean-) to rotate about its center.

**Parameters:**
- `draw2D`: the overlay to nest
- `x`: the x position
- `y`: the y position
- `width`: the width supplier
- `height`: the height supplier
- `zIndex`: the ordering value on the parent overlay
- `scale`: the scale to apply
- `rotation`: the rotation in degrees

## Fields

### draw2D {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_draw2D}

```js
draw2D: Draw2D
```

The overlay rendered by this element.

### height {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_height}

```js
height: IntSupplier
```

Supplies the element's height; its default and replacement behavior matches [width](#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_width).

### parent {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_parent}

```js
parent: IDraw2D<?>
```

The parent overlay used for parent-size queries, or `null` to use the
 window's GUI-scaled dimensions. Builders set this when creating the element.

### rotateCenter {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_rotateCenter}

```js
rotateCenter: boolean
```

Whether rotation is about the element's center rather than its positioned corner.  
 Direct construction defaults to `false`; builders default to `true`.

### rotation {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_rotation}

```js
rotation: float
```

The rotation in degrees. Constructors and [setRotation(double)](#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_setRotation-double-) normalize angles to
 `[-180, 180)`. Assigning directly to this field bypasses normalization.

### scale {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_scale}

```js
scale: float
```

The scale applied to the element and nested content. Builders default it to `1`.

### width {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_width}

```js
width: IntSupplier
```

Supplies the element's width. The builder's default supplier follows its parent;  
 [setWidth(int)](#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_setWidth-int-) replaces the supplier with a fixed value.

### x {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_x}

```js
x: int
```

The element's x position; scaling is applied after translation.

### y {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_y}

```js
y: int
```

The element's y position; scaling is applied after translation.

### zIndex {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_zIndex}

```js
zIndex: int
```

This element's ordering value on its overlay; lower values are drawn first.

## Methods

### getDraw2D {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_getDraw2D-}

```js
getDraw2D(): Draw2D
```

Returns the overlay nested by this element.

**Returns:** the nested overlay

**Since:** 1.8.4

### getHeight {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_getHeight-}

```js
getHeight(): int
```

Returns the current height from this element's height supplier.

**Returns:** the height of this draw2D.

**Since:** 1.8.4

### getParentHeight {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_getParentHeight-}

```js
getParentHeight(): int
```

Returns the parent overlay's height, or the window's GUI-scaled height when no
 parent is set.

**Returns:** the height of the parent

### getParentWidth {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_getParentWidth-}

```js
getParentWidth(): int
```

Returns the parent overlay's width, or the window's GUI-scaled width when no parent
 is set.

**Returns:** the width of the parent

### getRotation {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_getRotation-}

```js
getRotation(): float
```

Returns the rotation in degrees. Constructors and setters normalize the value;  
 direct writes to the public field do not.

**Returns:** the rotation of this draw2D.

**Since:** 1.8.4

### getScale {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_getScale-}

```js
getScale(): float
```

Returns the scale used to calculate the element's scaled dimensions.

**Returns:** the scale of this draw2D.

**Since:** 1.8.4

### getScaledHeight {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_getScaledHeight-}

```js
getScaledHeight(): int
```

Returns the element height multiplied by its scale and cast to an integer
 (truncated toward zero).

**Returns:** the scaled height of this element

### getScaledLeft {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_getScaledLeft-}

```js
getScaledLeft(): int
```

Returns this element's x position; scaling does not change the left edge.

**Returns:** the position of the scaled element's left side

### getScaledTop {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_getScaledTop-}

```js
getScaledTop(): int
```

Returns this element's y position; scaling does not change the top edge.

**Returns:** the position of the scaled element's top side

### getScaledWidth {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_getScaledWidth-}

```js
getScaledWidth(): int
```

Returns the element width multiplied by its scale and cast to an integer (truncated
 toward zero). Alignment calculations use this scaled width.

**Returns:** the scaled width of this element

### getWidth {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_getWidth-}

```js
getWidth(): int
```

Returns the current width from its supplier, before scaling. A supplier tied to
 another overlay reflects that overlay's current width.

**Returns:** the current width

**Since:** 1.8.4

### getX {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_getX-}

```js
getX(): int
```

Returns the element's x position, which scaling does not change.

**Returns:** the x position

**Since:** 1.8.4

### getY {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_getY-}

```js
getY(): int
```

Returns the element's y position, which scaling does not change.

**Returns:** the y position

**Since:** 1.8.4

### getZIndex {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_getZIndex-}

```js
getZIndex(): int
```

Returns this element's ordering value on its overlay. Lower values draw first;  
 newly constructed elements default to zero.

**Returns:** the z-index of this element

### isRotatingCenter {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_isRotatingCenter-}

```js
isRotatingCenter(): boolean
```

Returns whether rotation is about the element's center. Builders enable this
 by default; directly constructed elements do not.

**Returns:** `true` if this draw2D should be rotated around its center, `false`
 otherwise.

**Since:** 1.8.4

### moveTo {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_moveTo-int-int-}

```js
moveTo(int x, int y): Draw2DElement
```

Sets this element's position without changing its size.

**Parameters:**
- `x`: the new x position
- `y`: the new y position

**Returns:** self for chaining.

### render {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_render-GuiGraphics-int-int-float-}

```js
render(GuiGraphics drawContext, int mouseX, int mouseY, float delta): void
```

Renders the nested overlay under this element's position, scale, and rotation
 transform. Rotation is about the element's center when `rotateCenter` is
 enabled, and otherwise about its positioned corner. Mouse coordinates and frame
 delta are unused.

**Parameters:**
- `drawContext`: the graphics context to draw into
- `mouseX`: the mouse x, not used by this element
- `mouseY`: the mouse y, not used by this element
- `delta`: the frame delta, not used by this element

### setHeight {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_setHeight-int-}

```js
setHeight(int height): Draw2DElement
```

Sets a fixed height, replacing any supplier that tracks another overlay.  
 Zero is allowed; negative values throw [IllegalArgumentException](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/IllegalArgumentException.html).

**Parameters:**
- `height`: the height

**Returns:** self for chaining.

**Since:** 1.8.4

### setParent {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_setParent-IDraw2D-}

```js
setParent(IDraw2D<?> parent): Draw2DElement
```

Sets the overlay used as this element's parent for parent-size queries. Builders
 set it when constructing the element; passing `null` makes those queries
 use the window's GUI-scaled dimensions.

**Parameters:**
- `parent`: the overlay this element is on, or `null` for the window

**Returns:** self for chaining.

### setPos {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_setPos-int-int-}

```js
setPos(int x, int y): Draw2DElement
```

Sets the element's position without changing its dimensions.

**Parameters:**
- `x`: the x position
- `y`: the y position

**Returns:** self for chaining.

**Since:** 1.8.4

### setRotateCenter {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_setRotateCenter-boolean-}

```js
setRotateCenter(boolean rotateCenter): Draw2DElement
```

Sets whether rotation is about the element's center rather than its positioned
 corner. Builders enable this by default; directly constructed elements do not.

**Parameters:**
- `rotateCenter`: whether this draw2D should be rotated around its center

**Returns:** self for chaining.

**Since:** 1.8.4

### setRotation {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_setRotation-double-}

```js
setRotation(double rotation): Draw2DElement
```

Sets the rotation in degrees; the value is narrowed to `float` and
 normalized to `[-180, 180)`.

**Parameters:**
- `rotation`: the rotation

**Returns:** self for chaining.

**Since:** 1.8.4

### setScale {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_setScale-double-}

```js
setScale(double scale): Draw2DElement
```

Sets the scale applied to this element and its nested overlay. The value is
 narrowed to `float`; zero and negative values throw
 [IllegalArgumentException](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/IllegalArgumentException.html).

**Parameters:**
- `scale`: the scale

**Returns:** self for chaining.

**Since:** 1.8.4

### setSize {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_setSize-int-int-}

```js
setSize(int width, int height): Draw2DElement
```

Sets fixed width and height. Zero is allowed; negative dimensions throw
 [IllegalArgumentException](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/IllegalArgumentException.html). Width is set before height, so a negative
 height leaves the width changed.

**Parameters:**
- `width`: the width
- `height`: the height

**Returns:** self for chaining.

**Since:** 1.8.4

### setWidth {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_setWidth-int-}

```js
setWidth(int width): Draw2DElement
```

Sets a fixed width, replacing any supplier that tracks another overlay. Zero is
 allowed; negative values throw [IllegalArgumentException](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/IllegalArgumentException.html).

**Parameters:**
- `width`: the width

**Returns:** self for chaining.

**Since:** 1.8.4

### setX {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_setX-int-}

```js
setX(int x): Draw2DElement
```

Sets the x position without changing the y position or dimensions.

**Parameters:**
- `x`: the x position

**Returns:** self for chaining.

**Since:** 1.8.4

### setY {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_setY-int-}

```js
setY(int y): Draw2DElement
```

Sets the y position without changing the x position or dimensions.

**Parameters:**
- `y`: the y position

**Returns:** self for chaining.

**Since:** 1.8.4

### setZIndex {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Draw2DElement_setZIndex-int-}

```js
setZIndex(int zIndex): Draw2DElement
```

Sets this element's ordering value relative to other elements on its overlay;  
 lower values are drawn first. A nested overlay is ordered as a single element.

**Parameters:**
- `zIndex`: the z-index of this draw2D

**Returns:** self for chaining.

**Since:** 1.8.4
