mirror of https://github.com/xzeldon/htop.git
Allow meters in text mode to span empty neighbors to the right
Closes: #484
This commit is contained in:
parent
6f6e0ec571
commit
2ec44098f9
48
Header.c
48
Header.c
|
@ -150,35 +150,71 @@ void Header_reinit(Header* this) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Header_draw(const Header* this) {
|
void Header_draw(const Header* this) {
|
||||||
int height = this->height;
|
const int height = this->height;
|
||||||
int pad = this->pad;
|
const int pad = this->pad;
|
||||||
attrset(CRT_colors[RESET_COLOR]);
|
attrset(CRT_colors[RESET_COLOR]);
|
||||||
for (int y = 0; y < height; y++) {
|
for (int y = 0; y < height; y++) {
|
||||||
mvhline(y, 0, ' ', COLS);
|
mvhline(y, 0, ' ', COLS);
|
||||||
}
|
}
|
||||||
int width = COLS / this->nrColumns - (pad * this->nrColumns - 1) - 1;
|
const int width = COLS / this->nrColumns - (pad * this->nrColumns - 1) - 1;
|
||||||
int x = pad;
|
int x = pad;
|
||||||
|
|
||||||
Header_forEachColumn(this, col) {
|
Header_forEachColumn(this, col) {
|
||||||
Vector* meters = this->columns[col];
|
Vector* meters = this->columns[col];
|
||||||
for (int y = (pad / 2), i = 0; i < Vector_size(meters); i++) {
|
for (int y = (pad / 2), i = 0; i < Vector_size(meters); i++) {
|
||||||
Meter* meter = (Meter*) Vector_get(meters, i);
|
Meter* meter = (Meter*) Vector_get(meters, i);
|
||||||
meter->draw(meter, x, y, width);
|
|
||||||
|
int actualWidth;
|
||||||
|
if (meter->mode == TEXT_METERMODE)
|
||||||
|
actualWidth = meter->columnWidthCount * width + (meter->columnWidthCount - 1) * (2 * pad + 1);
|
||||||
|
else
|
||||||
|
actualWidth = width;
|
||||||
|
|
||||||
|
meter->draw(meter, x, y, actualWidth);
|
||||||
y += meter->h;
|
y += meter->h;
|
||||||
}
|
}
|
||||||
x += width + pad;
|
x += width + pad;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* Returns the number of columns to span, i.e. if the direct neighbor is occupied 1.
|
||||||
|
*/
|
||||||
|
static int calcColumnWidthCount(const Header* this, const Meter* curMeter, const int pad, const int curColumn, const int curHeight) {
|
||||||
|
for (int i = curColumn + 1; i < this->nrColumns; i++) {
|
||||||
|
const Vector* meters = this->columns[i];
|
||||||
|
|
||||||
|
int height = pad;
|
||||||
|
for (int j = 0; j < Vector_size(meters); j++) {
|
||||||
|
const Meter* meter = (const Meter*) Vector_get(meters, j);
|
||||||
|
|
||||||
|
if (height >= curHeight + curMeter->h)
|
||||||
|
break;
|
||||||
|
|
||||||
|
height += meter->h;
|
||||||
|
if (height <= curHeight)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!Object_isA((const Object*) meter, (const ObjectClass*) &BlankMeter_class))
|
||||||
|
return i - curColumn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this->nrColumns - curColumn;
|
||||||
|
}
|
||||||
|
|
||||||
int Header_calculateHeight(Header* this) {
|
int Header_calculateHeight(Header* this) {
|
||||||
int pad = this->settings->headerMargin ? 2 : 0;
|
const int pad = this->settings->headerMargin ? 2 : 0;
|
||||||
int maxHeight = pad;
|
int maxHeight = pad;
|
||||||
|
|
||||||
Header_forEachColumn(this, col) {
|
Header_forEachColumn(this, col) {
|
||||||
const Vector* meters = this->columns[col];
|
const Vector* meters = this->columns[col];
|
||||||
int height = pad;
|
int height = pad;
|
||||||
for (int i = 0; i < Vector_size(meters); i++) {
|
for (int i = 0; i < Vector_size(meters); i++) {
|
||||||
const Meter* meter = (const Meter*) Vector_get(meters, i);
|
Meter* meter = (Meter*) Vector_get(meters, i);
|
||||||
|
meter->columnWidthCount = calcColumnWidthCount(this, meter, pad, col, height);
|
||||||
height += meter->h;
|
height += meter->h;
|
||||||
}
|
}
|
||||||
maxHeight = MAXIMUM(maxHeight, height);
|
maxHeight = MAXIMUM(maxHeight, height);
|
||||||
|
|
1
Meter.h
1
Meter.h
|
@ -98,6 +98,7 @@ struct Meter_ {
|
||||||
int param;
|
int param;
|
||||||
GraphData* drawData;
|
GraphData* drawData;
|
||||||
int h;
|
int h;
|
||||||
|
int columnWidthCount; /*<< only used internally by the Header */
|
||||||
const ProcessList* pl;
|
const ProcessList* pl;
|
||||||
uint8_t curItems;
|
uint8_t curItems;
|
||||||
const int* curAttributes;
|
const int* curAttributes;
|
||||||
|
|
4
Object.c
4
Object.c
|
@ -15,8 +15,6 @@ const ObjectClass Object_class = {
|
||||||
.extends = NULL
|
.extends = NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef NDEBUG
|
|
||||||
|
|
||||||
bool Object_isA(const Object* o, const ObjectClass* klass) {
|
bool Object_isA(const Object* o, const ObjectClass* klass) {
|
||||||
if (!o)
|
if (!o)
|
||||||
return false;
|
return false;
|
||||||
|
@ -29,5 +27,3 @@ bool Object_isA(const Object* o, const ObjectClass* klass) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* NDEBUG */
|
|
||||||
|
|
4
Object.h
4
Object.h
|
@ -57,10 +57,6 @@ typedef union {
|
||||||
|
|
||||||
extern const ObjectClass Object_class;
|
extern const ObjectClass Object_class;
|
||||||
|
|
||||||
#ifndef NDEBUG
|
|
||||||
|
|
||||||
bool Object_isA(const Object* o, const ObjectClass* klass);
|
bool Object_isA(const Object* o, const ObjectClass* klass);
|
||||||
|
|
||||||
#endif /* NDEBUG */
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue