From b9e69223d02287f75c24c3f5be869a04979e5b17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sat, 21 Aug 2021 20:42:04 +0200 Subject: ScreenManager: reduce ScreenManager_resize The main change is the header hight being not included in y1. This is important if a sub-manager gets resized, e.g. a resize while editing the Settings or in a pickFromVector selection, and afterwards, then the sub-manager is closed, the super-ScreenManager gets resized, it uses the correct header hight. The header hight might have been changed since the last resize of the super-manager in the Settings by adding/removing some meters. This fixes new meters being hidden after added at runtime after a resize in the main window. --- AvailableMetersPanel.c | 2 +- DisplayOptionsPanel.c | 2 +- MetersPanel.c | 2 +- ScreenManager.c | 23 ++++++++++------------- ScreenManager.h | 2 +- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/AvailableMetersPanel.c b/AvailableMetersPanel.c index 55a45d15..a8af8d0a 100644 --- a/AvailableMetersPanel.c +++ b/AvailableMetersPanel.c @@ -81,7 +81,7 @@ static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) { Header_calculateHeight(header); Header_updateData(header); Header_draw(header); - ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2); + ScreenManager_resize(this->scr); } return result; } diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index 23b16bb2..7e05ae07 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -74,7 +74,7 @@ static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) { Header_reinit(header); Header_updateData(header); Header_draw(header); - ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2); + ScreenManager_resize(this->scr); } return result; } diff --git a/MetersPanel.c b/MetersPanel.c index d0ad9389..ccf8d0ed 100644 --- a/MetersPanel.c +++ b/MetersPanel.c @@ -186,7 +186,7 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) { this->settings->changed = true; Header_calculateHeight(header); Header_draw(header); - ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2); + ScreenManager_resize(this->scr); } return result; } diff --git a/ScreenManager.c b/ScreenManager.c index 5a985d4d..d403e24c 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -27,7 +27,7 @@ ScreenManager* ScreenManager_new(Header* header, const Settings* settings, const ScreenManager* this; this = xMalloc(sizeof(ScreenManager)); this->x1 = 0; - this->y1 = header->height; + this->y1 = 0; this->x2 = 0; this->y2 = -1; this->panels = Vector_new(Class(Panel), owner, DEFAULT_SIZE); @@ -54,13 +54,13 @@ void ScreenManager_add(ScreenManager* this, Panel* item, int size) { const Panel* last = (const Panel*) Vector_get(this->panels, this->panelCount - 1); lastX = last->x + last->w + 1; } - int height = LINES - this->y1 + this->y2; + int height = LINES - this->y1 - (this->header ? this->header->height : 0) + this->y2; if (size > 0) { Panel_resize(item, size, height); } else { Panel_resize(item, COLS - this->x1 + this->x2 - lastX, height); } - Panel_move(item, lastX, this->y1); + Panel_move(item, lastX, this->y1 + (this->header ? this->header->height : 0)); Vector_add(this->panels, item); item->needsRedraw = true; this->panelCount++; @@ -73,22 +73,19 @@ Panel* ScreenManager_remove(ScreenManager* this, int idx) { return panel; } -void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) { - this->x1 = x1; - this->y1 = y1; - this->x2 = x2; - this->y2 = y2; +void ScreenManager_resize(ScreenManager* this) { + int y1_header = this->y1 + (this->header ? this->header->height : 0); int panels = this->panelCount; int lastX = 0; for (int i = 0; i < panels - 1; i++) { Panel* panel = (Panel*) Vector_get(this->panels, i); - Panel_resize(panel, panel->w, LINES - y1 + y2); - Panel_move(panel, lastX, y1); + Panel_resize(panel, panel->w, LINES - y1_header + this->y2); + Panel_move(panel, lastX, y1_header); lastX = panel->x + panel->w + 1; } Panel* panel = (Panel*) Vector_get(this->panels, panels - 1); - Panel_resize(panel, COLS - x1 + x2 - lastX, LINES - y1 + y2); - Panel_move(panel, lastX, y1); + Panel_resize(panel, COLS - this->x1 + this->x2 - lastX, LINES - y1_header + this->y2); + Panel_move(panel, lastX, y1_header); } static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTimeout, bool* redraw, bool* rescan, bool* timedOut) { @@ -260,7 +257,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { switch (ch) { case KEY_RESIZE: { - ScreenManager_resize(this, this->x1, this->y1, this->x2, this->y2); + ScreenManager_resize(this); continue; } case KEY_LEFT: diff --git a/ScreenManager.h b/ScreenManager.h index 59d30bd6..bf55f17d 100644 --- a/ScreenManager.h +++ b/ScreenManager.h @@ -39,7 +39,7 @@ void ScreenManager_add(ScreenManager* this, Panel* item, int size); Panel* ScreenManager_remove(ScreenManager* this, int idx); -void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2); +void ScreenManager_resize(ScreenManager* this); void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey); -- cgit v1.2.3