diff options
author | Florrie <towerofnix@gmail.com> | 2018-06-12 23:55:06 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-06-12 23:55:06 -0300 |
commit | c5b3a076963517c93b6596f3e0a860be1d80ef80 (patch) | |
tree | 83bf575df2adb45227c39437d545a87347bad808 /ui/Label.js | |
parent | 5ca7837f83be3c3ea1081db150ece49875fa61a0 (diff) |
Add WrapLabel UI element
Diffstat (limited to 'ui/Label.js')
-rw-r--r-- | ui/Label.js | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/ui/Label.js b/ui/Label.js index 850edc0..faeee98 100644 --- a/ui/Label.js +++ b/ui/Label.js @@ -5,20 +5,23 @@ const DisplayElement = require('./DisplayElement') module.exports = class Label extends DisplayElement { // A simple text display. Automatically adjusts size to fit text. - constructor(text='') { + constructor(text = '') { super() this.text = text this.textAttributes = [] } + fixLayout() { + this.w = this.text.length + } + drawTo(writable) { if (this.textAttributes.length) { writable.write(ansi.setAttributes(this.textAttributes)) } - writable.write(ansi.moveCursor(this.absTop, this.absLeft)) - writable.write(this.text) + this.writeTextTo(writable) if (this.textAttributes.length) { writable.write(ansi.resetAttributes()) @@ -27,10 +30,14 @@ module.exports = class Label extends DisplayElement { super.drawTo(writable) } + writeTextTo(writable) { + writable.write(ansi.moveCursor(this.absTop, this.absLeft)) + writable.write(this.text) + } + set text(newText) { this._text = newText - - this.w = newText.length + this.fixLayout() } get text() { |