diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2020-12-15 17:25:25 +0100 |
---|---|---|
committer | cgzones <cgzones@googlemail.com> | 2020-12-20 16:55:17 +0100 |
commit | c5e31ba4aacb4065457d184567e12de657ad8735 (patch) | |
tree | 772d5e82a0346132a4be7edf505a425b429b2eb4 /Meter.c | |
parent | f878f302caf0e10762bedda0839bb87c0ce1fb92 (diff) |
Meter: fix artifacts with very tiny width
- The Bar Meter might override the right border
- The TextMeter might wrap-around into the next line
Diffstat (limited to 'Meter.c')
-rw-r--r-- | Meter.c | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -156,16 +156,20 @@ ListItem* Meter_toListItem(Meter* this, bool moving) { static void TextMeterMode_draw(Meter* this, int x, int y, int w) { char buffer[METER_BUFFER_LEN]; Meter_updateValues(this, buffer, sizeof(buffer)); - (void) w; attrset(CRT_colors[METER_TEXT]); - mvaddstr(y, x, this->caption); + mvaddnstr(y, x, this->caption, w - 1); + attrset(CRT_colors[RESET_COLOR]); + int captionLen = strlen(this->caption); x += captionLen; - attrset(CRT_colors[RESET_COLOR]); + w -= captionLen; + if (w <= 0) + return; + RichString_begin(out); Meter_displayBuffer(this, buffer, &out); - RichString_printVal(out, y, x); + RichString_printoffnVal(out, y, x, 0, w - 1); RichString_end(out); } @@ -185,7 +189,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { w -= captionLen; attrset(CRT_colors[BAR_BORDER]); mvaddch(y, x, '['); - mvaddch(y, x + w, ']'); + mvaddch(y, x + MAXIMUM(w, 0), ']'); attrset(CRT_colors[RESET_COLOR]); w--; @@ -238,7 +242,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { offset = 0; for (uint8_t i = 0; i < this->curItems; i++) { RichString_setAttrn(&bar, CRT_colors[Meter_attributes(this)[i]], offset, offset + blockSizes[i] - 1); - RichString_printoffnVal(bar, y, x + offset, offset, blockSizes[i]); + RichString_printoffnVal(bar, y, x + offset, offset, MINIMUM(blockSizes[i], w - offset)); offset += blockSizes[i]; offset = CLAMP(offset, 0, w); } |