public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Sven Eden" <sven.eden@gmx.de>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/ufed:master commit in: /
Date: Wed, 23 Jan 2013 12:05:27 +0000 (UTC)	[thread overview]
Message-ID: <1358803405.ffa22db238235c70dc4c7cd12434ec78d39ed01e.yamakuzure@gentoo> (raw)

commit:     ffa22db238235c70dc4c7cd12434ec78d39ed01e
Author:     Sven Eden <sven.eden <AT> gmx <DOT> de>
AuthorDate: Mon Jan 21 21:23:25 2013 +0000
Commit:     Sven Eden <sven.eden <AT> gmx <DOT> de>
CommitDate: Mon Jan 21 21:23:25 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/ufed.git;a=commit;h=ffa22db2

Rewrote the core displaying routines to use the static list of lines
for the general organization, but determine the real display line
number of each displayed flag in a flexible way.
Variable line counts of flags with multiple descriptions are not
scrolling correctly, yet. This has to be fixed.
Once fully functional, the new drawing allows a much easier filtering
of the displayed flags. It will no longer be neccessary to have the
masked flags being at the front of the list.

---
 ufed-curses-checklist.c |   97 +++++++++++++-------
 ufed-curses-help.c      |   10 +-
 ufed-curses.c           |  229 ++++++++++++++++++++++++++++-------------------
 ufed-curses.h           |    5 +-
 4 files changed, 207 insertions(+), 134 deletions(-)

diff --git a/ufed-curses-checklist.c b/ufed-curses-checklist.c
index 11de724..ae2a3e3 100644
--- a/ufed-curses-checklist.c
+++ b/ufed-curses-checklist.c
@@ -55,8 +55,13 @@ static void free_flags(void);
 enum mask  showMasked = show_unmasked; //!< Set whether to show masked, unmasked or both flags
 enum order pkgOrder   = pkgs_left;     //!< Set whether to display package lists left or right of the description
 enum scope showScope  = show_all;      //!< Set whether global, local or all flags are shown
