# BaseScreen

`com.jsmacrosce.wagyourgui.BaseScreen`

Base class for screens that host nested overlays and retain a navigation parent.  
 Subclasses provide GUI initialization and rendering behavior. The client stores the
 most recently initialized instance in `prevScreen`; that need not be the
 currently displayed screen.  
 ```js
const Client = Java.type('com.jsmacrosce.jsmacros.client.JsMacrosClient');  
const screen = Client.prevScreen;  
if (screen !== null) {
  screen.reload();  
}
 ```

## Methods

### addRenderableWidget {#com.jsmacrosce.wagyourgui.BaseScreen_addRenderableWidget-T-}

```js
addRenderableWidget(T extends GuiEventListener & Renderable & NarratableEntry renderableWidget): T extends GuiEventListener & Renderable & NarratableEntry
```

Registers a widget for input, rendering, and narration, returning the same widget.  
 This adds to the native rendering, input and narration lists without duplicate filtering or overlay-local tracking.

**Parameters:**
- `renderableWidget`: non-null widget to register

**Type Parameters:**
- `T`: widget type supporting input, rendering, and narration

**Returns:** the supplied widget reference

### closeOverlay {#com.jsmacrosce.wagyourgui.BaseScreen_closeOverlay-OverlayContainer-}

```js
closeOverlay(OverlayContainer overlay): void
```

Removes the supplied overlay's tracked widgets from this screen, restores its saved widget states, and calls its close hook.  
 The supplied overlay need not be this screen's current overlay; only a matching current reference is cleared, after the hook returns.  
 A hook failure leaves that reference uncleared. The supplied tracking list, saved-state map and child overlay are not cleared or recursively closed.

**Parameters:**
- `overlay`: overlay to clean up and notify, or `null` for a no-op

### getChildOverlay {#com.jsmacrosce.wagyourgui.BaseScreen_getChildOverlay-}

```js
getChildOverlay(): OverlayContainer
```

Returns the deepest open overlay, or `null` when none is open.

**Returns:** deepest open overlay, or `null`

### getFirstOverlayParent {#com.jsmacrosce.wagyourgui.BaseScreen_getFirstOverlayParent-}

```js
getFirstOverlayParent(): IOverlayParent
```

Returns this screen as the first overlay host.

**Returns:** this screen as overlay host

### keyPressed {#com.jsmacrosce.wagyourgui.BaseScreen_keyPressed-int-int-int-}

```js
keyPressed(int keyCode, int scanCode, int modifiers): boolean
```

On Escape with a direct overlay, requests closing its deepest overlay and returns true if closing returns normally.  
 Other paths delegate to the native screen handler; this method does not forward ordinary keys directly to the overlay's key hook.

**Parameters:**
- `keyCode`: GLFW key code
- `scanCode`: platform-specific scan code forwarded to the screen handler
- `modifiers`: modifier flags forwarded to the screen handler

**Returns:** true for the intercepted Escape path, otherwise the native screen handler's result

### mouseClicked {#com.jsmacrosce.wagyourgui.BaseScreen_mouseClicked-double-double-int-}

```js
mouseClicked(double mouseX, double mouseY, int button): boolean
```

Calls the direct overlay's click hook, if present, before delegating to the native screen handler.  
 Overlay presence does not itself consume the click; if the overlay hook throws, native delegation is not reached.

**Parameters:**
- `mouseX`: mouse X coordinate in GUI space
- `mouseY`: mouse Y coordinate in GUI space
- `button`: clicked mouse button code

**Returns:** the native screen handler's result, not the overlay hook's handling state

### mouseScrolled {#com.jsmacrosce.wagyourgui.BaseScreen_mouseScrolled-double-double-double-double-}

```js
mouseScrolled(double mouseX, double mouseY, double horiz, double vert): boolean
```

If the direct overlay has a scrollbar, forwards vertical scrolling to it as a drag, then delegates the original scroll event to the native screen handler.  
 The drag uses zero horizontal delta and -2 times the vertical scroll amount, without a local activation or visibility check. Its result is ignored; a failure prevents native delegation.

**Parameters:**
- `mouseX`: mouse X coordinate in GUI space
- `mouseY`: mouse Y coordinate in GUI space
- `horiz`: horizontal scroll amount, forwarded unchanged to the native handler
- `vert`: vertical scroll amount, multiplied by -2 for the scrollbar drag

**Returns:** the native screen handler's result, not whether the scrollbar moved

### onClose {#com.jsmacrosce.wagyourgui.BaseScreen_onClose-}

```js
onClose(): void
```

With no loaded level, calls the overridable openParent; with a level, explicitly clears focus and asks the client to clear the current screen.  
 Expects the Minecraft client to be assigned. Does not call updateSettings or explicitly close overlays or clear their saved state.

