diff options
author | Explorer09 <explorer09@gmail.com> | 2024-04-13 23:07:42 +0800 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2024-04-13 19:05:04 +0200 |
commit | 0da63c903c6c5227fdebf3a5adaba095dde92841 (patch) | |
tree | 9f9001ca699da06d8bd86352ab0ac2a060454cdd | |
parent | 1a12d5852602a7507d5911408561a754c446539c (diff) |
BarMeterMode_draw() code formatting adjustment
Suggested by Benny Baumann (@BenBE). No code changes.
-rw-r--r-- | Meter.c | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -184,12 +184,15 @@ static void TextMeterMode_draw(Meter* this, int x, int y, int w) { static const char BarMeterMode_characters[] = "|#*@$%&."; static void BarMeterMode_draw(Meter* this, int x, int y, int w) { + // Draw the caption const char* caption = Meter_getCaption(this); attrset(CRT_colors[METER_TEXT]); int captionLen = 3; mvaddnstr(y, x, caption, captionLen); x += captionLen; w -= captionLen; + + // Draw the bar borders attrset(CRT_colors[BAR_BORDER]); mvaddch(y, x, '['); w--; @@ -199,14 +202,16 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { x++; - if (w < 1) + if (w < 1) { return; + } // The text in the bar is right aligned; // Pad with maximal spaces and then calculate needed starting position offset RichString_begin(bar); RichString_appendChr(&bar, 0, ' ', w); RichString_appendWide(&bar, 0, this->txtBuffer); + int startPos = RichString_sizeVal(bar) - w; if (startPos > w) { // Text is too large for bar @@ -223,6 +228,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { // If still too large, print the start not the end startPos = MINIMUM(startPos, w); } + assert(startPos >= 0); assert(startPos <= w); assert(startPos + w <= RichString_sizeVal(bar)); |