Skip to content

SelectorWidget

The SelectorWidget is a dropdown-style selection widget that allows users to pick an option from a predefined list. It supports dynamically updating the selection list, displaying a configurable UI, and handling selection changes efficiently.


Features

  • Dropdown selection – Expands to show available choices.
  • Event handling – Fires callbacks when the selection changes.

Properties

Field Type Description
currentValue String Currently selected option.

APIs

setCandidates

Updates the list of selectable options.

selectorWidget.setCandidates(List.of("OptionA", "OptionB", "OptionC"));
selectorWidget.setCandidates(["OptionA", "OptionB", "OptionC"]);
  • Triggers a UI update to reflect the new options.

setValue

Sets the currently selected value.

selectorWidget.setValue("OptionA");
  • If the value is not found in candidates, it remains unchanged.

setMaxCount

Defines how many options should be visible before scrolling.

selectorWidget.setMaxCount(3);
  • If there are more than maxCount options, a scrollbar is added.

setFontColor

Changes the color of option text.

selectorWidget.setFontColor(0xFFFFFF); // White text

setButtonBackground

Sets the background texture for the button area.

selectorWidget.setButtonBackground(myCustomTexture);

setOnChanged

Registers a callback to handle selection changes.

selectorWidget.setOnChanged(selected -> {
    System.out.println("New selection: " + selected);
});
selectorWidget.setOnChanged(selected => {
    console.log("New selection: " + selected);
});
  • This is useful for updating UI state or triggering game logic.

setCandidatesSupplier

Automatically updates the option list from a dynamic source.

selectorWidget.setCandidatesSupplier(() -> fetchDynamicOptions());
selectorWidget.setCandidatesSupplier(() => fetchDynamicOptions());
  • The widget polls this function to refresh the list.
  • Useful when candidates change based on external conditions.

setShow

Manually toggles the dropdown visibility.

selectorWidget.setShow(true); // Opens dropdown