Allow itemFormat/focusItem format on TextViews/Buttons/...

This commit is contained in:
Bryan Ashby 2023-02-01 21:59:55 -07:00
parent 45deef3f03
commit eb9d9055e9
No known key found for this signature in database
GPG Key ID: C2C1B501E4EFD994
1 changed files with 21 additions and 6 deletions

View File

@ -54,13 +54,28 @@ function TextView(options) {
// |ABCDEFG| ^_ this.text.length
// ^-- this.dimens.width
//
let renderLength = renderStringLength(s); // initial; may be adjusted below:
let textToDraw;
if (this.itemFormat) {
textToDraw = pipeToAnsi(
stringFormat(
this.hasFocus && this.focusItemFormat
? this.focusItemFormat
: this.itemFormat,
{
text: stylizeString(
s,
this.hasFocus ? this.focusTextStyle : this.textStyle
),
}
)
);
} else {
textToDraw = _.isString(this.textMaskChar)
? new Array(renderStringLength(s) + 1).join(this.textMaskChar)
: stylizeString(s, this.hasFocus ? this.focusTextStyle : this.textStyle);
}
let textToDraw = _.isString(this.textMaskChar)
? new Array(renderLength + 1).join(this.textMaskChar)
: stylizeString(s, this.hasFocus ? this.focusTextStyle : this.textStyle);
renderLength = renderStringLength(textToDraw);
const renderLength = renderStringLength(textToDraw);
if (renderLength >= this.dimens.width) {
if (this.hasFocus) {