From e3862aa67e37ecef0eb8f82ba1f4a710ffac9c02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 16 Dec 2020 21:46:11 +0100 Subject: Rework drawing of FunctionBar Draw the FunctionBar within Panel_draw instead of manually throughout the code. Add an optional PanelClass function drawFunctionBar, to allow specific panels to override the default FunctionBar_draw call. Rework the code on color change, to really change all colors (selection markers and panel headers). Closes: #402 --- IncSet.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'IncSet.c') diff --git a/IncSet.c b/IncSet.c index 8cd850b3..af8e3aef 100644 --- a/IncSet.c +++ b/IncSet.c @@ -54,12 +54,13 @@ static inline void IncMode_done(IncMode* mode) { } IncSet* IncSet_new(FunctionBar* bar) { - IncSet* this = xCalloc(1, sizeof(IncSet)); + IncSet* this = xMalloc(sizeof(IncSet)); IncMode_initSearch(&(this->modes[INC_SEARCH])); IncMode_initFilter(&(this->modes[INC_FILTER])); this->active = NULL; - this->filtering = false; this->defaultBar = bar; + this->filtering = false; + this->found = false; return this; } @@ -99,20 +100,14 @@ static void updateWeakPanel(IncSet* this, Panel* panel, Vector* lines) { static bool search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue) { int size = Panel_size(panel); - bool found = false; for (int i = 0; i < size; i++) { if (String_contains_i(getPanelValue(panel, i), mode->buffer)) { Panel_setSelected(panel, i); - found = true; - break; + return true; } } - FunctionBar_drawExtra(mode->bar, - mode->buffer, - found ? -1 : CRT_colors[FAILED_SEARCH], - true); - return found; + return false; } static bool IncMode_find(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue, int step) { @@ -202,7 +197,6 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue } this->active = NULL; Panel_setDefaultBar(panel); - FunctionBar_draw(this->defaultBar); doSearch = false; } if (doSearch) { @@ -221,13 +215,12 @@ const char* IncSet_getListItemValue(Panel* panel, int i) { void IncSet_activate(IncSet* this, IncType type, Panel* panel) { this->active = &(this->modes[type]); - FunctionBar_drawExtra(this->active->bar, this->active->buffer, -1, true); panel->currentBar = this->active->bar; } void IncSet_drawBar(const IncSet* this) { if (this->active) { - FunctionBar_drawExtra(this->active->bar, this->active->buffer, -1, true); + FunctionBar_drawExtra(this->active->bar, this->active->buffer, (this->active->isFilter || this->found) ? -1 : CRT_colors[FAILED_SEARCH], true); } else { FunctionBar_draw(this->defaultBar); } -- cgit v1.2.3