From d712d405f76178fc67b9421c113dccc3537e2a0c Mon Sep 17 00:00:00 2001 From: Florrie Date: Fri, 14 Dec 2018 23:49:41 -0400 Subject: Add options to not call fixLayout automatically --- ui/DisplayElement.js | 14 ++++++++++---- ui/form/Form.js | 10 +++++----- 2 files changed, 15 insertions(+), 9 deletions(-) (limited to 'ui') diff --git a/ui/DisplayElement.js b/ui/DisplayElement.js index 952c78e..8a2aa71 100644 --- a/ui/DisplayElement.js +++ b/ui/DisplayElement.js @@ -77,7 +77,7 @@ module.exports = class DisplayElement extends EventEmitter { } } - addChild(child, afterIndex = this.children.length) { + addChild(child, afterIndex = this.children.length, {fixLayout = true} = {}) { // TODO Don't let a direct ancestor of this be added as a child. Don't // let itself be one of its childs either! @@ -88,10 +88,13 @@ module.exports = class DisplayElement extends EventEmitter { child.parent = this this.children.splice(afterIndex, 0, child) - child.fixLayout() + + if (fixLayout) { + child.fixLayout() + } } - removeChild(child) { + removeChild(child, {fixLayout = true} = {}) { // Removes the given child element from the children list of this // element. It won't be rendered in the future. If the given element // isn't a direct child of this element, nothing will happen. @@ -102,7 +105,10 @@ module.exports = class DisplayElement extends EventEmitter { child.parent = null this.children.splice(this.children.indexOf(child), 1) - this.fixLayout() + + if (fixLayout) { + this.fixLayout() + } } centerInParent() { diff --git a/ui/form/Form.js b/ui/form/Form.js index 6cdd5a5..7a82b31 100644 --- a/ui/form/Form.js +++ b/ui/form/Form.js @@ -11,19 +11,19 @@ module.exports = class Form extends FocusElement { this.captureTab = true } - addInput(input, asChild = true) { + addInput(input, asChild = true, opts = {}) { // Adds the given input as a child element and pushes it to the input - // list. If the second optional, asChild, is false, it won't add the + // list. If the optional argument asChild is false, it won't add the // input element as a child of the form. this.inputs.push(input) if (asChild) { - this.addChild(input) + this.addChild(input, opts) } } - removeInput(input, asChild = true) { + removeInput(input, asChild = true, opts = {}) { // Removes the given input from the form's input list. If the optional // argument asChild is false, it won't try to removeChild the input. @@ -31,7 +31,7 @@ module.exports = class Form extends FocusElement { this.inputs.splice(this.inputs.indexOf(input), 1) if (asChild) { - this.removeChild(input) + this.removeChild(input, opts) } } } -- cgit 1.3.0-6-gf8a5