# AbstractWidgetBuilder

`com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder`

**Since:** 1.8.4

Base builder for screen widgets, storing their position, size, label, state flags,  
alpha, and z-index until [build()](#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_build-) creates and adds a widget to its screen.  
Builders are obtained from their screen and setters return the builder for chaining.  
Opening a screen clears elements added before its init callback, so build widgets
inside the callback passed to `IScreen.setOnInit`.  
Defaults are position and width zero, height 20, empty label, active and visible,  
alpha 1.0, and z-index zero. Subclasses may constrain properties; for example,  
button builders fix height at 20 and text-field builders use the screen font.  

```js
const screen = Hud.createScreen("a screen", true);  
screen.setOnInit(JavaWrapper.methodToJava(function (self) {
  // the shared half on its own: a label, a box and the flags
  self.buttonBuilder()
     .pos(10, 20)
     .size(100, 20)
     .message("a button")
     .visible(true)
     .active(true)
     .alpha(0.8)
     .zIndex(5)
     .build();  
}));  
Hud.openScreen(screen);  
```

## Type Parameters

- `B`: the builder class itself, so a chain keeps its own type
- `T`: the kind of game widget this builder makes
- `U`: the kind of widget helper this builder hands back

## Methods

### active {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_active-boolean-}

```js
active(boolean active): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>
```

Sets whether the built widget is active. Inactive widgets cannot be interacted
with; this flag does not determine whether an active widget's action does anything.

**Parameters:**
- `active`: whether the widget should be active or not

**Returns:** self for chaining.

**Since:** 1.8.4

### alpha {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_alpha-double-}

```js
alpha(double alpha): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>
```

Sets the widget's alpha, clamped to the range `0.0` (transparent) through
`1.0` (opaque).

**Parameters:**
- `alpha`: the alpha value of the widget

**Returns:** self for chaining.

**Since:** 1.8.4

### build {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_build-}

```js
build(): U extends ClickableWidgetHelper<U, T extends AbstractWidget>
```

Creates the widget with the builder's properties, applies its alpha, active and
visible flags, and adds it to the screen associated with this builder. Each call
creates and adds a new widget.

**Returns:** the build widget for the set properties.

**Since:** 1.8.4

### getAlpha {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_getAlpha-}

```js
getAlpha(): float
```

Returns the alpha applied to the widget when built, from `0.0` (transparent)
to `1.0` (opaque); the default is `1.0`.

**Returns:** the alpha value of the widget.

**Since:** 1.8.4

### getHeight {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_getHeight-}

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

Returns the height configured on this builder, initially 20.

**Returns:** the height of the widget.

**Since:** 1.8.4

### getMessage {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_getMessage-}

```js
getMessage(): TextHelper
```

Returns the configured label as a text helper. It is empty until a label is set.

**Returns:** the message of the widget or an empty text if none is set.

**Since:** 1.8.4

### getParentHeight {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_getParentHeight-}

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

Returns the height reported by the screen associated with this builder, used as
the parent extent for alignment.

**Returns:** the height of the parent element

**Since:** 1.8.4

### getParentWidth {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_getParentWidth-}

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

Returns the width reported by the screen associated with this builder, used as
the parent extent for alignment.

**Returns:** the width of the parent element

**Since:** 1.8.4

### getScaledHeight {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_getScaledHeight-}

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

Returns the builder's configured height, used for alignment even before the widget
is built.

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

**Since:** 1.8.4

### getScaledLeft {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_getScaledLeft-}

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

Returns the builder's current x coordinate for alignment.

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

**Since:** 1.8.4

### getScaledTop {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_getScaledTop-}

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

Returns the builder's current y coordinate for alignment.

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

**Since:** 1.8.4

### getScaledWidth {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_getScaledWidth-}

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

Returns the builder's configured width, used for alignment even before the widget
is built.

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

**Since:** 1.8.4

### getWidth {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_getWidth-}

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

Returns the width configured on this builder; it is not read from a built widget.

**Returns:** the width of the widget.

**Since:** 1.8.4

### getX {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_getX-}

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

Returns the builder's configured x coordinate, initially zero.

**Returns:** the x position of the widget.

**Since:** 1.8.4

### getY {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_getY-}

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

Returns the builder's configured y coordinate, initially zero.

**Returns:** the y position of the widget.

**Since:** 1.8.4

### getZIndex {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_getZIndex-}

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

Returns this builder's z-index, initially zero.

**Returns:** the z-index of the widget.

**Since:** 1.8.4

### height {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_height-int-}

```js
height(int height): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>
```

Sets the configured height; subclasses with fixed heights may override this setter.

**Parameters:**
- `height`: the height of the widget

**Returns:** self for chaining.

**Since:** 1.8.4

### isActive {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_isActive-}

```js
isActive(): boolean
```

Returns whether this builder's widget is active; the default is `true`.

**Returns:** `true` if the widget is active, `false` otherwise.

**Since:** 1.8.4

### isVisible {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_isVisible-}

```js
isVisible(): boolean
```

Returns whether the builder is set to create a visible widget; the default is
`true`. The built widget has no corresponding visibility reader.

**Returns:** `true` if the widget is visible, `false` otherwise.

**Since:** 1.8.4

### message {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_message-String-}

```js
message(String message): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>
```

Sets the label from a literal string. Passing `null` leaves the label unchanged.

**Parameters:**
- `message`: the message of the widget

**Returns:** self for chaining.

**Since:** 1.8.4

### message {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_message-TextHelper-}

```js
message(TextHelper message): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>
```

Sets the label from a text helper, preserving its component styling. Passing
`null` leaves the label unchanged.

**Parameters:**
- `message`: the message of the widget

**Returns:** self for chaining.

**Since:** 1.8.4

### moveTo {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_moveTo-int-int-}

```js
moveTo(int x, int y): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>
```

Sets the builder's position, equivalent to [pos(int, int)](#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_pos-int-int-). Alignment
methods use this operation; it does not resize the eventual widget.

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

**Returns:** self for chaining.

**Since:** 1.8.4

### pos {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_pos-int-int-}

```js
pos(int x, int y): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>
```

Sets both configured coordinates.

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

**Returns:** self for chaining.

**Since:** 1.8.4

### size {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_size-int-int-}

```js
size(int width, int height): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>
```

Sets both configured dimensions. Subclasses may override this to constrain a dimension.

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

**Returns:** self for chaining.

**Since:** 1.8.4

### visible {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_visible-boolean-}

```js
visible(boolean visible): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>
```

Sets whether the created widget is visible; unlike `active`, this controls
drawing. The value is applied during [build()](#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_build-) and has no built-widget setter.

**Parameters:**
- `visible`: whether the widget should be visible or not

**Returns:** self for chaining.

**Since:** 1.8.4

### width {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_width-int-}

```js
width(int width): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>
```

Sets the configured width. Subclasses may constrain other dimensions independently.

**Parameters:**
- `width`: the width of the widget

**Returns:** self for chaining.

**Since:** 1.8.4

### x {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_x-int-}

```js
x(int x): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>
```

Sets the widget's configured x coordinate; this builder does not constrain it to the screen.

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

**Returns:** self for chaining.

**Since:** 1.8.4

### y {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_y-int-}

```js
y(int y): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>
```

Sets the builder's y coordinate; this builder does not constrain it to the screen.

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

**Returns:** self for chaining.

**Since:** 1.8.4

### zIndex {#com.jsmacrosce.jsmacros.client.api.helper.screen.AbstractWidgetBuilder_zIndex-int-}

```js
zIndex(int zIndex): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>
```

Sets the z-index used when creating the widget.

**Parameters:**
- `zIndex`: the z-index of the widget

**Returns:** self for chaining.

**Since:** 1.8.4
