Skip to content

Commit 9b8c443

Browse files
committed
Introduce Meter_drawCaptionFixedWidth() function
1 parent 1330b6a commit 9b8c443

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

Meter.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ typedef struct MeterMode_ {
3939

4040
/* Meter drawing modes */
4141

42+
static void Meter_drawCaptionFixedWidth(const Meter* this, int x, int y, int w) {
43+
attrset(CRT_colors[METER_TEXT]);
44+
const char* caption = Meter_getCaption(this);
45+
mvaddnstr(y, x, caption, w);
46+
}
47+
4248
static inline void Meter_displayBuffer(const Meter* this, RichString* out) {
4349
if (Object_displayFn(this)) {
4450
Object_display(this, out);
@@ -79,12 +85,10 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
7985
w = MINIMUM(INT_MAX - x, w);
8086

8187
// Draw the caption
82-
const char* caption = Meter_getCaption(this);
83-
attrset(CRT_colors[METER_TEXT]);
84-
int captionLen = 3;
85-
mvaddnstr(y, x, caption, captionLen);
86-
x += captionLen;
87-
w -= captionLen;
88+
const int captionWidth = 3;
89+
Meter_drawCaptionFixedWidth(this, x, y, captionWidth);
90+
x += captionWidth;
91+
w -= captionWidth;
8892

8993
// Draw the bar borders
9094
attrset(CRT_colors[BAR_BORDER]);
@@ -202,12 +206,10 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
202206
w = MINIMUM(INT_MAX - x, w);
203207

204208
// Draw the caption
205-
const char* caption = Meter_getCaption(this);
206-
attrset(CRT_colors[METER_TEXT]);
207-
const int captionLen = 3;
208-
mvaddnstr(y, x, caption, captionLen);
209-
x += captionLen;
210-
w -= captionLen;
209+
const int captionWidth = 3;
210+
Meter_drawCaptionFixedWidth(this, x, y, captionWidth);
211+
x += captionWidth;
212+
w -= captionWidth;
211213

212214
GraphData* data = &this->drawData;
213215

0 commit comments

Comments
 (0)