Explicit "maxItems" property of meters

Two changes in this commit:
- All meters now explicitly specify "maxItems" property, even for just
  1 item. (Exception is "container" CPU meter classes, which use
  CUSTOM_METERMODE.)
- "maxItems" being 0 is now allowed. This will let bar meters and graph
  meters render an empty meter.
This commit is contained in:
Explorer09 2016-03-11 10:54:34 +08:00
parent 7d3f67e822
commit 99fb3070a2
9 changed files with 11 additions and 8 deletions

View File

@ -75,6 +75,7 @@ MeterClass BatteryMeter_class = {
},
.setValues = BatteryMeter_setValues,
.defaultMode = TEXT_METERMODE,
.maxItems = 1,
.total = 100.0,
.attributes = BatteryMeter_attributes,
.name = "Battery",

View File

@ -312,8 +312,8 @@ MeterClass LeftCPUs2Meter_class = {
.total = 100.0,
.attributes = CPUMeter_attributes,
.name = "LeftCPUs2",
.description = "CPUs (1&2/4): first half in 2 shorter columns",
.uiName = "CPUs (1&2/4)",
.description = "CPUs (1&2/4): first half in 2 shorter columns",
.caption = "CPU",
.draw = DualColCPUsMeter_draw,
.init = AllCPUsMeter_init,

View File

@ -34,6 +34,7 @@ MeterClass ClockMeter_class = {
},
.setValues = ClockMeter_setValues,
.defaultMode = TEXT_METERMODE,
.maxItems = 1,
.total = 1440, /* 24*60 */
.attributes = ClockMeter_attributes,
.name = "Clock",

View File

@ -31,6 +31,7 @@ MeterClass HostnameMeter_class = {
},
.setValues = HostnameMeter_setValues,
.defaultMode = TEXT_METERMODE,
.maxItems = 0,
.total = 100.0,
.attributes = HostnameMeter_attributes,
.name = "Hostname",

View File

@ -77,6 +77,7 @@ MeterClass LoadMeter_class = {
},
.setValues = LoadMeter_setValues,
.defaultMode = TEXT_METERMODE,
.maxItems = 1,
.total = 100.0,
.attributes = LoadMeter_attributes,
.name = "Load",

View File

@ -132,12 +132,8 @@ Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type) {
this->h = 1;
this->param = param;
this->pl = pl;
char maxItems = type->maxItems;
if (maxItems == 0) {
maxItems = 1;
}
type->curItems = maxItems;
this->values = xCalloc(maxItems, sizeof(double));
type->curItems = type->maxItems;
this->values = xCalloc(type->maxItems, sizeof(double));
this->total = type->total;
this->caption = xStrdup(type->caption);
if (Meter_initFn(this))
@ -550,6 +546,7 @@ MeterClass BlankMeter_class = {
},
.setValues = BlankMeter_setValues,
.defaultMode = TEXT_METERMODE,
.maxItems = 0,
.total = 100.0,
.attributes = BlankMeter_attributes,
.name = "Blank",

View File

@ -56,6 +56,7 @@ MeterClass SwapMeter_class = {
},
.setValues = SwapMeter_setValues,
.defaultMode = BAR_METERMODE,
.maxItems = 1,
.total = 100.0,
.attributes = SwapMeter_attributes,
.name = "Swap",

View File

@ -74,8 +74,8 @@ MeterClass TasksMeter_class = {
},
.setValues = TasksMeter_setValues,
.defaultMode = TEXT_METERMODE,
.total = 100.0,
.maxItems = 4,
.total = 100.0,
.attributes = TasksMeter_attributes,
.name = "Tasks",
.uiName = "Task counter",

View File

@ -51,6 +51,7 @@ MeterClass UptimeMeter_class = {
},
.setValues = UptimeMeter_setValues,
.defaultMode = TEXT_METERMODE,
.maxItems = 1,
.total = 100.0,
.attributes = UptimeMeter_attributes,
.name = "Uptime",