-int firstNormalY      = -1;            //!< y of first not masked flag
-extern int topy, minwidth;
+int lineCountGlobal;
+int lineCountLocal;
+int lineCountLocalInstalled;
+int lineCountMasked;
+int lineCountMaskedInstalled;
+int lineCountMasked;
+extern int minwidth;
 
 /* static functions */
 static char *getline(FILE *fp) {
@@ -99,14 +104,22 @@ static char *getline(FILE *fp) {
 }
 
 static void read_flags(void) {
-	FILE *input = fdopen(3, "r");
-	int   y     = 0;
-	char *line  = NULL;
+	FILE *input   = fdopen(3, "r");
+	int   lineNum = 0;
+	char *line    = NULL;
 
 	if(input == NULL)
 		ERROR_EXIT(-1, "fdopen failed with error %d\n", errno);
 	atexit(&free_flags);
 
+	// Initialize line count per type:
+	lineCountGlobal          = 0;
+	lineCountLocal           = 0;
+	lineCountLocalInstalled  = 0;
+	lineCountMasked          = 0;
+	lineCountMaskedInstalled = 0;
+	lineCountMasked          = 0;
+
 	for(;;) {
 		struct {
 			int start, end;
@@ -144,7 +157,8 @@ static void read_flags(void) {
 			ERROR_EXIT(-1, "Can not allocate %lu bytes for descr array\n", ndescr * sizeof(char*));
 
 		/* note position and name of the flag */
-		flag->item.top = y;
+		flag->item.listline = lineNum;
+		flag->item.currline = 0;
 
 		if(name.end - name.start + 11 > minwidth)
 			minwidth = name.end - name.start + 11;
@@ -167,7 +181,7 @@ static void read_flags(void) {
 		strncpy(flag->state, &line[state.start], 4);
 
 		/* check and set flag item height */
-		flag->item.height = ndescr;
+		flag->item.ndescr = ndescr;
 
 		/* read description(s) and determine flag status */
 		flag->item.isMasked    = false;
@@ -196,16 +210,26 @@ static void read_flags(void) {
 
 			// Set general state of the flag
 			flag->isInstalled[i] = false;
-			if ('g' == descState)
+			if ('g' == descState) {
 				flag->item.isGlobal  = true;
-			else if ('L' == descState)
+				++lineCountGlobal;
+			}
+			else if ('l' == descState) {
+				++lineCountLocal;
+			}
+			else if ('L' == descState) {
 				flag->isInstalled[i] = true;
+				++lineCountLocalInstalled;
+			}
 			else if ('M' == descState) {
 				flag->item.isMasked  = true;
 				flag->isInstalled[i] = true;
+				++lineCountMaskedInstalled;
 			}
-			else if ('m' == descState)
+			else if ('m' == descState) {
 				flag->item.isMasked = true;
+				++lineCountMasked;
+			}
 
 			// Save packages
 			if (pkgs.start > -1) {
@@ -231,13 +255,10 @@ static void read_flags(void) {
 			size_t fullWidth = 1 + strlen(flag->descr[i]) + (flag->pkgs[i] ? strlen(flag->pkgs[i] + 3) : 0);
 			if (fullWidth > maxDescWidth)
 				maxDescWidth = fullWidth;
-		} // loop through description lines
 
-		/* record first not masked y if not done, yet */
-		if (firstNormalY < 0 && !flag->item.isMasked)
-			firstNormalY = flag->item.top;
-
-		y += ndescr;
+			// Advance lineNum
+			++lineNum;
+		} // loop through description lines
 
 		/* Save flag in our linked list */
 		if(flags==NULL) {
@@ -266,7 +287,7 @@ static void free_flags(void) {
 		flag->item.prev->next = NULL;
 		do {
 			void *p = flag;
-			for (int i = 0; i < flag->item.height; ++i) {
+			for (int i = 0; i < flag->item.ndescr; ++i) {
 				if (flag->pkgs[i])  free(flag->pkgs[i]);
 				if (flag->descr[i]) free(flag->descr[i]);
 			}
@@ -290,12 +311,12 @@ static int drawflag(struct item *item, bool highlight) {
 	struct flag *flag = (struct flag *) item;
 	char buf[wWidth(List)+1];
 	char desc[maxDescWidth];
-	int y = flag->item.top - topy;
-	int idx = 0;
+	int idx   = 0;
 	int usedY = 0;
+	int line  = flag->item.currline;
 
 	// Return early if there is nothing to display:
-	if (!isLegalItem(item))
+	if (!isLegalItem(&flag->item))
 		return 0;
 
 	/* Determine with which description to start.
@@ -303,11 +324,16 @@ static int drawflag(struct item *item, bool highlight) {
 	 * and therefore must be scrolled instead of the flags
 	 * themselves.
 	 */
-	if(y < 0 && (-y < flag->item.height)) {
-		idx = -y;
-		y   = 0;
+	if (line < 0) {
+		if (-line < getItemHeight(&flag->item)) {
+			idx  = -line;
+			line = 0;
+		} else
+			// Otherwise this item is out of the display area
+			return 0;
 	}
-	wmove(win(List), y, 0);
+
+	wmove(win(List), line, 0);
 
 	/* print the selection, name and state of the flag */
 	sprintf(buf, " %c%c%c %s%s%s%-*s %-4.4s ",
@@ -328,7 +354,7 @@ static int drawflag(struct item *item, bool highlight) {
 	/* print descriptions according to filters
 	 * TODO: Implement installed/all filters
 	 */
-	if(idx < flag->item.height) {
+	if(idx < flag->item.ndescr) {
 		for(;;) {
 			// Filter global description if it is not wanted:
 			if (!idx && (show_local == showScope) && flag->item.isGlobal) {
@@ -374,10 +400,10 @@ static int drawflag(struct item *item, bool highlight) {
 
 			// Finally put the line on the screen
 			waddstr(win(List), buf);
-			y++;
-			idx++;
-			usedY++;
-			if((idx < flag->item.height) && (y < wHeight(List)) ) {
+			++line;
+			++idx;
+			++usedY;
+			if((idx < flag->item.ndescr) && (line < wHeight(List)) ) {
 				char *p;
 				for(p = buf; p != buf + minwidth; p++)
 					*p = ' ';
@@ -391,7 +417,7 @@ static int drawflag(struct item *item, bool highlight) {
 		waddstr(win(List), buf);
 	}
 	if(highlight)
-		wmove(win(List), max(flag->item.top - topy, 0), 2);
+		wmove(win(List), max(flag->item.currline, 0), 2);
 	wnoutrefresh(win(List));
 	return usedY;
 }
@@ -472,7 +498,7 @@ static int callback(struct item **currentitem, int key) {
 			mvwaddstr(win(Input), 0, 0, fayt);
 			whline(win(Input), ' ', 2);
 			if(n==0) {
-				wmove(win(List), (*currentitem)->top-topy, 2);
+				wmove(win(List), (*currentitem)->currline, 2);
 				wnoutrefresh(win(Input));
 				wrefresh(win(List));
 			} else {
@@ -508,7 +534,7 @@ static int callback(struct item **currentitem, int key) {
 		}
 		if (*currentitem != &flags->item) {
 			drawflag(*currentitem, TRUE);
-			wmove(win(List), (*currentitem)->top-topy, 2);
+			wmove(win(List), (*currentitem)->currline, 2);
 			wrefresh(win(List));
 		} else {
 			drawitems();
@@ -519,13 +545,13 @@ static int callback(struct item **currentitem, int key) {
 		if(descriptionleft>0)
 			descriptionleft--;
 		drawflag(*currentitem, TRUE);
-		wmove(win(List), (*currentitem)->top-topy, 2);
+		wmove(win(List), (*currentitem)->currline, 2);
 		wrefresh(win(List));
 		break;
 	case KEY_RIGHT:
 		descriptionleft++;
 		drawflag(*currentitem, TRUE);
-		wmove(win(List), (*currentitem)->top-topy, 2);
+		wmove(win(List), (*currentitem)->currline, 2);
 		wrefresh(win(List));
 		break;
 #ifdef NCURSES_MOUSE_VERSION
@@ -547,7 +573,7 @@ static int callback(struct item **currentitem, int key) {
 		}
 		if (*currentitem != &flags->item) {
 			drawflag(*currentitem, TRUE);
-			wmove(win(List), (*currentitem)->top-topy, 2);
+			wmove(win(List), (*currentitem)->currline, 2);
 			wrefresh(win(List));
 		} else {
 			drawitems();
@@ -600,3 +626,4 @@ int main(void) {
 
 	return result;
 }
+

diff --git a/ufed-curses-help.c b/ufed-curses-help.c
index fff79f5..5a12712 100644
--- a/ufed-curses-help.c
+++ b/ufed-curses-help.c
@@ -11,7 +11,7 @@
 #include <strings.h>
 #include <unistd.h>
 
-extern int topy;
+extern int topline;
 
 static struct line {
 	struct item item;
@@ -123,8 +123,8 @@ static void init_lines(void) {
 			lines->item.prev->next = (struct item *) line;
 			lines->item.prev = (struct item *) line;
 		}
-		line->item.top = y++;
-		line->item.height = 1;
+		line->item.listline = y++;
+		line->item.ndescr = 1;
 		n = strlen(word);
 		if(n > helpwidth-1) {
 			for(n = helpwidth-1; word[n]!=' '; n--) {
@@ -180,9 +180,9 @@ static int drawline(struct item *item, bool highlight) {
 		wattrset(win(List), COLOR_PAIR(3));
 	else
 		wattrset(win(List), COLOR_PAIR(3) | A_BOLD | A_REVERSE);
-	mvwaddstr(win(List), line->item.top-topy, 0, buf);
+	mvwaddstr(win(List), line->item.currline, 0, buf);
 	if(highlight)
-		wmove(win(List), line->item.top-topy, 0);
+		wmove(win(List), line->item.currline, 0);
 	wnoutrefresh(win(List));
 	return 1;
 }

diff --git a/ufed-curses.c b/ufed-curses.c
index 1e9b232..1bb26ca 100644
--- a/ufed-curses.c
+++ b/ufed-curses.c
@@ -25,21 +25,60 @@ static struct item *items, *currentitem;
 
 
 /* external members */
-int topy, minwidth;
+int topline, minwidth;
 extern enum mask showMasked;
 extern enum order pkgOrder;
 extern enum scope showScope;
-extern int firstNormalY;
+extern int lineCountGlobal;
+extern int lineCountLocal;
+extern int lineCountLocalInstalled;
+extern int lineCountMasked;
+extern int lineCountMaskedInstalled;
+extern int lineCountMasked;
 
 
 /* internal prototypes */
 static void checktermsize(void);
+int  getListHeight();
 void resetDisplay();
 void setNextItem(int count, bool strict);
 void setPrevItem(int count, bool strict);
 
 
 /* internal functions */
+/** @brief return the number of lines the full item display needs
+**/
+int getItemHeight(struct item *item)
+{
+	// TODO : Add filtering and possible line break
+	return item->ndescr;
+}
+
+
+/** @brief get the sum of lines the list holds respecting current filtering
+**/
+int getListHeight()
+{
+	int result = 0;
+
+	if (show_unmasked != showMasked) {
+		// TODO : add installed/not installed filter
+		result += lineCountMasked + lineCountMaskedInstalled;
+	}
+	if (show_masked != showMasked) {
+		if (show_global != showScope) {
+			// TODO : add installed/not installed filter
+			result += lineCountLocal + lineCountLocalInstalled;
+		}
+		if (show_local != showScope) {
+			result += lineCountGlobal;
+		}
+	}
+
+	return result;
+}
+
+
 void initcurses(void) {
 	setlocale(LC_CTYPE, "");
 	initscr();
@@ -87,49 +126,63 @@ static void checktermsize(void) {
 static int (*drawitem)(struct item *, bool);
 
 void drawitems(void) {
+	/* sanitize currentitem first.
+	 * This is needed, because the currently selected
+	 * item may become invalid when a filter is
+	 * toggled.
+	 */
+	if (!isLegalItem(currentitem)) {
+		while ((currentitem != items) && !isLegalItem(currentitem)) {
+			currentitem = currentitem->prev;
+			topline -= getItemHeight(currentitem);
+		}
+		while ((currentitem->next != items) && !isLegalItem(currentitem)) {
+			topline += getItemHeight(currentitem);
+			currentitem = currentitem->next;
+		}
+	} // End of sanitizing currentitem
+
 	struct item *item = currentitem;
-	int y = item->top - topy;
+	int line = item->listline - topline;
 
 	/* move to the top of the displayed list */
-	for ( ; (y > 0) && item; y = item->top - topy)
+	for ( ; (item != items) && ((line > 0) || !isLegalItem(item)); line = item->listline - topline)
 		item = item->prev;
 
-	/* advance in the list if the top item would be a masked
-	 * flag that is to be filtered out.
-	 * This is needed in two situations. First at the very start
-	 * of the program and second whenever the filtering is
-	 * toggled. The latter resets the list position to guarantee
-	 * a valid display.
+	/* If the above move ended up with item == items
+	 * it must be checked whether to move forwards again.
+	 * This can happen if the flag filter is toggled
+	 * and the current item is the first not filtered item.
 	 */
-	if ((show_unmasked == showMasked) && item->isMasked) {
-		while (item && item->isMasked) {
+	if ((item == items) && !isLegalItem(item)) {
+		item = currentitem;
+		while (!isLegalItem(item) && (item != items)) {
 			if (currentitem == item)
 				currentitem = item->next;
-			topy += item->height;
-			item  = item->next;
+			item = item->next;
+			topline += getItemHeight(item);
 		}
 	}
 
-	for(;;) {
-		if(item!=currentitem)
-			y += (*drawitem)(item, FALSE);
-		else
-			y += item->height;
+	for( ; line < wHeight(List); ) {
+		item->currline = line; // drawitem() and maineventloop() need this
+		line += (*drawitem)(item, item == currentitem ? TRUE : FALSE);
 		item = item->next;
-		if(y >= wHeight(List))
-			break;
-		if(item==items) {
+
+		/* Add blank lines if we reached the end of the
+		 * flag list, but not the end of the display.
+		 */
+		if((line < wHeight(List)) && (item == items)) {
 			char buf[wWidth(List)];
 			memset(buf, ' ', wWidth(List));
 			buf[wWidth(List)] = '\0';
-			wmove(win(List), y, 0);
+			wmove(win(List), line, 0);
 			wattrset(win(List), COLOR_PAIR(3));
-			while(y++ < wHeight(List))
+			while(line++ < wHeight(List))
 				waddstr(win(List), buf);
 			break;
 		}
 	}
-	(*drawitem)(currentitem, TRUE);
 	wnoutrefresh(win(List));
 }
 
@@ -142,25 +195,12 @@ static void drawscrollbar(void) {
 	/* The scrollbar location differs related to the
 	 * current filtering of masked flags.
 	 */
-	int bottomY    = items->prev->top + items->prev->height;
-	// Case 1: Masked flags are not displayed (the default)
-	int listHeight = bottomY - firstNormalY;
-	int listTopY   = topy    - firstNormalY;
-	if (show_masked == showMasked) {
-		// Case 2: Only masked flags are displayed
-		listHeight = firstNormalY;
-		listTopY   = topy;
-	}
-	else if (show_both == showMasked) {
-		// case 3: All flags are shown
-		listHeight = bottomY;
-		listTopY   = topy;
-	}
+	int listHeight = getListHeight();
 
 	// Only show a scrollbar if the list is actually longer than can be displayed:
 	if (listHeight > wHeight(List)) {
 		int sbHeight = wHeight(Scrollbar) - 3;
-		int barStart = 1 + (sbHeight * listTopY / listHeight);
+		int barStart = 1 + (sbHeight / listHeight);
 		int barEnd   = barStart + (sbHeight * wHeight(List) / listHeight);
 		for ( ; barStart <= barEnd; ++barStart)
 			mvwaddch(w, barStart, 0, ACS_BLOCK);
@@ -291,10 +331,10 @@ static void draw(void) {
 }
 
 void scrollcurrent(void) {
-	if(currentitem->top < topy)
-		topy = max(currentitem->top, currentitem->top + currentitem->height - wHeight(List));
-	else if( (currentitem->top + currentitem->height) > (topy + wHeight(List)))
-		topy = min(currentitem->top + currentitem->height - wHeight(List), currentitem->top);
+	if(currentitem->listline < topline)
+		topline = max(currentitem->listline, currentitem->listline + currentitem->ndescr - wHeight(List));
+	else if( (currentitem->listline + currentitem->ndescr) > (topline + wHeight(List)))
+		topline = min(currentitem->listline + currentitem->ndescr - wHeight(List), currentitem->listline);
 	else
 		return;
 	drawitems();
@@ -327,7 +367,7 @@ bool yesno(const char *prompt) {
 					window[w].win = newwin(wHeight(w), wWidth(w), wTop(w), wLeft(w));
 				} }
 				/* this won't work for the help viewer, but it doesn't use yesno() */
-				topy = 0;
+				topline = 0;
 				scrollcurrent();
 				draw();
 				wattrset(win(Input), COLOR_PAIR(4) | A_BOLD | A_REVERSE);
@@ -363,7 +403,7 @@ int maineventloop(
 		_keys=temp; }
 
 	currentitem = items;
-	topy = 0;
+	topline = 0;
 
 	draw();
 
@@ -395,14 +435,14 @@ int maineventloop(
 				if(wmouse_trafo(win(List), &event.y, &event.x, FALSE)) {
 					if(event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED)) {
 						struct item *item = currentitem;
-						if(currentitem->top-topy > event.y) {
+						if(currentitem->currline > event.y) {
 							do item = item->prev;
 							while((item==items ? item=NULL, 0 : 1)
-							 && item->top-topy > event.y);
-						} else if(currentitem->top-topy+currentitem->height-1 < event.y) {
+							 && item->currline > event.y);
+						} else if(currentitem->currline + getItemHeight(currentitem) - 1 < event.y) {
 							do item = item->next;
 							while((item->next==items ? item=NULL, 0 : 1)
-							 && item->top-topy+item->height-1 < event.y);
+							 && item->currline + getItemHeight(item) - 1 < event.y);
 						}
 						if(item==NULL)
 							continue;
@@ -417,10 +457,15 @@ int maineventloop(
 						(*drawitem)(currentitem, TRUE);
 					}
 				} else if(wmouse_trafo(win(Scrollbar), &event.y, &event.x, FALSE)) {
-					if( (event.bstate & (BUTTON1_PRESSED | BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))
+					// Only do mouse events if there actually is a scrollbar
+					int listHeight = getListHeight();
+					if( (listHeight > wHeight(List))
+					 && (event.bstate & (BUTTON1_PRESSED | BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))
 					 && (event.y < wHeight(Scrollbar)-1) ) {
+						int sbHeight = wHeight(Scrollbar) - 3;
+						int barStart = 1 + (sbHeight / listHeight);
+						int barEnd   = barStart + (sbHeight * wHeight(List) / listHeight);
 						halfdelay(1);
-
 #define SIM(key) \
 	{ \
 		c = KEY_ ## key; \
@@ -428,50 +473,48 @@ int maineventloop(
 			mousekey = c; \
 		goto check_key; \
 	}
-						if(items->prev->top+items->prev->height > wHeight(List))
-							{}
-						else if(event.y == 0)
+						if(event.y == 0)
 							SIM(UP)
 						else if(event.y == wHeight(Scrollbar)-2)
 							SIM(DOWN)
-						else if(event.y-1 < (wHeight(Scrollbar)-3)*topy/(items->prev->top+items->prev->height-(wHeight(List)-1)))
+						else if( (event.y - 1) < barStart)
 							SIM(PPAGE)
-						else if(event.y-1 > (wHeight(Scrollbar)-3)*topy/(items->prev->top+items->prev->height-(wHeight(List)-1)))
+						else if( (event.y - 1) > barEnd)
 							SIM(NPAGE)
 #undef SIM
-						else
-							if(event.bstate & BUTTON1_PRESSED) {
-								for(;;) {
-									c = getch();
-									switch(c) {
-									case ERR:
-										continue;
-									case KEY_MOUSE:
-										if(getmouse(&event)==OK) {
-											event.y -= wTop(Scrollbar)+1;
-											if(event.y>=0 && event.y<wHeight(Scrollbar)-3) {
-												topy = (event.y*(items->prev->top+items->prev->height-(wHeight(List)-1))+(wHeight(Scrollbar)-4))/(wHeight(Scrollbar)-3);
-												while(currentitem!=items
-												 && currentitem->prev->top >= topy)
-													currentitem = currentitem->prev;
-												while(currentitem->next!=items
-												 && currentitem->top < topy)
-													currentitem = currentitem->next;
-												if(currentitem->top+currentitem->height > topy+wHeight(List))
-													topy = currentitem->top+currentitem->height - wHeight(List);
-												drawitems();
-												drawscrollbar();
-												wrefresh(win(List));
-											}
+						else if(event.bstate & BUTTON1_PRESSED) {
+							for(;;) {
+								c = getch();
+								switch(c) {
+								case ERR:
+									continue;
+								case KEY_MOUSE:
+									if(getmouse(&event)==OK) {
+										event.y -= wTop(Scrollbar) + 1;
+										if( (event.y >= 0) && (event.y < sbHeight) ) {
+											topline = (event.y * (listHeight - sbHeight + 2) + sbHeight - 1) / sbHeight;
+											// was: topy = (event.y*(items->prev->top+items->prev->height-(wHeight(List)-1))+(wHeight(Scrollbar)-4))/(wHeight(Scrollbar)-3);
+											while( (currentitem != items)
+												&& (currentitem->prev->listline >= topline) )
+												currentitem = currentitem->prev;
+											while( (currentitem->next != items)
+												&& (currentitem->listline < topline) )
+												currentitem = currentitem->next;
+											if( (currentitem->listline + currentitem->ndescr) > (topline + wHeight(List)) )
+												topline = currentitem->listline + currentitem->ndescr - wHeight(List);
+											drawitems();
+											drawscrollbar();
+											wrefresh(win(List));
 										}
-										break;
-									default:
-										goto check_key;
 									}
 									break;
+								default:
+									goto check_key;
 								}
+								break;
 							}
-					}
+						} // End of alternate scrollbar event
+					} // End of having a scrollbar
 				} else if(wmouse_trafo(win(Bottom), &event.y, &event.x, FALSE)) {
 					if( (event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))
 					 && (event.y == 1) ) {
@@ -511,19 +554,19 @@ int maineventloop(
 
 			switch(c) {
 				case KEY_UP:
-					if(currentitem->top < topy ) {
+					if(currentitem->listline < topline ) {
 						(*drawitem)(currentitem, FALSE);
-						topy--;
+						topline--;
 						(*drawitem)(currentitem, TRUE);
 					} else
 						setPrevItem(1, true);
 					break;
 	
 				case KEY_DOWN:
-					if( (currentitem->top + currentitem->height) > (topy + wHeight(List)) ) {
+					if( (currentitem->listline + currentitem->ndescr) > (topline + wHeight(List)) ) {
 						// Scroll through descriptions if their list is longer than the window
 						(*drawitem)(currentitem, FALSE);
-						topy++;
+						++topline;
 						(*drawitem)(currentitem, TRUE);
 					} else
 						setNextItem(1, true);
@@ -584,7 +627,7 @@ int maineventloop(
 						window[w].win = newwin(wHeight(w), wWidth(w), wTop(w), wLeft(w));
 					} }
 					if(result==-1) {
-						topy = 0;
+						topline = 0;
 						scrollcurrent();
 					} else
 						items = currentitem;
@@ -603,7 +646,7 @@ exit:
 
 	if(items!=NULL) {
 		currentitem = items;
-		topy = 0;
+		topline = 0;
 		draw();
 	}
 
@@ -619,7 +662,7 @@ void resetDisplay()
 	currentitem = items;
 	while (!isLegalItem(currentitem))
 		currentitem = currentitem->next;
-	topy = currentitem->top;
+	topline = currentitem->listline;
 	draw();
 }
 
@@ -692,7 +735,7 @@ bool isLegalItem(struct item *item)
 	     ( ( item->isMasked && (show_unmasked != showMasked))
 	    || (!item->isMasked && (show_masked   != showMasked)) )
 	     // 2: Global / Local filter
-	  && ( ( item->isGlobal && ( (show_local  != showScope) || (item->height > 1) ) )
+	  && ( ( item->isGlobal && ( (show_local  != showScope) || (item->ndescr > 1) ) )
 	    || (!item->isGlobal && (  show_global != showScope)) ) )
 		return true;
 	return false;

diff --git a/ufed-curses.h b/ufed-curses.h
index 9633692..71a4b18 100644
--- a/ufed-curses.h
+++ b/ufed-curses.h
@@ -41,7 +41,9 @@ struct window {
 
 struct item {
 	struct item *prev, *next;
-	int top, height;
+	int currline; //!< the current line on the screen this item starts.
+	int listline; //!< the fixed line within the full list this item starts
+	int ndescr;   //!< number of description lines
 	bool isMasked;
 	bool isGlobal;
 };
@@ -55,6 +57,7 @@ struct key {
 
 /* global prototypes */
 void cursesdone(void);
+int  getItemHeight(struct item *item);
 void initcurses(void);
 bool isLegalItem(struct item *item);
 


             reply	other threads:[~2013-01-23 12:05 UTC|newest]

Thread overview: 238+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-23 12:05 Sven Eden [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-11-07 14:25 [gentoo-commits] proj/ufed:master commit in: / Sven Eden
2020-05-02  8:38 Ulrich Müller
2019-09-27  6:42 Sven Eden
2019-09-27  6:39 Sven Eden
2019-09-24 17:57 Sven Eden
2019-09-24 17:56 Sven Eden
2019-04-07 15:17 David Seifert
2019-04-07 13:56 David Seifert
2019-04-07 13:19 David Seifert
2019-04-07 13:19 David Seifert
2019-04-07 13:19 David Seifert
2019-04-07 13:19 David Seifert
2019-04-07 13:19 David Seifert
2015-02-12 15:47 Sven Eden
2015-02-11  9:03 Sven Eden
2014-11-10  9:59 Sven Eden
2014-10-28 11:43 Sven Eden
2014-02-26 10:26 Sven Eden
2014-02-26 10:26 Sven Eden
2014-02-26 10:26 Sven Eden
2014-02-26 10:26 Sven Eden
2014-02-26 10:26 Sven Eden
2014-02-26 10:26 Sven Eden
2014-02-25  8:18 Sven Eden
2014-02-25  8:18 Sven Eden
2014-02-25  8:18 Sven Eden
2014-02-25  8:18 Sven Eden
2013-11-25 21:43 Sven Eden
2013-11-25 21:43 Sven Eden
2013-11-25 21:43 Sven Eden
2013-11-25 21:43 Sven Eden
2013-11-25 21:43 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-11  7:09 Sven Eden
2013-09-11  6:31 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-10 12:37 Sven Eden
2013-09-10  6:36 Sven Eden
2013-09-10  6:36 Sven Eden
2013-09-10  6:36 Sven Eden
2013-09-10  6:36 Sven Eden
2013-09-10  6:36 Sven Eden
2013-09-10  6:36 Sven Eden
2013-09-10  6:36 Sven Eden
2013-07-22  9:34 Sven Eden
2013-07-22  6:09 Sven Eden
2013-07-22  6:09 Sven Eden
2013-04-09  7:22 Sven Eden
2013-04-09  7:22 Sven Eden
2013-04-09  7:22 Sven Eden
2013-04-08  7:18 Sven Eden
2013-04-03 13:39 Sven Eden
2013-03-05 16:53 Sven Eden
2013-03-05 16:49 Sven Eden
2013-03-05 16:49 Sven Eden
2013-03-05 16:49 Sven Eden
2013-03-05 16:49 Sven Eden
2013-03-05 16:49 Sven Eden
2013-02-21 10:02 Sven Eden
2013-02-19 15:16 Sven Eden
2013-02-19 13:34 Sven Eden
2013-02-18  7:22 Sven Eden
2013-02-15  8:36 Sven Eden
2013-02-15  8:36 Sven Eden
2013-02-15  8:36 Sven Eden
2013-02-14  8:35 Sven Eden
2013-02-14  8:35 Sven Eden
2013-02-14  8:35 Sven Eden
2013-02-13  9:23 Sven Eden
2013-02-13  9:23 Sven Eden
2013-02-13  9:23 Sven Eden
2013-02-13  9:23 Sven Eden
2013-02-13  9:23 Sven Eden
2013-02-12 10:51 Sven Eden
2013-02-12 10:51 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-06  9:09 Sven Eden
2013-02-06  9:09 Sven Eden
2013-02-05 18:06 Paul Varner
2013-02-05 13:53 Sven Eden
2013-02-05 13:53 Sven Eden
2013-02-05 11:24 Sven Eden
2013-02-03 14:32 Sven Eden
2013-02-03 14:32 Sven Eden
2013-02-03 14:32 Sven Eden
2013-02-03 14:32 Sven Eden
2013-02-03 14:32 Sven Eden
2013-02-02 20:49 Sven Eden
2013-02-02 10:11 Sven Eden
2013-02-02  9:47 Sven Eden
2013-02-02  9:47 Sven Eden
2013-02-02  9:47 Sven Eden
2013-02-01 21:12 Sven Eden
2013-02-01 21:12 Sven Eden
2013-02-01 21:12 Sven Eden
2013-02-01 16:04 Sven Eden
2013-02-01 15:55 Sven Eden
2013-02-01 15:26 Sven Eden
2013-02-01 14:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-01-24 10:15 Sven Eden
2013-01-24 10:15 Sven Eden
2013-01-24 10:15 Sven Eden
2013-01-24 10:15 Sven Eden
2013-01-24 10:15 Sven Eden
2013-01-23 14:44 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-16 13:43 Sven Eden
2013-01-16 12:56 Sven Eden
2013-01-16 12:56 Sven Eden
2013-01-16 12:56 Sven Eden
2013-01-16 12:56 Sven Eden
2013-01-16 12:56 Sven Eden
2013-01-16 12:56 Sven Eden
2013-01-08 11:02 Sven Eden
2013-01-02  8:47 Sven Eden
2013-01-02  8:01 Sven Eden
2013-01-02  8:01 Sven Eden
2012-11-20 17:31 Paul Varner
2012-11-20 17:25 Paul Varner
2012-10-23 16:13 Paul Varner
2012-10-23 16:13 Paul Varner
2012-10-23 16:13 Paul Varner
2012-10-23 16:01 Paul Varner
2012-10-22 20:42 Paul Varner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1358803405.ffa22db238235c70dc4c7cd12434ec78d39ed01e.yamakuzure@gentoo \
    --to=sven.eden@gmx.de \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox