fix scroll rendering for children with padding.

This commit is contained in:
Christopher Jeffrey 2013-08-01 07:09:06 -05:00
parent c4a7f05025
commit 52a9f5d182
2 changed files with 20 additions and 8 deletions

View File

@ -2864,7 +2864,8 @@ Element.prototype._getCoords = function(get) {
, noright , noright
, notop , notop
, nobot , nobot
, ppos; , ppos
, b;
// Attempt to shrink the element base on the // Attempt to shrink the element base on the
// size of the content and child elements. // size of the content and child elements.
@ -2900,30 +2901,37 @@ Element.prototype._getCoords = function(get) {
if (!ppos) return; if (!ppos) return;
// TODO: Figure out how to fix base (and cbase to only
// take into account the *parent's* padding.
yi -= ppos.base; yi -= ppos.base;
yl -= ppos.base; yl -= ppos.base;
if (yi < ppos.yi + this.parent.itop) { b = this.parent.border ? 1 : 0;
if (yl - 1 < ppos.yi + this.parent.itop) {
if (yi < ppos.yi + b) {
if (yl - 1 < ppos.yi + b) {
// Is above. // Is above.
return; return;
} else { } else {
// Is partially covered above. // Is partially covered above.
notop = true; notop = true;
v = ppos.yi - yi; v = ppos.yi - yi;
v += this.parent.itop - this.itop; if (this.border) v--;
if (this.parent.border) v++;
base += v; base += v;
yi += v; yi += v;
} }
} else if (yl > ppos.yl - this.parent.ibottom) { } else if (yl > ppos.yl - b) {
if (yi > ppos.yl - 1 - this.parent.ibottom) { if (yi > ppos.yl - 1 - b) {
// Is below. // Is below.
return; return;
} else { } else {
// Is partially covered below. // Is partially covered below.
nobot = true; nobot = true;
v = yl - ppos.yl; v = yl - ppos.yl;
v += this.parent.ibottom - this.ibottom; if (this.border) v--;
if (this.parent.border) v++;
yl -= v; yl -= v;
} }
} }

View File

@ -8,6 +8,7 @@ screen = blessed.screen({
var box = blessed.box({ var box = blessed.box({
parent: screen, parent: screen,
//padding: 2,
scrollable: true, scrollable: true,
left: 'center', left: 'center',
top: 'center', top: 'center',
@ -21,7 +22,7 @@ var box = blessed.box({
keys: true, keys: true,
vi: true, vi: true,
alwaysScroll: true, alwaysScroll: true,
scrollbar_: { scrollbar: {
ch: ' ', ch: ' ',
inverse: true inverse: true
} }
@ -30,6 +31,7 @@ var box = blessed.box({
var text = blessed.box({ var text = blessed.box({
parent: box, parent: box,
content: 'hello1\nhello2\nhello3\nhello4', content: 'hello1\nhello2\nhello3\nhello4',
padding: 2,
style: { style: {
bg: 'red' bg: 'red'
}, },
@ -42,6 +44,7 @@ var text = blessed.box({
var text2 = blessed.box({ var text2 = blessed.box({
parent: box, parent: box,
content: 'world', content: 'world',
padding: 1,
style: { style: {
bg: 'red' bg: 'red'
}, },
@ -55,6 +58,7 @@ var box2 = blessed.box({
parent: box, parent: box,
scrollable: true, scrollable: true,
content: 'foo-one\nfoo-two\nfoo-three', content: 'foo-one\nfoo-two\nfoo-three',
padding: 2,
left: 'center', left: 'center',
top: 20, top: 20,
width: '80%', width: '80%',