### openOverlay {#com.jsmacrosce.wagyourgui.BaseScreen_openOverlay-OverlayContainer-}

```js
openOverlay(OverlayContainer overlay): void
```

Opens an overlay at the deepest open level, saving and deactivating existing host-level AbstractWidget entries by default.

**Parameters:**
- `overlay`: non-null overlay to open

### openOverlay {#com.jsmacrosce.wagyourgui.BaseScreen_openOverlay-OverlayContainer-boolean-}

```js
openOverlay(OverlayContainer overlay, boolean disableButtons): void
```

Opens an overlay at the deepest level; at this level, optionally saves and deactivates existing widgets.  
 Only existing AbstractWidget entries are deactivated; false leaves their active states unchanged. The overlay is assigned before its
 initialization, so an initialization failure leaves the assignment and any deactivation in place.  
 Saved-state entries are merged rather than cleared, and the overlay is not automatically reparented.

**Parameters:**
- `overlay`: non-null overlay to open
- `disableButtons`: whether to save and deactivate existing host-level widgets

### openParent {#com.jsmacrosce.wagyourgui.BaseScreen_openParent-}

```js
openParent(): void
```

Asks the client to open the stored parent screen, or clear the current screen when the parent is null.  
 Expects the Minecraft client to be assigned. Does not call updateSettings, clear the stored parent, or explicitly close overlays.

### reload {#com.jsmacrosce.wagyourgui.BaseScreen_reload-}

```js
reload(): void
```

Invokes this screen's overridable initialization without opening it; the base implementation expects the Minecraft client to be assigned.  
 The base initialization clears registered widgets and discards the current overlay
 without its normal close callback or saved active-state restoration, then records this instance as `prevScreen`.

### removed {#com.jsmacrosce.wagyourgui.BaseScreen_removed-}

```js
removed(): void
```

Base implementation performs only an assertion that the client is available.

### removeWidget {#com.jsmacrosce.wagyourgui.BaseScreen_removeWidget-GuiEventListener-}

```js
removeWidget(GuiEventListener btn): void
```

Removes a listener from this screen's native widget registrations.  
 Removes one matching entry from each applicable rendering, narration and input list, not from an overlay's local tracking list.  
 On Minecraft 1.21.10 and later, native removal clears focus when this is the focused listener; 1.21.5 and 1.21.8 do not.

**Parameters:**
- `btn`: listener to remove

### render {#com.jsmacrosce.wagyourgui.BaseScreen_render-GuiGraphics-int-int-float-}

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

Renders the direct overlay when present without calling the superclass to render this screen's own widgets.  
 Minecraft 1.21.5 first renders the screen background, even without an overlay; later targets using this hook do not automatically render that background. Subclasses handle their own widgets.

**Parameters:**
- `drawContext`: non-null native graphics context
- `mouseX`: mouse X coordinate in GUI space
- `mouseY`: mouse Y coordinate in GUI space
- `delta`: frame value forwarded to the overlay

### setFocused {#com.jsmacrosce.wagyourgui.BaseScreen_setFocused-GuiEventListener-}

```js
setFocused(GuiEventListener focused): void
```

Sets the current focused listener, unfocusing the old listener and focusing a non-null replacement even if it is not registered as a child.  
 A null replacement clears focus; this does not register a widget or check its visibility or activation.

**Parameters:**
- `focused`: listener to focus, or null to clear focus

### setParent {#com.jsmacrosce.wagyourgui.BaseScreen_setParent-Screen-}

```js
setParent(Screen parent): void
```

Sets the screen used as this screen's navigation parent; this does not open or display it.

**Parameters:**
- `parent`: parent screen, or `null` when there is no parent

### shouldCloseOnEsc {#com.jsmacrosce.wagyourgui.BaseScreen_shouldCloseOnEsc-}

```js
shouldCloseOnEsc(): boolean
```

Reports whether the native Escape-close path is allowed; this query does not close anything.

**Returns:** true when no direct overlay is set, false otherwise

### trimmed {#com.jsmacrosce.wagyourgui.BaseScreen_trimmed-Font-FormattedText-int-}

```js
static trimmed(Font textRenderer, FormattedText str, int width): FormattedCharSequence
```

Trims formatted text to a font-measured prefix and applies the current language's visual ordering.

**Parameters:**
- `textRenderer`: non-null font used to measure the trimmed prefix
- `str`: non-null formatted text in logical order
- `width`: requested maximum measured width

**Returns:** language-ordered sequence for the trimmed prefix

### updateSettings {#com.jsmacrosce.wagyourgui.BaseScreen_updateSettings-}

```js
updateSettings(): void
```

No-op extension hook for subclass settings updates or persistence.  
 BaseScreen does not automatically invoke it from closing, parent navigation, reinitialization or removal.
