Settings¶
Every loaded plugin's [Setting] variables, as a flat list. Index i runs from 0 to Count() - 1. A plugin
normally just reads and assigns its own setting variables; these functions are for building a settings page.
Set and Reset are for the plugin manager only. See Settings.
Count¶
uint Settings::Count()
How many settings there are across all loaded plugins.
Example
for (uint i = 0; i < Settings::Count(); i++)
Log::Info(Settings::Plugin(i) + ": " + Settings::Name(i) + " = " + Settings::Get(i));
Plugin¶
string Settings::Plugin(uint)
The id of the plugin that owns the setting.
Example
// Only this plugin's settings
if (Settings::Plugin(i) == "grind-timer")
AddSettingRow(i);
Name¶
string Settings::Name(uint)
The setting's display name (name= in its [Setting] tag, or the variable's name).
Example
label.text = Settings::Name(i);
Description¶
string Settings::Description(uint)
The setting's description (description= in its tag), or "".
Example
if (Settings::Description(i) != "")
label.text += "\n" + Settings::Description(i);
Kind¶
string Settings::Kind(uint)
The variable's type: "bool", "int", "uint", "float", "double" or "string".
Example
// An on/off button for a bool, a text box for everything else
if (Settings::Kind(i) == "bool")
window.AddButton(Settings::Get(i) == "true" ? "on" : "off");
else
window.AddTextInput(200, "type a value, Enter");
Hidden¶
bool Settings::Hidden(uint)
Whether the setting is tagged hidden. Hidden settings are saved, but a settings page doesn't show them.
Example
if (Settings::Hidden(i))
continue;
HasRange¶
bool Settings::HasRange(uint)
Whether the setting has both min and max, so it can be shown as a slider.
Example
if (Settings::HasRange(i))
window.AddSlider(360);
Min¶
double Settings::Min(uint)
The setting's min (meaningful when HasRange).
Example
// Slider position (0..1) for the current value
float fraction = float((parseFloat(Settings::Get(i)) - Settings::Min(i)) / (Settings::Max(i) - Settings::Min(i)));
Max¶
double Settings::Max(uint)
The setting's max (meaningful when HasRange).
Example
// Value for a slider position (0..1)
double value = Settings::Min(i) + slider.value * (Settings::Max(i) - Settings::Min(i));
Choices¶
array<string>@ Settings::Choices(uint)
A string setting's choices, from choices="A|B|C" in its tag (shown as a dropdown); empty for any other setting.
Set only takes one of them. Requires host 0.21.0.
Example
array<string>@ options = Settings::Choices(i);
for (uint k = 0; k < options.length(); k++)
dropdown.AddOption(options[k]);
Get¶
string Settings::Get(uint)
The setting's current value as text ("true", "56", "0.35", ...).
Example
valueText.text = Settings::Get(i);
IsDefault¶
bool Settings::IsDefault(uint)
Whether the setting is at its default value (the value the variable starts with in the script).
Example
// Only show "reset" when there's something to reset
resetButton.visible = !Settings::IsDefault(i);
Set¶
bool Settings::Set(uint, const string &in)
Sets a setting from text: the plugin manager any plugin's, a plugin its own (for a settings panel of its own).
Numbers are clamped to min/max. Returns false if the text isn't a value of the setting's type. The owner's
OnSettingsChanged() runs before its next Update.
Example
if (input.Submitted() && !Settings::Set(i, input.text))
Log::Warn("not a value for " + Settings::Name(i) + ": " + input.text);
Reset¶
void Settings::Reset(uint)
Puts a setting back to its default: the plugin manager any plugin's, a plugin its own.
Example
if (resetButton.Clicked())
Settings::Reset(i);