From 769413468e88acba1a180baa0113139d929a3b9f Mon Sep 17 00:00:00 2001 From: liam4 Date: Mon, 3 Jul 2017 18:59:57 -0300 Subject: A long-due cleanup + examples + things ..Obviously this breaks old things (particularly, see changes in FocusElement). --- examples/basic-app.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 examples/basic-app.js (limited to 'examples/basic-app.js') diff --git a/examples/basic-app.js b/examples/basic-app.js new file mode 100644 index 0000000..bf8aa41 --- /dev/null +++ b/examples/basic-app.js @@ -0,0 +1,51 @@ +// Basic app demo: +// - Structuring a basic element tree +// - Creating a pane and text input +// - Using content width/height to layout elements +// - Subclassing a FocusElement and using its focused method +// - Sending a quit-app request via Control-C +// +// This script cannot actually be used on its own; see the examples on +// interfacers (interfacer-command-line.js and inerfacer-telnet.js) for a +// working demo. + +const Pane = require('../ui/Pane') +const FocusElement = require('../ui/form/FocusElement') +const TextInput = require('../ui/form/TextInput') + +module.exports = class AppElement extends FocusElement { + constructor() { + super() + + this.pane = new Pane() + this.addChild(this.pane) + + this.textInput = new TextInput() + this.pane.addChild(this.textInput) + } + + fixLayout() { + this.w = this.parent.contentW + this.h = this.parent.contentH + + this.pane.w = this.contentW + this.pane.h = this.contentH + + this.textInput.x = 4 + this.textInput.y = 2 + this.textInput.w = this.pane.contentW - 8 + } + + focused() { + this.root.select(this.textInput) + } + + keyPressed(keyBuf) { + if (keyBuf[0] === 0x03) { // 0x03 is Control-C + this.emit('quitRequested') + return + } + + super.keyPressed(keyBuf) + } +} -- cgit 1.3.0-6-gf8a5