add string menu functions
code to handle menu string options from Anton clock settings.jsmaster
parent
c950e931a9
commit
689398c846
|
|
@ -11,25 +11,37 @@
|
|||
require('Storage').writeJSON(FILE, settings);
|
||||
}
|
||||
|
||||
// Helper method which uses int-based menu item for set of string values
|
||||
function stringItems(startvalue, writer, values) {
|
||||
return {
|
||||
value: (startvalue === undefined ? 0 : values.indexOf(startvalue)),
|
||||
format: v => values[v],
|
||||
min: 0,
|
||||
max: values.length - 1,
|
||||
wrap: true,
|
||||
step: 1,
|
||||
onchange: v => {
|
||||
writer(values[v]);
|
||||
writeSettings();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Helper method which breaks string set settings down to local settings object
|
||||
function stringInSettings(name, values) {
|
||||
return stringItems(settings[name], v => settings[name] = v, values);
|
||||
}
|
||||
|
||||
// Show the menu
|
||||
E.showMenu({
|
||||
"" : { "title" : "Seaside Watch" },
|
||||
"< Back" : () => back(),
|
||||
'Tide type': {
|
||||
value: "high"|settings.nextTideType, // !! converts undefined to false
|
||||
format: v => v?"high":"low ",
|
||||
onchange: v => {
|
||||
settings.nextTideType = v;
|
||||
print(v);
|
||||
writeSettings();
|
||||
}
|
||||
},
|
||||
"Tide type": stringInSettings("nextTideType", ["high", "low "]),
|
||||
'Hour': {
|
||||
value: 0|settings.nextTideHour, // 0| converts undefined to 0
|
||||
min: 0, max: 23,
|
||||
onchange: v => {
|
||||
settings.nextTideHour = v;
|
||||
print(v);
|
||||
writeSettings();
|
||||
}
|
||||
},
|
||||
|
|
@ -38,7 +50,6 @@
|
|||
min: 0, max: 59,
|
||||
onchange: v => {
|
||||
settings.nextTideMin = v;
|
||||
print(v);
|
||||
writeSettings();
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue