diff options
Diffstat (limited to 'ui/form')
-rw-r--r-- | ui/form/Button.js | 10 | ||||
-rw-r--r-- | ui/form/Form.js | 2 | ||||
-rw-r--r-- | ui/form/ListScrollForm.js | 35 |
3 files changed, 46 insertions, 1 deletions
diff --git a/ui/form/Button.js b/ui/form/Button.js index 3a35912..46329a6 100644 --- a/ui/form/Button.js +++ b/ui/form/Button.js @@ -38,4 +38,14 @@ module.exports = class Button extends FocusElement { this.emit('pressed') } } + + clicked(button) { + if (button === 'left') { + if (this.isSelected) { + this.emit('pressed') + } else { + this.root.select(this) + } + } + } } diff --git a/ui/form/Form.js b/ui/form/Form.js index ac9f1e4..6cdd5a5 100644 --- a/ui/form/Form.js +++ b/ui/form/Form.js @@ -76,7 +76,7 @@ module.exports = class Form extends FocusElement { this.curIndex = this.inputs.length - 1 } - this.root.select(this.inputs[this.curIndex]) + this.root.select(this.inputs[this.curIndex], {fromForm: true}) } } diff --git a/ui/form/ListScrollForm.js b/ui/form/ListScrollForm.js index 3f16416..77bebcd 100644 --- a/ui/form/ListScrollForm.js +++ b/ui/form/ListScrollForm.js @@ -24,6 +24,8 @@ module.exports = class ListScrollForm extends Form { } fixLayout() { + this.keepScrollInBounds() + // The scrollItems property represents the item to the very left of where // we've scrolled, so we know right away that none of those will be // visible and we won't bother iterating over them. @@ -96,6 +98,34 @@ module.exports = class ListScrollForm extends Form { return ret } + clicked(button) { + // Old code for changing the actual selected item...maybe an interesting + // functionality to explore later? + /* + if (button === 'scroll-up') { + this.previousInput() + this.scrollSelectedElementIntoView() + } else if (button === 'scroll-down') { + this.nextInput() + this.scrollSelectedElementIntoView() + } + */ + + // Scrolling is typically pretty slow with a mouse wheel when it's by + // a single line, so scroll at 3x that speed. + for (let i = 0; i < 3; i++) { + if (button === 'scroll-up') { + this.scrollItems-- + } else if (button === 'scroll-down') { + this.scrollItems++ + } else { + return + } + } + + this.fixLayout() + } + scrollSelectedElementIntoView() { const sel = this.inputs[this.curIndex] @@ -152,6 +182,11 @@ module.exports = class ListScrollForm extends Form { this.fixLayout() } + keepScrollInBounds() { + this.scrollItems = Math.max(this.scrollItems, 0) + this.scrollItems = Math.min(this.scrollItems, this.getScrollItemsLength()) + } + getScrollItemsLength() { if (typeof this._scrollItemsLength === 'undefined') { const lastInput = this.inputs[this.inputs.length - 1] |