From e9f7d933bdb11f65199005a73997f53cf286aced Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 17 Jul 2013 05:30:42 -0500 Subject: [PATCH] replace shrink padding code. --- lib/widget.js | 39 +++++++++++++++------------------------ test/widget-form.js | 14 ++++++++------ 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/lib/widget.js b/lib/widget.js index e6058cd..e2d51ef 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -1981,8 +1981,10 @@ Box.prototype._getShrinkBox = function(xi, xl, yi, yl) { || this.options.right == null)) { if (this.options.left == null && this.options.right != null) { xi = xl - (mxl - mxi); + xi -= this.padding * 2; } else { xl = mxl; + xl += this.padding * 2; } } @@ -1992,8 +1994,10 @@ Box.prototype._getShrinkBox = function(xi, xl, yi, yl) { && this.childBase == null) { if (this.options.top == null && this.options.bottom != null) { yi = yl - (myl - myi); + yi -= this.padding * 2; } else { yl = myl; + yl += this.padding * 2; } } @@ -2065,29 +2069,6 @@ Box.prototype._getShrink = function(xi, xl, yi, yl, content) { yl += yll; } - // Add padding, doesn't seem to be necessary. - if (0 && this.padding) { - if (this.options.width == null - && (this.options.left == null - || this.options.right == null)) { - if (this.options.left == null && this.options.right != null) { - xi -= this.padding * 2; - } else { - xl += this.padding * 2; - } - } - if (this.options.height == null - && (this.options.top == null - || this.options.bottom == null) - && this.childBase == null) { - if (this.options.top == null && this.options.bottom != null) { - yi -= this.padding * 2; - } else { - yl += this.padding * 2; - } - } - } - return { xi: xi, xl: xl, yi: yi, yl: yl }; }; @@ -2163,6 +2144,15 @@ Box.prototype.render = function(stop) { xi = ret.xi, xl = ret.xl, yi = ret.yi, yl = ret.yl; } + // TODO: Possibly do something like this, except more complex. + // if (this.parent.padding) { + // xi += this.parent.padding; + // xl += this.parent.padding; + // yi += this.parent.padding; + // yl += this.parent.padding; + // } + // if (this.parent.border) xi++, xl++, yi++, yl++; + ret = { xi: xi, xl: xl, @@ -4013,8 +4003,9 @@ function Checkbox(options) { } this.on('focus', function(old) { + if (!this.lpos) return; self.screen.program.saveCursor(); - self.screen.program.cup(this.top, this.left + 1); + self.screen.program.cup(this.lpos.yi, this.lpos.xi + 1); self.screen.program.showCursor(); }); diff --git a/test/widget-form.js b/test/widget-form.js index 4badf4f..04cb113 100644 --- a/test/widget-form.js +++ b/test/widget-form.js @@ -24,7 +24,8 @@ var set = blessed.radioset({ left: 0, top: 0, shrink: true, - height: 1, + //padding: 1, + //content: 'f', bg: 'magenta' }); @@ -62,7 +63,7 @@ var text = blessed.textbox({ height: 1, width: 20, left: 1, - top: 1, + top: 2, name: 'text' }); @@ -77,8 +78,8 @@ var check = blessed.checkbox({ shrink: true, bg: 'magenta', height: 1, - left: 24, - top: 1, + left: 28, + top: 0, name: 'check', content: 'check' }); @@ -87,9 +88,10 @@ var submit = blessed.button({ parent: form, mouse: true, keys: true, - height: 1, + shrink: true, + padding: 1, left: 30, - top: 0, + top: 2, shrink: true, name: 'submit', content: 'submit',