From 24c5ca9ddfbe088a3d25694cbe170eaf3d7f828f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 1 Jan 2021 22:06:26 +0100 Subject: 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. --- Panel.c | 37 +++++++++++++++++-------------------- ScreenManager.c | 2 +- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/Panel.c b/Panel.c index 26a0c0ec..d59f3d6b 100644 --- a/Panel.c +++ b/Panel.c @@ -92,10 +92,6 @@ void Panel_move(Panel* this, int x, int y) { void Panel_resize(Panel* this, int w, int h) { assert (this != NULL); - if (RichString_sizeVal(this->header) > 0) { - h--; - } - this->w = w; this->h = h; this->needsRedraw = true; @@ -240,6 +236,7 @@ void Panel_draw(Panel* this, bool force_redraw, bool focus, bool highlightSelect } attrset(CRT_colors[RESET_COLOR]); y++; + h--; } // 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); } +static int Panel_headerHeight(const Panel* this) { + return RichString_sizeVal(this->header) > 0 ? 1 : 0; +} + bool Panel_onKey(Panel* this, int key) { assert (this != NULL); - int size = Vector_size(this->items); + const int size = Vector_size(this->items); - #define CLAMP_INDEX(var, delta, min, max) \ - CLAMP((var) + (delta), (min), MAXIMUM(0, (max))) + #define PANEL_SCROLL(amount) \ + 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) { case KEY_DOWN: @@ -373,27 +378,19 @@ bool Panel_onKey(Panel* this, int key) { break; case KEY_PPAGE: - this->selected -= (this->h - 1); - this->scrollV = CLAMP_INDEX(this->scrollV, -(this->h - 1), 0, size - this->h); - this->needsRedraw = true; + PANEL_SCROLL(-(this->h - Panel_headerHeight(this))); break; case KEY_NPAGE: - this->selected += (this->h - 1); - this->scrollV = CLAMP_INDEX(this->scrollV, +(this->h - 1), 0, size - this->h); - this->needsRedraw = true; + PANEL_SCROLL(+(this->h - Panel_headerHeight(this))); break; case KEY_WHEELUP: - this->selected -= CRT_scrollWheelVAmount; - this->scrollV = CLAMP_INDEX(this->scrollV, -CRT_scrollWheelVAmount, 0, size - this->h); - this->needsRedraw = true; + PANEL_SCROLL(-CRT_scrollWheelVAmount); break; case KEY_WHEELDOWN: - this->selected += CRT_scrollWheelVAmount; - this->scrollV = CLAMP_INDEX(this->scrollV, +CRT_scrollWheelVAmount, 0, size - this->h); - this->needsRedraw = true; + PANEL_SCROLL(+CRT_scrollWheelVAmount); break; case KEY_HOME: @@ -418,7 +415,7 @@ bool Panel_onKey(Panel* this, int key) { return false; } - #undef CLAMP_INDEX + #undef PANEL_SCROLL // ensure selection within bounds if (this->selected < 0 || size == 0) { diff --git a/ScreenManager.c b/ScreenManager.c index 4c74e477..6b7ddc9b 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -124,7 +124,7 @@ static void ScreenManager_drawPanels(ScreenManager* this, int focus, bool force_ for (int i = 0; i < nPanels; i++) { Panel* panel = (Panel*) Vector_get(this->panels, i); 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); } } -- cgit v1.2.3