summaryrefslogtreecommitdiffstats
path: root/Meter.c
diff options
context:
space:
mode:
authorExplorer09 <explorer09@gmail.com>2024-04-13 23:07:42 +0800
committerBenBE <BenBE@geshi.org>2024-04-13 19:05:04 +0200
commit0da63c903c6c5227fdebf3a5adaba095dde92841 (patch)
tree9f9001ca699da06d8bd86352ab0ac2a060454cdd /Meter.c
parent1a12d5852602a7507d5911408561a754c446539c (diff)
BarMeterMode_draw() code formatting adjustment
Suggested by Benny Baumann (@BenBE). No code changes.
Diffstat (limited to 'Meter.c')
-rw-r--r--Meter.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/Meter.c b/Meter.c
index 86f88856..938b907b 100644
--- a/Meter.c
+++ b/Meter.c
@@ -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));

© 2014-2024 Faster IT GmbH | imprint | privacy policy