mirror of https://github.com/xzeldon/htop.git
Panel: rework hight logic
The hight of a Panel dpends on whether the Panel has a header or not. Also the header migth not be set on Panel creation, like in the MainPanel. This currently causes the cursor to get hidden behind the FunctionBar on down-scrolling.
This commit is contained in:
parent
eb6f8d569d
commit
24c5ca9ddf
37
Panel.c
37
Panel.c
|
@ -92,10 +92,6 @@ void Panel_move(Panel* this, int x, int y) {
|
||||||
void Panel_resize(Panel* this, int w, int h) {
|
void Panel_resize(Panel* this, int w, int h) {
|
||||||
assert (this != NULL);
|
assert (this != NULL);
|
||||||
|
|
||||||
if (RichString_sizeVal(this->header) > 0) {
|
|
||||||
h--;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->w = w;
|
this->w = w;
|
||||||
this->h = h;
|
this->h = h;
|
||||||
this->needsRedraw = true;
|
this->needsRedraw = true;
|
||||||
|
@ -240,6 +236,7 @@ void Panel_draw(Panel* this, bool force_redraw, bool focus, bool highlightSelect
|
||||||
}
|
}
|
||||||
attrset(CRT_colors[RESET_COLOR]);
|
attrset(CRT_colors[RESET_COLOR]);
|
||||||
y++;
|
y++;
|
||||||
|
h--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure scroll area is on screen
|
// ensure scroll area is on screen
|
||||||
|
@ -333,13 +330,21 @@ void Panel_draw(Panel* this, bool force_redraw, bool focus, bool highlightSelect
|
||||||
move(0, 0);
|
move(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int Panel_headerHeight(const Panel* this) {
|
||||||
|
return RichString_sizeVal(this->header) > 0 ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool Panel_onKey(Panel* this, int key) {
|
bool Panel_onKey(Panel* this, int key) {
|
||||||
assert (this != NULL);
|
assert (this != NULL);
|
||||||
|
|
||||||
int size = Vector_size(this->items);
|
const int size = Vector_size(this->items);
|
||||||
|
|
||||||
#define CLAMP_INDEX(var, delta, min, max) \
|
#define PANEL_SCROLL(amount) \
|
||||||
CLAMP((var) + (delta), (min), MAXIMUM(0, (max)))
|
do { \
|
||||||
|
this->selected += (amount); \
|
||||||
|
this->scrollV = CLAMP(this->scrollV + (amount), 0, MAXIMUM(0, (size - this->h - Panel_headerHeight(this)))); \
|
||||||
|
this->needsRedraw = true; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case KEY_DOWN:
|
case KEY_DOWN:
|
||||||
|
@ -373,27 +378,19 @@ bool Panel_onKey(Panel* this, int key) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KEY_PPAGE:
|
case KEY_PPAGE:
|
||||||
this->selected -= (this->h - 1);
|
PANEL_SCROLL(-(this->h - Panel_headerHeight(this)));
|
||||||
this->scrollV = CLAMP_INDEX(this->scrollV, -(this->h - 1), 0, size - this->h);
|
|
||||||
this->needsRedraw = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KEY_NPAGE:
|
case KEY_NPAGE:
|
||||||
this->selected += (this->h - 1);
|
PANEL_SCROLL(+(this->h - Panel_headerHeight(this)));
|
||||||
this->scrollV = CLAMP_INDEX(this->scrollV, +(this->h - 1), 0, size - this->h);
|
|
||||||
this->needsRedraw = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KEY_WHEELUP:
|
case KEY_WHEELUP:
|
||||||
this->selected -= CRT_scrollWheelVAmount;
|
PANEL_SCROLL(-CRT_scrollWheelVAmount);
|
||||||
this->scrollV = CLAMP_INDEX(this->scrollV, -CRT_scrollWheelVAmount, 0, size - this->h);
|
|
||||||
this->needsRedraw = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KEY_WHEELDOWN:
|
case KEY_WHEELDOWN:
|
||||||
this->selected += CRT_scrollWheelVAmount;
|
PANEL_SCROLL(+CRT_scrollWheelVAmount);
|
||||||
this->scrollV = CLAMP_INDEX(this->scrollV, +CRT_scrollWheelVAmount, 0, size - this->h);
|
|
||||||
this->needsRedraw = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KEY_HOME:
|
case KEY_HOME:
|
||||||
|
@ -418,7 +415,7 @@ bool Panel_onKey(Panel* this, int key) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef CLAMP_INDEX
|
#undef PANEL_SCROLL
|
||||||
|
|
||||||
// ensure selection within bounds
|
// ensure selection within bounds
|
||||||
if (this->selected < 0 || size == 0) {
|
if (this->selected < 0 || size == 0) {
|
||||||
|
|
|
@ -124,7 +124,7 @@ static void ScreenManager_drawPanels(ScreenManager* this, int focus, bool force_
|
||||||
for (int i = 0; i < nPanels; i++) {
|
for (int i = 0; i < nPanels; i++) {
|
||||||
Panel* panel = (Panel*) Vector_get(this->panels, i);
|
Panel* panel = (Panel*) Vector_get(this->panels, i);
|
||||||
Panel_draw(panel, force_redraw, i == focus, !((panel == this->state->panel) && this->state->hideProcessSelection));
|
Panel_draw(panel, force_redraw, i == focus, !((panel == this->state->panel) && this->state->hideProcessSelection));
|
||||||
mvvline(panel->y, panel->x + panel->w, ' ', panel->h + 1);
|
mvvline(panel->y, panel->x + panel->w, ' ', panel->h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue