Skip to content

Commit

Permalink
replace shrink padding code.
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Jul 17, 2013
1 parent 8e81ef0 commit e9f7d93
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
39 changes: 15 additions & 24 deletions lib/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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 };
};

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
});

Expand Down
14 changes: 8 additions & 6 deletions test/widget-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ var set = blessed.radioset({
left: 0,
top: 0,
shrink: true,
height: 1,
//padding: 1,
//content: 'f',
bg: 'magenta'
});

Expand Down Expand Up @@ -62,7 +63,7 @@ var text = blessed.textbox({
height: 1,
width: 20,
left: 1,
top: 1,
top: 2,
name: 'text'
});

Expand All @@ -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'
});
Expand All @@ -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',
Expand Down

0 comments on commit e9f7d93

Please sign in to comment.