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

FieldTypeDescription
currentValueStringCurrently selected option.

APIs

setCandidates

Updates the list of selectable options.

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

setValue

Sets the currently selected value.

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

setMaxCount

Defines how many options should be visible before scrolling.

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

setFontColor

Changes the color of option text.

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

setButtonBackground

Sets the background texture for the button area.

java
selectorWidget.setButtonBackground(myCustomTexture);

setOnChanged

Registers a callback to handle selection changes.

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

setCandidatesSupplier

Automatically updates the option list from a dynamic source.

java
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.

java
selectorWidget.setShow(true); // Opens dropdown

Released under the MIT License.