Skip to content

Commit 09de683

Browse files
committed
Add xOffsetOfMeterColumn() sub-function in CPUMeterCommonDraw()
Make the 'x' offset calculation in CPUMeterCommonDraw() a sub-function. There should be no changes to the compiled code. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
1 parent 79abc57 commit 09de683

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

CPUMeter.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,17 +300,22 @@ static void OctoColCPUsMeter_updateMode(Meter* this, MeterModeId mode) {
300300
CPUMeterCommonUpdateMode(this, mode, 8);
301301
}
302302

303+
static int xOffsetOfMeterColumn(int w, int nCol, int col) {
304+
int colwidth = w / nCol;
305+
int diff = w % nCol;
306+
int d = MINIMUM(diff, col); // dynamic spacer
307+
return (col * colwidth) + d;
308+
}
309+
303310
static void CPUMeterCommonDraw(Meter* this, int x, int y, int w, int ncol) {
304311
CPUMeterData* data = this->meterData;
305312
Meter** meters = data->meters;
306313
int start, count;
307314
AllCPUsMeter_getRange(this, &start, &count);
308315
int colwidth = w / ncol;
309-
int diff = w % ncol;
310316
int nrows = (count + ncol - 1) / ncol;
311317
for (int i = 0; i < count; i++) {
312-
int d = (i / nrows) > diff ? diff : (i / nrows); // dynamic spacer
313-
int xpos = x + ((i / nrows) * colwidth) + d;
318+
int xpos = x + xOffsetOfMeterColumn(w, ncol, i / nrows);
314319
int ypos = y + ((i % nrows) * meters[0]->h);
315320
meters[i]->draw(meters[i], xpos, ypos, colwidth);
316321
}

0 commit comments

Comments
 (0)