form.addSourceField¶
since 1.1.0
Add a source field to the current form.
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¶
local function configure(widget)
local line = form.addLine("Source")
form.addSourceField(line, nil,
function() return widget.source end,
function(value) widget.source = value end)
end
local function write(widget) storage.write("source", widget.source) end
local function read(widget) widget.source = storage.read("source") end
From the official Ethos documentation
form.addSourceField(line, nil, function() return source end, function(newValue) source = newValue end)
Used in¶
- Background alert task
- Battery gauge widget
- Lua source
- Telemetry value widget
- lazy-loading
- tool-form
- widget-form
- widget-gauge
- widget-jet
Real-world usage¶
Called 6 times across 1 open-source Ethos Lua project. A few short excerpts:
panel = form.addExpansionPanel("EGT configure")
local egtMaxEdit
line = panel:addLine("EGT source")
form.addSourceField(line, nil, function() return widget.egtSource end, function(newValue)
widget.egtSource = newValue
if egtMaxEdit ~= nil then
egtMaxEdit:suffix(widget.egtSource ~= nil and widget.egtSource:stringUnit() or "")
end
end)