From 52a9f5d1820114527a7aa396a1bfb3767735b56c Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 1 Aug 2013 07:09:06 -0500 Subject: [PATCH] fix scroll rendering for children with padding. --- lib/widget.js | 22 +++++++++++++++------- test/widget-scrollable-boxes.js | 6 +++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/widget.js b/lib/widget.js index febefcd..5179485 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -2864,7 +2864,8 @@ Element.prototype._getCoords = function(get) { , noright , notop , nobot - , ppos; + , ppos + , b; // Attempt to shrink the element base on the // size of the content and child elements. @@ -2900,30 +2901,37 @@ Element.prototype._getCoords = function(get) { if (!ppos) return; + // TODO: Figure out how to fix base (and cbase to only + // take into account the *parent's* padding. + yi -= ppos.base; yl -= ppos.base; - if (yi < ppos.yi + this.parent.itop) { - if (yl - 1 < ppos.yi + this.parent.itop) { + b = this.parent.border ? 1 : 0; + + if (yi < ppos.yi + b) { + if (yl - 1 < ppos.yi + b) { // Is above. return; } else { // Is partially covered above. notop = true; v = ppos.yi - yi; - v += this.parent.itop - this.itop; + if (this.border) v--; + if (this.parent.border) v++; base += v; yi += v; } - } else if (yl > ppos.yl - this.parent.ibottom) { - if (yi > ppos.yl - 1 - this.parent.ibottom) { + } else if (yl > ppos.yl - b) { + if (yi > ppos.yl - 1 - b) { // Is below. return; } else { // Is partially covered below. nobot = true; v = yl - ppos.yl; - v += this.parent.ibottom - this.ibottom; + if (this.border) v--; + if (this.parent.border) v++; yl -= v; } } diff --git a/test/widget-scrollable-boxes.js b/test/widget-scrollable-boxes.js index 6995e19..8d8889c 100644 --- a/test/widget-scrollable-boxes.js +++ b/test/widget-scrollable-boxes.js @@ -8,6 +8,7 @@ screen = blessed.screen({ var box = blessed.box({ parent: screen, + //padding: 2, scrollable: true, left: 'center', top: 'center', @@ -21,7 +22,7 @@ var box = blessed.box({ keys: true, vi: true, alwaysScroll: true, - scrollbar_: { + scrollbar: { ch: ' ', inverse: true } @@ -30,6 +31,7 @@ var box = blessed.box({ var text = blessed.box({ parent: box, content: 'hello1\nhello2\nhello3\nhello4', + padding: 2, style: { bg: 'red' }, @@ -42,6 +44,7 @@ var text = blessed.box({ var text2 = blessed.box({ parent: box, content: 'world', + padding: 1, style: { bg: 'red' }, @@ -55,6 +58,7 @@ var box2 = blessed.box({ parent: box, scrollable: true, content: 'foo-one\nfoo-two\nfoo-three', + padding: 2, left: 'center', top: 20, width: '80%',