From 930d61b9f067346f467d4d84015088f57c54da56 Mon Sep 17 00:00:00 2001 From: liam4 Date: Mon, 3 Jul 2017 21:00:02 -0300 Subject: Buttons and lists - Button class name changed to Button, from ButtonInput - Button layouts are now updated with fixLayout, rather than automatically when the text property is changed - Buttons now have a height of 1, so they can generally actually be used in layouts - New example for list form elements - List form elements let you navigate with up/down (or left/right, for horizontal lists) - List forms now have nextInput and previousInput methods --- ui/form/Form.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'ui/form/Form.js') diff --git a/ui/form/Form.js b/ui/form/Form.js index 9274da4..cf94978 100644 --- a/ui/form/Form.js +++ b/ui/form/Form.js @@ -30,20 +30,33 @@ module.exports = class Form extends FocusElement { } if (telc.isTab(keyBuf)) { - this.curIndex = (this.curIndex + 1) % this.inputs.length + this.nextInput() } else { - this.curIndex = (this.curIndex - 1) - if (this.curIndex < 0) { - this.curIndex = (this.inputs.length - 1) - } + this.previousInput() } - const nextInput = this.inputs[this.curIndex] - this.root.select(nextInput) - return false } } + + updateSelectedElement() { + this.root.select(this.inputs[this.curIndex]) + } + + previousInput() { + this.curIndex = (this.curIndex - 1) + if (this.curIndex < 0) { + this.curIndex = (this.inputs.length - 1) + } + + this.updateSelectedElement() + } + + nextInput() { + this.curIndex = (this.curIndex + 1) % this.inputs.length + + this.updateSelectedElement() + } focused() { this.root.select(this.inputs[this.curIndex]) -- cgit 1.3.0-6-gf8a5