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 51CE21381F3 for ; Fri, 20 Sep 2013 08:30:49 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 1CD71E0B1B; Fri, 20 Sep 2013 08:30:43 +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 545A2E0B1B for ; Fri, 20 Sep 2013 08:30:42 +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 420FB33EB84 for ; Fri, 20 Sep 2013 08:30:41 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id CFA6CE5464 for ; Fri, 20 Sep 2013 08:30:38 +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: <1379486916.c1c2d4e2581a150a267a8d9851d4492bae8c4f34.yamakuzure@gentoo> Subject: [gentoo-commits] proj/ufed:master commit in: / X-VCS-Repository: proj/ufed X-VCS-Files: ufed-curses-checklist.c X-VCS-Directories: / X-VCS-Committer: yamakuzure X-VCS-Committer-Name: Sven Eden X-VCS-Revision: c1c2d4e2581a150a267a8d9851d4492bae8c4f34 X-VCS-Branch: master Date: Fri, 20 Sep 2013 08:30:38 +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: 67f46b1a-36d7-49d7-8b04-74cf6fd6c34f X-Archives-Hash: 2600ecbf7880bf5813deb059b8afe1cf commit: c1c2d4e2581a150a267a8d9851d4492bae8c4f34 Author: Sven Eden gmx net> AuthorDate: Wed Sep 18 06:48:36 2013 +0000 Commit: Sven Eden gmx de> CommitDate: Wed Sep 18 06:48:36 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/ufed.git;a=commit;h=c1c2d4e2 drawFlag(): Moved finding the starting description / wrapped line out of the function into the new static function findFlagStart() --- ufed-curses-checklist.c | 143 ++++++++++++++++++++++++++++-------------------- 1 file changed, 83 insertions(+), 60 deletions(-) diff --git a/ufed-curses-checklist.c b/ufed-curses-checklist.c index ee11b10..8425997 100644 --- a/ufed-curses-checklist.c +++ b/ufed-curses-checklist.c @@ -19,6 +19,7 @@ static char* lineBuf = NULL; static sFlag* flags = NULL; /* internal prototypes */ +static int findFlagStart(sFlag* flag, int* index, sWrap** wrap, int* line, bool* isFirstWrap); static void free_flags(void); @@ -202,71 +203,26 @@ static void free_flags(void) static int drawflag(sFlag* flag, bool highlight) { - int idx = 0; - int usedY = 0; + // Return early if there is nothing to display: + if (!isFlagLegal(flag)) + return 0; + + // Get the starting description/wrapped line of the flag + int idx = 0; // The description index to start with int line = flag->currline; - char buf[wWidth(List)+1]; - char desc[maxDescWidth]; - sWrap* wrapPart = NULL; + int usedY = 0; // Counts how many lines this flag really needs to display + sWrap* wrapPart = NULL; // Wrap part to begin with/draw bool wrapFirst = true; // The first part, pkg or desc - // Return early if there is nothing to display: - if (!isFlagLegal(flag)) + if ((line < 0) + && (0 == (usedY = findFlagStart(flag, &idx, &wrapPart, &line, &wrapFirst))) ) return 0; - /* Determine with which description to start. - * Overly long description lists might not fit on one screen, - * and therefore must be scrolled instead of the flags - * themselves. - * If descriptions are wrapped, any description must be held - * until wrapPart is either NULL, or a part on the screen is - * reached. - */ - if (line < 0) { - if (-line < getFlagHeight(flag)) { - while (line < 0) { - if (isDescLegal(flag, idx)) { - if (eWrap_normal == e_wrap) { - ++line; - ++usedY; - ++idx; - } else { - /* With wrapped descriptions there are two possible - * situations: - * a) The list of wrapped lines is shorter than the - * lines to be skipped to get this description on - * the screen. In this case the full description - * can be fast forwareded. - * b) The number of lines above the screen is less - * than the number of wrapped parts. In this case - * the first on screen part must be found. - */ - int wrapCount = flag->desc[idx].wrapCount; - wrapPart = flag->desc[idx].wrap; - if (wrapPart && wrapCount && (-line < wrapCount)) { - // Situation b) This description enters screen - while (wrapPart && (line < 0)) { - ++line; - ++usedY; - wrapPart = wrapPart->next; - if (wrapPart && !wrapPart->pos) - wrapFirst = false; - // Note: The wrap parts are already calculated - // to resemble the current order. - } - } else { - // Situation a) Fast forward - line += wrapCount; - usedY += wrapCount; - ++idx; - } - } // End of handling wrapped lines - } // End of having a legal flag - } // end of moving to line 0 - } else - // Otherwise this item is out of the display area - return 0; - } + + char buf[wWidth(List)+1]; + char desc[maxDescWidth]; + + memset(buf, 0, sizeof(char) * (wWidth(List)+1)); @@ -715,6 +671,73 @@ static int callback(sFlag** curr, int key) return -1; } +/** @brief find the first description/wrapped part drawn on line 0. + * + * Determine with which description to start. + * Overly long description lists might not fit on one screen, + * and therefore must be scrolled instead of the flags + * themselves. + * If descriptions are wrapped, any description must be held + * until wrapPart is either NULL, or a part on the screen is + * reached. +**/ +static int findFlagStart(sFlag* flag, int* index, sWrap** wrap, int* line, bool* isFirstWrap) +{ + int usedLines = 0; + int flagHeight = getFlagHeight(flag); // Will recalculate wrap parts if needed + sWrap* wrapPart = NULL; + + if ( (*line < 0) && (-(*line) < flagHeight) ){ + + while (*line < 0) { + if (isDescLegal(flag, *index)) { + if (eWrap_normal == e_wrap) { + ++(*line); + ++usedLines; + ++(*index); + } else { + /* With wrapped descriptions there are two possible + * situations: + * a) The list of wrapped lines is shorter than the + * lines to be skipped to get this description on + * the screen. In this case the full description + * can be fast forwareded. + * b) The number of lines above the screen is less + * than the number of wrapped parts. In this case + * the first on screen part must be found. + */ + int wrapCount = flag->desc[*index].wrapCount; + wrapPart = flag->desc[*index].wrap; + *isFirstWrap = true; + if (wrapPart && wrapCount && (-(*line) < wrapCount)) { + // Situation b) This description enters screen + while (wrapPart && (*line < 0)) { + ++(*line); + ++usedLines; + wrapPart = wrapPart->next; + if (wrapPart && !wrapPart->pos) + *isFirstWrap = false; + // Note: The wrap parts are already calculated + // to resemble the current order. + } + } else { + // Situation a) Fast forward + *line += wrapCount; + usedLines += wrapCount; + ++(*index); + } + } // End of handling wrapped lines + } // End of having a legal flag + } // end of moving to line 0 + + // Write back wrapPart: + *wrap = wrapPart; + } + + return usedLines; +} + + int main(void) { int result = EXIT_SUCCESS;