Skip to content

form.addSwitchField

since 1.1.0

Add a switch field to the current form.

form.addSwitchField(line, rect, getValue, setValue)

Parameters

Name Type Required Description
line FormLine yes the line where the field should be added
rect Rect yes the coordinates
getValue function yes the function which will return the current value
setValue function yes the function which will be called on value change

Returns

The new field

Examples

From the official Ethos documentation
form.addSwitchField(line, nil, function() return switch end, function(newValue) switch = newValue end)

Used in

Real-world usage

Called 11 times across 4 open-source Ethos Lua projects. A few short excerpts:
line = form.addLine("Reset Switch")
form.addSwitchField(line, form.getFieldSlots(line)[0],
    function() return widget.rstSwitch end,
    function(v) widget.rstSwitch = v end)

src/bmfa-caller/widget_impl.lua:147

local armLine = addLine(triggersPanel, "@i18n(app.modules.model.model_armswitch)@")
form.addSwitchField(armLine, nil, function()
    return decodeSwitchSpec(widget.armswitch)
end, function(newValue)
    widget.armswitch = encodeSwitchSource(newValue)
end)

src/dashx/widgets/dashboard/configure.lua:315

line = form.addLine("@i18n(app.modules.settings.activelook_hide_display)@")
form.addSwitchField(line, nil,
  function() return switchFromConfig(settings.activelook.display_switch) end,
  function(source)
    settings.activelook.display_switch = switchToConfig(source)
    updateSaveEnabled()
  end)

src/rfsuite/app/pages/settings_activelook_settings.lua:36