# EventChooser

`com.jsmacrosce.jsmacros.client.gui.overlays.EventChooser`

Displays registered event names in a five-column overlay and lets the caller confirm a selection.  
 Closing or cancelling does not invoke the callback. In this factory the caller supplies an
 `IOverlayParent`, native `Font`, non-null initial event name and JavaScript callback:  
 ```js
function showEventChooser(parent, font, selected, onSelected) {
  const EventChooser = Java.type('com.jsmacrosce.jsmacros.client.gui.overlays.EventChooser');  
  const chooser = new EventChooser(10, 10, 300, 180, font, selected, parent, JavaWrapper.methodToJava(onSelected));  
  parent.openOverlay(chooser);  
  return chooser;  
}
 ```

 The callback runs on confirmation only when both a selection and callback are non-null. An arbitrary non-null
 selection can be confirmed, whether or not it is in the registered event list. Confirmation closes the
 overlay only after the callback returns normally; a missing callback leaves the Select button without this action.

## Nested types

- [EventObj](EventChooser.EventObj.md)

## Constructors

### new EventChooser {#com.jsmacrosce.jsmacros.client.gui.overlays.EventChooser_constructor-int-int-int-int-Font-String-IOverlayParent-Consumer-}

```js
new EventChooser(int x, int y, int width, int height, Font textRenderer, String selected, IOverlayParent parent, Consumer<String> setEvent)
```

Stores the overlay geometry, initial selection, parent, and optional confirmation callback; the constructor does not open the overlay or initialize its widgets.

**Parameters:**
- `x`: left edge in GUI coordinates
- `y`: top edge in GUI coordinates
- `width`: overlay width in GUI coordinates
- `height`: overlay height in GUI coordinates
- `textRenderer`: non-null font used for overlay text and buttons
- `selected`: initial event name; must be non-null if the initialized event list is nonempty, but need not name a registered event
- `parent`: non-null overlay parent
- `setEvent`: nullable callback invoked on confirmation when a selection is non-null

## Methods

### addEvent {#com.jsmacrosce.jsmacros.client.gui.overlays.EventChooser_addEvent-String-}

```js
addEvent(String eventName): void
```

Appends an event row after existing rows and updates the scrollbar range; this does not sort, deduplicate, or register the name.  
 Requires the scrollbar created by `init`. Uses an available translation for
 `"jsmacrosce.event."` plus the name lowercased with `Locale.ROOT`, otherwise the literal name.  
 Adding a row does not select or highlight it, even if its name matches the current selection.

**Parameters:**
- `eventName`: non-null event name represented by the row and selected when its button is clicked

### init {#com.jsmacrosce.jsmacros.client.gui.overlays.EventChooser_init-}

```js
init(): void
```

Initializes the overlay controls, copies and sorts the registered event names, and adds rows before applying the current selection.  
 Requires an initialized client event registry and a non-null selection when there are rows.  
 Repeated calls reset the scroll position and container button tracking but retain prior rows, so they append duplicate rows and are not a refresh operation. Previously registered parent widgets are not removed.

### onScrollbar {#com.jsmacrosce.jsmacros.client.gui.overlays.EventChooser_onScrollbar-double-}

```js
onScrollbar(double page): void
```

Applies an unclamped scrollbar offset and repositions rows; visibility uses row top edges, not full-row clipping.  
 Sets the row origin to `y + 13 - (int) (page * (height - 27))`.

**Parameters:**
- `page`: scroll offset in units of `height - 27` GUI coordinates, not a normalized percentage

### render {#com.jsmacrosce.jsmacros.client.gui.overlays.EventChooser_render-GuiGraphics-int-int-float-}

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

Submits the background, caption and separators, forwards the hook to widgets and a child overlay,  
 then submits full-label popups for tracked buttons with the stored hovering flag and truncated text.  
 Neither the inherited visibility flag nor the popup button's visibility or active flag is checked here.

**Parameters:**
- `drawContext`: context receiving the overlay and widget drawing operations
- `mouseX`: mouse x-coordinate in GUI coordinates, forwarded to widgets and used to position label popups
- `mouseY`: mouse y-coordinate in GUI coordinates, forwarded to widgets and used to position label popups
- `delta`: frame value forwarded to widgets

### selectEvent {#com.jsmacrosce.jsmacros.client.gui.overlays.EventChooser_selectEvent-String-}

```js
selectEvent(String event): void
```

Sets the selection and highlights every row whose event name exactly matches it; does not confirm or close the overlay.

**Parameters:**
- `event`: non-null event name to select; matching is case-sensitive

### updateEventPos {#com.jsmacrosce.jsmacros.client.gui.overlays.EventChooser_updateEventPos-}

```js
updateEventPos(): void
```

Repositions retained rows from the current overlay geometry and scroll offset, updating visibility from each row's top edge.  
 Rows use five columns with 12-unit row heights. Visibility checks whether each row's top is within
 the inclusive interval from `y + 13` to `y + height - 27`, not whether its full bounds fit.  
 This does not change the scroll offset or recompute the scrollbar range.
