Skip to content

Commit

Permalink
BarMeterMode_draw() code formatting adjustment
Browse files Browse the repository at this point in the history
Suggested by Benny Baumann (@BenBE). No code changes.
  • Loading branch information
Explorer09 authored and BenBE committed Apr 13, 2024
1 parent 1a12d58 commit 0da63c9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
Expand All @@ -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
Expand All @@ -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));
Expand Down

0 comments on commit 0da63c9

Please sign in to comment.