Fixed justification

This commit is contained in:
Nathan Byrd 2022-01-19 14:36:43 -06:00
parent d77de9c388
commit c82497b75e
2 changed files with 19 additions and 10 deletions

View File

@ -124,9 +124,9 @@ function FullMenuView(options) {
// Check if we have room for this column
// skip for column 0, we need at least one
if (itemInCol != 0 && (col + maxLength + spacer.length + 1 > this.position.col + this.dimens.width)) {
if (itemInCol != 0 && (col + maxLength > this.dimens.width)) {
// save previous page
this.pages.push({ start: pageStart, end: i - this.itemsPerRow });
this.pages.push({ start: pageStart, end: i - itemInRow });
// fix the last column processed
for (var j = 0; j < this.itemsPerRow; j++) {
@ -165,7 +165,7 @@ function FullMenuView(options) {
// Check if we have room for this column in the current page
// skip for first column, we need at least one
if (itemInCol != 0 && (col + maxLength > this.position.col + this.dimens.width)) {
if (itemInCol != 0 && (col + maxLength > this.dimens.width)) {
// save previous page
this.pages.push({ start: pageStart, end: i - this.itemsPerRow });
@ -181,10 +181,6 @@ function FullMenuView(options) {
this.items[i - j].col = col;
}
}
// increment the column
@ -233,7 +229,9 @@ function FullMenuView(options) {
text = strUtil.renderSubstr(text, 0, this.dimens.width - (item.col + this.textOverflow.length)) + this.textOverflow;
}
text = `${sgr}${strUtil.pad(text, this.fixedLength, this.fillChar, this.justify)}`;
let padLength = Math.min(item.fixedLength + 1, this.dimens.width);
text = `${sgr}${strUtil.pad(text, padLength, this.fillChar, this.justify)}`;
this.client.term.write(`${ansi.goto(item.row, item.col)}${text}`);
this.setRenderCacheItem(index, text, item.focused);
};
@ -508,6 +506,12 @@ FullMenuView.prototype.setItemSpacing = function(itemSpacing) {
this.positionCacheExpired = true;
};
FullMenuView.prototype.setJustify = function(justify) {
FullMenuView.super_.prototype.setJustify.call(this, justify);
this.positionCacheExpired = true;
};
FullMenuView.prototype.setItemHorizSpacing = function(itemHorizSpacing) {
FullMenuView.super_.prototype.setItemHorizSpacing.call(this, itemHorizSpacing);

View File

@ -46,7 +46,6 @@ function MenuView(options) {
this.focusSuffix = options.focusSuffix || '';
this.fillChar = miscUtil.valueWithDefault(options.fillChar, ' ').substr(0, 1);
this.justify = options.justify || 'none';
this.hasFocusItems = function() {
return !_.isUndefined(self.focusItems);
@ -280,7 +279,7 @@ MenuView.prototype.setPropertyValue = function(propName, value) {
case 'hotKeys': this.setHotKeys(value); break;
case 'textOverflow': this.setTextOverflow(value); break;
case 'hotKeySubmit': this.hotKeySubmit = value; break;
case 'justify': this.justify = value; break;
case 'justify': this.setJustify(value); break;
case 'focusItemIndex': this.focusedItemIndex = value; break;
case 'itemFormat':
@ -296,6 +295,12 @@ MenuView.prototype.setPropertyValue = function(propName, value) {
MenuView.super_.prototype.setPropertyValue.call(this, propName, value);
};
MenuView.prototype.setJustify = function(justify) {
this.justify = justify;
this.invalidateRenderCache();
this.positionCacheExpired = true;
};
MenuView.prototype.setHotKeys = function(hotKeys) {
if (_.isObject(hotKeys)) {
if (this.caseInsensitiveHotKeys) {