From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 250061387C2 for ; Fri, 1 Feb 2013 10:50:11 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 4BC0E21C055; Fri, 1 Feb 2013 10:50:00 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 9B4C621C056 for ; Fri, 1 Feb 2013 10:49:54 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 6A30133DCAC for ; Fri, 1 Feb 2013 10:49:53 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 4F2A0E4073 for ; Fri, 1 Feb 2013 10:49:50 +0000 (UTC) From: "Sven Eden" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sven Eden" Message-ID: <1359713705.f44fc180351f67a460acf1d46b03124660da1c9a.yamakuzure@gentoo> Subject: [gentoo-commits] proj/ufed:master commit in: / X-VCS-Repository: proj/ufed X-VCS-Files: ufed-curses.c X-VCS-Directories: / X-VCS-Committer: yamakuzure X-VCS-Committer-Name: Sven Eden X-VCS-Revision: f44fc180351f67a460acf1d46b03124660da1c9a X-VCS-Branch: master Date: Fri, 1 Feb 2013 10:49:50 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: bdef2eb6-ac58-4107-b02d-6d87fda1afd0 X-Archives-Hash: cc753f59e3322218d360a27f904975e2 commit: f44fc180351f67a460acf1d46b03124660da1c9a Author: Sven Eden gmx de> AuthorDate: Fri Feb 1 10:15:05 2013 +0000 Commit: Sven Eden gmx de> CommitDate: Fri Feb 1 10:15:05 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/ufed.git;a=commit;h=f44fc180 Fixed setPrevItem(), setNextItem() and drawFlags() to handle the skipping of individual filtered out description lines. Note: this surely can be optimized. Later. --- ufed-curses.c | 176 ++++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 123 insertions(+), 53 deletions(-) diff --git a/ufed-curses.c b/ufed-curses.c index bc55ca1..2808055 100644 --- a/ufed-curses.c +++ b/ufed-curses.c @@ -42,8 +42,8 @@ void draw(bool withSep); void drawScrollbar(void); int getListHeight(void); void resetDisplay(bool withSep); -void setNextItem(int count, bool strict); -void setPrevItem(int count, bool strict); +bool setNextItem(int count, bool strict); +bool setPrevItem(int count, bool strict); /* internal functions */ @@ -197,25 +197,28 @@ void drawFlags() { topline, currentflag->listline) sFlag* flag = currentflag; + sFlag* last = currentflag; int line = flag->listline - topline; /* move to the top of the displayed list */ while ((flag != flags) && (line > 0)) { flag = flag->prev; - if (isFlagLegal(flag)) + if (isFlagLegal(flag)) { line -= getFlagHeight(flag); + last = flag; + } } /* If the above move ended up with flag == flags - * topline and line must be adapted to the current - * flag. + * topline and line must be adapted to the last + * found not filtered flag. * This can happen if the flag filter is toggled * and the current flag is the first not filtered. */ if ((flag == flags) && !isFlagLegal(flag)) { - flag = currentflag; - topline = currentflag->listline; + flag = last; + topline = last->listline; line = 0; } @@ -408,10 +411,14 @@ void draw(bool withSep) { } bool scrollcurrent() { - if(currentflag->listline < topline) - topline = max(currentflag->listline, currentflag->listline + currentflag->ndesc - wHeight(List)); - else if( (currentflag->listline + currentflag->ndesc) > (topline + wHeight(List))) - topline = min(currentflag->listline + currentflag->ndesc - wHeight(List), currentflag->listline); + int lsLine = currentflag->listline; + int flHeight = getFlagHeight(currentflag); + int btLine = lsLine + flHeight; + int wdHeight = wHeight(List); + if(lsLine < topline) + topline = max(lsLine, btLine - wdHeight); + else if( btLine > (topline + wdHeight)) + topline = min(btLine - wdHeight, lsLine); else return false; drawFlags(); @@ -777,77 +784,140 @@ void resetDisplay(bool withSep) /** @brief set currentflag to the next flag @a count lines away * @param count set how many lines should be skipped * @param strict if set to false, at least one item has to be skipped. + * @return true if currentflag was changed, flase otherwise */ -void setNextItem(int count, bool strict) +bool setNextItem(int count, bool strict) { - bool result = true; - sFlag* curr = currentflag; - int skipped = 0; - int oldTop = topline; + bool result = true; + sFlag* curr = currentflag; + sFlag* lastFlag = NULL; + int lastTop = 0; + int skipped = 0; + int oldTop = topline; + int fHeight = 0; + + // It is crucial to start with a not filtered flag: + while (!isFlagLegal(curr) && (curr->next != flags)) { + topline += curr->ndesc; + curr = curr->next; + } + + // Break this if the current item is still filtered + if (!isFlagLegal(curr)) { + topline = oldTop; + return false; + } while (result && (skipped < count)) { - if (curr->next == flags) - result = false; // The list is finished, no next item to display - else - curr = curr->next; - - // curr is only counted if it is not filtered out: - if (isFlagLegal(curr)) - skipped += getFlagHeight(curr); - else - // Otherwise topline must be adapted or scrollcurrent() wreaks havoc! + lastFlag = curr; + lastTop = topline; + fHeight = getFlagHeight(curr); + skipped += fHeight; + topline += curr->ndesc - fHeight; + curr = curr->next; + + // Ensure a not filtered flag to continue + while (!isFlagLegal(curr) && (curr->next != flags)) { topline += curr->ndesc; + curr = curr->next; + } + + // It is possible to end up with the last flag + // which might be filtered: + if (curr->next == flags) { + if (!isFlagLegal(curr)) { + // Revert to last known legal state: + curr = lastFlag; + topline = lastTop; + skipped -= getFlagHeight(curr); + } + // Did we fail ? + if (skipped < count) + result = false; + } } // End of trying to find a next item if ( (result && strict) || (!strict && skipped) ) { - // Move back again if curr ended up being filtered - while (!isFlagLegal(curr)) { - topline -= curr->ndesc; - curr = curr->prev; - } drawflag(currentflag, FALSE); currentflag = curr; if (!scrollcurrent()) drawflag(currentflag, TRUE); - } else + result = true; + } else { topline = oldTop; + result = false; + } + + return result; } /* @brief set currentflag to the previous item @a count lines away * @param count set how many lines should be skipped * @param strict if set to false, at least one item has to be skipped. + * @return true if currentflag was changed, flase otherwise */ -void setPrevItem(int count, bool strict) +bool setPrevItem(int count, bool strict) { - bool result = true; - sFlag* curr = currentflag; - int skipped = 0; - int oldTop = topline; + bool result = true; + sFlag* curr = currentflag; + sFlag* lastFlag = NULL; + int lastTop = 0; + int skipped = 0; + int oldTop = topline; + int fHeight = 0; + + // It is crucial to start with a not filtered flag: + while (!isFlagLegal(curr) && (curr != flags)) { + topline -= curr->ndesc; + curr = curr->prev; + } + // Break this if the current item is still filtered + if (!isFlagLegal(curr)) { + topline = oldTop; + return false; + } while (result && (skipped < count)) { - if (curr == flags) - result = false; // The list is finished, no previous item to display - else - curr = curr->prev; - - // curr is only counted if it is not filtered out: - if (isFlagLegal(curr)) - skipped += getFlagHeight(curr); - else + lastFlag = curr; + lastTop = topline; + curr = curr->prev; + + // Ensure a not filtered flag to continue + while (!isFlagLegal(curr) && (curr != flags)) { topline -= curr->ndesc; - } // End of trying to find next item + curr = curr->prev; + } - if ( (result && strict) || (!strict && skipped) ) { - // Move forth again if curr ended up being filtered - while (!isFlagLegal(curr)) { - topline += curr->ndesc; - curr = curr->next; + fHeight = getFlagHeight(curr); + skipped += fHeight; + topline -= curr->ndesc - fHeight; + + // It is possible to end up with the first flag + // which might be filtered: + if (curr == flags) { + if (!isFlagLegal(curr)) { + // Revert to last known legal state: + skipped -= getFlagHeight(curr); + curr = lastFlag; + topline = lastTop; + } + // Did we fail ? + if (skipped < count) + result = false; } + } // End of trying to find a next item + + if ( (result && strict) || (!strict && skipped) ) { drawflag(currentflag, FALSE); currentflag = curr; if (!scrollcurrent()) drawflag(currentflag, TRUE); - } else + result = true; + } else { topline = oldTop; + result = false; + } + + return result; }