widget

The widget table contains functions to manipulate and get data about widgets in a scriptpane.

The widgetName passed into most of these functions can contain period separators for getting children.

Example:

widget.getPosition("itemScrollArea.itemList.1.name")

General callbacks

These callbacks are available for all widgets.


void widget.playSound(String audio, [int loops = 0], [float volume = 1.0f])

Plays a sound.


Vec2I widget.getPosition(String widgetName)

Returns the position of a widget.


void widget.setPosition(String widgetName, Vec2I position)

Sets the position of a widget.


Vec2I widget.getSize(String widgetName)

Returns the size of a widget.


void widget.setSize(String widgetName, Vec2I size)

Sets the size of a widget.


void widget.setVisible(String widgetName, bool visible)

Sets the visibility of a widget.


void widget.focus(String widgetName)

Sets focus on the specified widget.


void widget.blur(String widgetName)

Unsets focus on the specified focused widget.


Json widget.getData(String widgetName)

Returns the arbitrary data value set for the widget.


void widget.setData(String widgetName, Json data)

Sets arbitrary data for the widget.

String widget.getChildAt(Vec2I screenPosition)

Returns the full name for any widget at screenPosition.


bool widget.setData(String widgetName, Vec2I screenPosition)

Returns whether the widget contains the specified screenPosition.


Widget specific callbacks

These callbacks only work for some widget types.


String widget.getText(String widgetName)

Returns the text set in a TextBoxWidget.


void widget.setText(String widgetName, String text)

Sets the text of: LabelWidget, ButtonWidget, TextBoxWidget


void widget.setFontColor(String widgetName, Color color)

Sets the font color of: LabelWidget, ButtonWidget, TextBoxWidget


void widget.setImage(String widgetName, String imagePath)

Sets the image of an ImageWidget.


void widget.setImageScale(String widgetName, float imageScale)

Sets the scale of an ImageWidget.


void widget.setImageRotation(String widgetName, float imageRotation)

Sets the rotation of an ImageWidget.


void widget.setButtonEnabled(String widgetName, bool enabled)

Sets whether the ButtonWidget should be enabled.


void widget.setButtonImage(String widgetName, String baseImage)

Sets the baseImage of a ButtonWidget.


void widget.setButtonImages(String widgetName, Json imageSet)

Sets the full image set of a ButtonWidget.

{
  base = "image.png",
  hover = "image.png",
  pressed = "image.png",
  disabled = "image.png",
}

void widget.setButtonCheckedImages(String widgetName, Json imageSet)

Similar to widget.setButtonImages, but sets the images used for the checked state of a checkable ButtonWidget.


void widget.setButtonOverlayImage(String widgetName, String overlayImage)

Sets the overlay image of a ButtonWidget.


bool widget.getChecked(String widgetName)

Returns whether the ButtonWidget is checked.


void widget.setChecked(String widgetName, bool checked)

Sets whether a ButtonWidget is checked


int widget.getSelectedOption(String widgetName)

Returns the index of the selected option in a ButtonGroupWidget.


int widget.getSelectedData(String widgetName)

Returns the data of the selected option in a ButtonGroupWidget. Nil if no option is selected.


void widget.setSelectedOption(String widgetName, int index)

Sets the selected option index of a ButtonGroupWidget.


void widget.setOptionEnabled(String widgetName, int index, bool enabled)

Sets whether a ButtonGroupWidget option should be enabled.


void widget.setOptionVisible(String widgetName, int index, bool, visible)

Sets whether a ButtonGroupWidget option should be visible.


void widget.setProgress(String widgetName, float value)

Sets the progress of a ProgressWidget. Value should be between 0.0 and 1.0.


void widget.setSliderEnabled(String widgetName, bool enabled)

Sets whether the SliderBarWidget should be enabled.


float widget.getSliderValue(String widgetName)

Gets the current value of a SliderBarWidget.


void widget.setSliderValue(String widgetName, int newValue)

Sets the current value of a SliderBarWidget.


void widget.getSliderRange(String widgetName, int newMin, int newMax, [int newDelta])

Sets the minimum, maximum and (optionally) delta values of a SliderBarWidget.


void widget.clearListItems(String widgetName)

Clears all items in a ListWidget.


String widget.addListItem(String widgetName)

Adds a list item to a ListWidget using the configured template, and returns the name of the added list item.


void widget.removeListItem(String widgetName, size_t at)

Removes a list item from a ListWidget at a specific index.


String widget.getListSelected(String widgetName)

Returns the name of the currently selected widget in a ListWidget.


void widget.setListSelected(String widgetName, String selected)

Sets the selected widget of a ListWidget.


ItemBag widget.itemGridItems(String widgetName)

Returns the full item bag contents of an ItemGridWidget.


void widget.setItemSlotItem(Json itemDescriptor)

Sets the item in the specified item slot widget.