Separate data-update and drawing of header

This commit is contained in:
Christian Göttsche 2021-02-08 16:38:49 +01:00 committed by BenBE
parent 2d1042adb3
commit b862e36ee7
7 changed files with 38 additions and 8 deletions

View File

@ -76,6 +76,7 @@ static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) {
if (update) {
this->settings->changed = true;
Header_calculateHeight(header);
Header_updateData(header);
Header_draw(header);
ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2);
}

View File

@ -187,6 +187,15 @@ static void AllCPUsMeter_getRange(const Meter* this, int* start, int* count) {
}
}
static void AllCPUsMeter_updateValues(Meter* this) {
CPUMeterData* data = this->meterData;
Meter** meters = data->meters;
int start, count;
AllCPUsMeter_getRange(this, &start, &count);
for (int i = 0; i < count; i++)
Meter_updateValues(meters[i]);
}
static void CPUMeterCommonInit(Meter* this, int ncol) {
int cpus = this->pl->cpuCount;
CPUMeterData* data = this->meterData;
@ -332,6 +341,7 @@ const MeterClass AllCPUsMeter_class = {
.delete = Meter_delete,
.display = CPUMeter_display
},
.updateValues = AllCPUsMeter_updateValues,
.defaultMode = CUSTOM_METERMODE,
.total = 100.0,
.attributes = CPUMeter_attributes,
@ -351,6 +361,7 @@ const MeterClass AllCPUs2Meter_class = {
.delete = Meter_delete,
.display = CPUMeter_display
},
.updateValues = AllCPUsMeter_updateValues,
.defaultMode = CUSTOM_METERMODE,
.total = 100.0,
.attributes = CPUMeter_attributes,
@ -370,6 +381,7 @@ const MeterClass LeftCPUsMeter_class = {
.delete = Meter_delete,
.display = CPUMeter_display
},
.updateValues = AllCPUsMeter_updateValues,
.defaultMode = CUSTOM_METERMODE,
.total = 100.0,
.attributes = CPUMeter_attributes,
@ -389,6 +401,7 @@ const MeterClass RightCPUsMeter_class = {
.delete = Meter_delete,
.display = CPUMeter_display
},
.updateValues = AllCPUsMeter_updateValues,
.defaultMode = CUSTOM_METERMODE,
.total = 100.0,
.attributes = CPUMeter_attributes,
@ -408,6 +421,7 @@ const MeterClass LeftCPUs2Meter_class = {
.delete = Meter_delete,
.display = CPUMeter_display
},
.updateValues = AllCPUsMeter_updateValues,
.defaultMode = CUSTOM_METERMODE,
.total = 100.0,
.attributes = CPUMeter_attributes,
@ -427,6 +441,7 @@ const MeterClass RightCPUs2Meter_class = {
.delete = Meter_delete,
.display = CPUMeter_display
},
.updateValues = AllCPUsMeter_updateValues,
.defaultMode = CUSTOM_METERMODE,
.total = 100.0,
.attributes = CPUMeter_attributes,
@ -446,6 +461,7 @@ const MeterClass AllCPUs4Meter_class = {
.delete = Meter_delete,
.display = CPUMeter_display
},
.updateValues = AllCPUsMeter_updateValues,
.defaultMode = CUSTOM_METERMODE,
.total = 100.0,
.attributes = CPUMeter_attributes,
@ -465,6 +481,7 @@ const MeterClass LeftCPUs4Meter_class = {
.delete = Meter_delete,
.display = CPUMeter_display
},
.updateValues = AllCPUsMeter_updateValues,
.defaultMode = CUSTOM_METERMODE,
.total = 100.0,
.attributes = CPUMeter_attributes,
@ -484,6 +501,7 @@ const MeterClass RightCPUs4Meter_class = {
.delete = Meter_delete,
.display = CPUMeter_display
},
.updateValues = AllCPUsMeter_updateValues,
.defaultMode = CUSTOM_METERMODE,
.total = 100.0,
.attributes = CPUMeter_attributes,
@ -503,6 +521,7 @@ const MeterClass AllCPUs8Meter_class = {
.delete = Meter_delete,
.display = CPUMeter_display
},
.updateValues = AllCPUsMeter_updateValues,
.defaultMode = CUSTOM_METERMODE,
.total = 100.0,
.attributes = CPUMeter_attributes,
@ -522,6 +541,7 @@ const MeterClass LeftCPUs8Meter_class = {
.delete = Meter_delete,
.display = CPUMeter_display
},
.updateValues = AllCPUsMeter_updateValues,
.defaultMode = CUSTOM_METERMODE,
.total = 100.0,
.attributes = CPUMeter_attributes,
@ -541,6 +561,7 @@ const MeterClass RightCPUs8Meter_class = {
.delete = Meter_delete,
.display = CPUMeter_display
},
.updateValues = AllCPUsMeter_updateValues,
.defaultMode = CUSTOM_METERMODE,
.total = 100.0,
.attributes = CPUMeter_attributes,

View File

@ -72,6 +72,7 @@ static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
Header* header = this->scr->header;
Header_calculateHeight(header);
Header_reinit(header);
Header_updateData(header);
Header_draw(header);
ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2);
}

View File

@ -177,6 +177,17 @@ void Header_draw(const Header* this) {
}
}
void Header_updateData(Header* this) {
Header_forEachColumn(this, col) {
Vector* meters = this->columns[col];
int items = Vector_size(meters);
for (int i = 0; i < items; i++) {
Meter* meter = (Meter*) Vector_get(meters, i);
Meter_updateValues(meter);
}
}
}
/*
* Calculate how many columns the current meter is allowed to span,
* by counting how many columns to the right are empty or contain a BlankMeter.

View File

@ -45,6 +45,8 @@ void Header_reinit(Header* this);
void Header_draw(const Header* this);
void Header_updateData(Header* this);
int Header_calculateHeight(Header* this);
#endif

View File

@ -154,8 +154,6 @@ ListItem* Meter_toListItem(const Meter* this, bool moving) {
/* ---------- TextMeterMode ---------- */
static void TextMeterMode_draw(Meter* this, int x, int y, ATTR_UNUSED int w) {
Meter_updateValues(this);
attrset(CRT_colors[METER_TEXT]);
mvaddnstr(y, x, this->caption, w - 1);
attrset(CRT_colors[RESET_COLOR]);
@ -177,8 +175,6 @@ static void TextMeterMode_draw(Meter* this, int x, int y, ATTR_UNUSED int w) {
static const char BarMeterMode_characters[] = "|#*@$%&.";
static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
Meter_updateValues(this);
w -= 2;
attrset(CRT_colors[METER_TEXT]);
int captionLen = 3;
@ -326,8 +322,6 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
for (int i = 0; i < nValues - 1; i++)
data->values[i] = data->values[i + 1];
Meter_updateValues(this);
double value = 0.0;
for (uint8_t i = 0; i < this->curItems; i++)
value += this->values[i];
@ -394,8 +388,6 @@ static void LEDMeterMode_draw(Meter* this, int x, int y, int w) {
#endif
LEDMeterMode_digits = LEDMeterMode_digitsAscii;
Meter_updateValues(this);
RichString_begin(out);
Meter_displayBuffer(this, &out);

View File

@ -105,6 +105,8 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi
if (*rescan) {
*oldTime = newTime;
// always update header, especially to avoid gaps in graph meters
Header_updateData(this->header);
ProcessList_scan(pl, this->state->pauseProcessUpdate);
if (!this->state->pauseProcessUpdate && (*sortTimeout == 0 || this->settings->treeView)) {
ProcessList_sort(pl);