H3lp Yours3lfDocs
api

slider

Build a bounded pointer-controlled numeric slider.

Builds a meter-based horizontal track. Pointer presses and drags map to min..max, clamp to the range, and optionally round to step.

Example

local ui = require 'openmw.ui'
local util = require 'openmw.util'
local column = require 'scripts.s3.components.column'
local slider = require 'scripts.s3.components.slider'
local text = require 'scripts.s3.components.text'

local value = 50
local readout = text {
  text = '50%',
}
local element

element = ui.create {
  type = ui.TYPE.Container,
  layer = 'Windows',
  content = ui.content {
    column {
      children = {
        slider {
          value = value,
          min = 0,
          max = 100,
          step = 5,
          props = {
            size = util.vector2(240, 18),
          },
          onChange = function(nextValue)
            value = nextValue
            readout.props.text = tostring(nextValue) .. '%'
            element:update()
          end,
        },
        readout,
      },
    },
  },
}

Parameters

FieldTypeDescription
valuenumber?Initial value; defaults to min.
minnumber?Lower bound; defaults to 0.
maxnumber?Upper bound; defaults to 1.
stepnumber?Optional rounding increment.
trackWidthnumber?Rendered width for relative tracks.
fillPropstable?Properties for the filled portion.
emptyPropstable?Properties for the empty portion.
onChangefunction?Receives the normalized value.
templateopenmw.ui.Template?Replaces the default H3UI meter template.

Common layout fields are documented on the UI Components overview. Invalid ranges and non-positive steps raise an error during construction.

See also

meter · numberInput · selector