H3lp Yours3lfDocs
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 ui = require 'openmw.ui'
local column = require 'scripts.s3.components.column'
local toggle = require 'scripts.s3.components.toggle'
local text = require 'scripts.s3.components.text'

local enabled = true
local status = text {
  text = 'Enabled',
}
local element

element = ui.create {
  type = ui.TYPE.Container,
  layer = 'Windows',
  content = ui.content {
    column {
      children = {
        toggle {
          label = 'Sound',
          value = enabled,
          onChange = function(value)
            enabled = value
            status.props.text = value and 'Enabled' or 'Disabled'
            element:update()
          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