add setLabel and removeLabel.
This commit is contained in:
parent
5dc840844c
commit
31e9e9c0c6
|
@ -363,6 +363,8 @@ The base element.
|
|||
- **setIndex(z)** - set the z-index of the element (changes rendering order).
|
||||
- **setFront()** - put the element in front of its siblings.
|
||||
- **setBack()** - put the element in back of its siblings.
|
||||
- **setLabel(text)** - set the label text for the top-left corner.
|
||||
- **removeLabel()** - remove the label completely.
|
||||
|
||||
###### Content Methods
|
||||
|
||||
|
|
|
@ -1802,21 +1802,7 @@ function Element(options) {
|
|||
this.setContent(options.content || '', true);
|
||||
|
||||
if (options.label) {
|
||||
this._label = new Box({
|
||||
screen: this.screen,
|
||||
parent: this,
|
||||
content: options.label,
|
||||
left: 2,
|
||||
top: this.border ? 0 : -1,
|
||||
tags: this.parseTags,
|
||||
shrink: true,
|
||||
style: this.style.label,
|
||||
fixed: true
|
||||
});
|
||||
if (this.screen.autoPadding) {
|
||||
this._label.rleft = -this.ileft + 2;
|
||||
this._label.rtop = -this.itop;
|
||||
}
|
||||
this.setLabel(options.label);
|
||||
}
|
||||
|
||||
// TODO: Possibly move this to Node for screen.on('mouse', ...).
|
||||
|
@ -2360,6 +2346,37 @@ Element.prototype.clearPos = function(get) {
|
|||
lpos.yi, lpos.yl);
|
||||
};
|
||||
|
||||
Element.prototype.setLabel = function(text) {
|
||||
if (this._label) {
|
||||
if (text) {
|
||||
this._label.setContent(text);
|
||||
} else {
|
||||
this._label.detach();
|
||||
delete this._label;
|
||||
}
|
||||
return;
|
||||
}
|
||||
this._label = new Box({
|
||||
screen: this.screen,
|
||||
parent: this,
|
||||
content: text,
|
||||
left: 2,
|
||||
top: this.border ? 0 : -1,
|
||||
tags: this.parseTags,
|
||||
shrink: true,
|
||||
style: this.style.label,
|
||||
fixed: true
|
||||
});
|
||||
if (this.screen.autoPadding) {
|
||||
this._label.rleft = -this.ileft + 2;
|
||||
this._label.rtop = -this.itop;
|
||||
}
|
||||
};
|
||||
|
||||
Element.prototype.removeLabel = function() {
|
||||
return this.setLabel(null);
|
||||
};
|
||||
|
||||
/**
|
||||
* Positioning
|
||||
*/
|
||||
|
@ -4333,7 +4350,12 @@ List.prototype.down = function(offset) {
|
|||
this.move(offset || 1);
|
||||
};
|
||||
|
||||
List.prototype.pick = function(callback) {
|
||||
List.prototype.pick = function(label, callback) {
|
||||
if (!callback) {
|
||||
callback = label;
|
||||
label = null;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
var focused = this.screen.focused;
|
||||
if (focused && focused._done) focused._done('stop');
|
||||
|
@ -4346,8 +4368,10 @@ List.prototype.pick = function(callback) {
|
|||
this.focus();
|
||||
this.show();
|
||||
this.select(0);
|
||||
if (label) this.setLabel(label);
|
||||
this.screen.render();
|
||||
this.once('action', function(el, selected) {
|
||||
if (label) self.removeLabel();
|
||||
self.screen.restoreFocus();
|
||||
self.hide();
|
||||
self.screen.render();
|
||||
|
|
Loading…
Reference in New Issue