Allow menus to start at a pre-selected position and use it on text speed selection
This commit is contained in:
parent
2ff44fcebe
commit
6cf9614518
2 changed files with 23 additions and 9 deletions
|
@ -76,15 +76,16 @@ function Screen(dom) {
|
||||||
getTextZone().classList[yes ? 'add' : 'remove']('read');
|
getTextZone().classList[yes ? 'add' : 'remove']('read');
|
||||||
}
|
}
|
||||||
|
|
||||||
function menu(name, entries) {
|
function menu(config) {
|
||||||
var domEntries = [];
|
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', {
|
domEntries.push(dom.make('li', {
|
||||||
class: i == 0 ? 'selected' : [],
|
class: i == selected ? 'selected' : [],
|
||||||
textContent: entries[i].label
|
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);
|
root.appendChild(ul);
|
||||||
menus.push(ul);
|
menus.push(ul);
|
||||||
return ul;
|
return ul;
|
||||||
|
|
21
src/ui.js
21
src/ui.js
|
@ -68,8 +68,8 @@ function UI(async, buttons, dom, screen, session) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function menu(config) {
|
function menu(config) {
|
||||||
var cursor = 0;
|
var cursor = config.selected || 0;
|
||||||
var m = screen.menu(config.name + 'Menu', config.entries);
|
var m = screen.menu(config);
|
||||||
var sync = function() { screen.select(cursor); };
|
var sync = function() { screen.select(cursor); };
|
||||||
var mapping = {
|
var mapping = {
|
||||||
Up: function() {
|
Up: function() {
|
||||||
|
@ -100,7 +100,8 @@ function UI(async, buttons, dom, screen, session) {
|
||||||
var menuConfig = {
|
var menuConfig = {
|
||||||
cancel: config.cancel,
|
cancel: config.cancel,
|
||||||
entries: [],
|
entries: [],
|
||||||
name: config.name
|
name: config.name,
|
||||||
|
selected: config.selected
|
||||||
};
|
};
|
||||||
var apply = function(f, val) { return function() { return f(val); }; };
|
var apply = function(f, val) { return function() { return f(val); }; };
|
||||||
return function(f) {
|
return function(f) {
|
||||||
|
@ -241,7 +242,19 @@ function UI(async, buttons, dom, screen, session) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function setTextSpeed(choices) {
|
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});
|
session.setOptions({textSpeed: value});
|
||||||
textDelay = textSpeeds[value];
|
textDelay = textSpeeds[value];
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue