Allow menus to start at a pre-selected position and use it on text speed selection

This commit is contained in:
Tissevert 2018-12-01 17:17:18 +01:00
parent 2ff44fcebe
commit 6cf9614518
2 changed files with 23 additions and 9 deletions

View File

@ -76,15 +76,16 @@ function Screen(dom) {
getTextZone().classList[yes ? 'add' : 'remove']('read');
}
function menu(name, entries) {
function menu(config) {
var domEntries = [];
for(var i = 0; i < entries.length; i++) {
var selected = config.selected || 0;
for(var i = 0; i < config.entries.length; i++) {
domEntries.push(dom.make('li', {
class: i == 0 ? 'selected' : [],
textContent: entries[i].label
class: i == selected ? 'selected' : [],
textContent: config.entries[i].label
}, []));
}
var ul = dom.make('ul', {class: ['menu', 'framed'], id: name}, domEntries);
var ul = dom.make('ul', {class: ['menu', 'framed'], id: config.name + 'Menu'}, domEntries);
root.appendChild(ul);
menus.push(ul);
return ul;

View File

@ -68,8 +68,8 @@ function UI(async, buttons, dom, screen, session) {
}
function menu(config) {
var cursor = 0;
var m = screen.menu(config.name + 'Menu', config.entries);
var cursor = config.selected || 0;
var m = screen.menu(config);
var sync = function() { screen.select(cursor); };
var mapping = {
Up: function() {
@ -100,7 +100,8 @@ function UI(async, buttons, dom, screen, session) {
var menuConfig = {
cancel: config.cancel,
entries: [],
name: config.name
name: config.name,
selected: config.selected
};
var apply = function(f, val) { return function() { return f(val); }; };
return function(f) {
@ -241,7 +242,19 @@ function UI(async, buttons, dom, screen, session) {
}
function setTextSpeed(choices) {
ask(choices)(function(value) {
var currentTextSpeed = session.getOptions().textSpeed;
var config = {
entries: [],
cancel: choices.cancel,
name: choices.name
};
for(var i = 0; i < choices.entries.length; i++) {
config.entries[i] = choices.entries[i];
if(choices.entries[i].value == currentTextSpeed) {
config.selected = i;
}
}
ask(config)(function(value) {
session.setOptions({textSpeed: value});
textDelay = textSpeeds[value];
});