Skip to content
S3ctor’s S3cret St4sh
api

toggle

Build a state-labelled yes/no button.

Builds an H3UI button whose label reflects a boolean value. value defaults to false; labels default to On and Off.

Example

local enabled = true
local status = ui.text {
  text = 'Enabled',
}

ui.column {
  children = {
    ui.toggle {
      label = 'Sound',
      value = enabled,
      onChange = function(value)
        enabled = value
        status.props.text = value and 'Enabled' or 'Disabled'
      end,
    },
    status,
  },
}

Parameters

FieldTypeDescription
valueboolean?Initial state; defaults to false.
onChangefunction?Receives the new boolean value.
labelstringBase label for the control.
onLabelstring?Label suffix for the enabled state.
offLabelstring?Label suffix for the disabled state.
labelPropstable?Properties for the generated label.
templateopenmw.ui.Template?Replaces the default H3UI button template.

Common layout fields are documented on the UI Components overview. onChange runs after the label changes.

See also

button · slider · collapsible