Gentoo Archives: gentoo-commits

From: Sven Eden <sven.eden@×××.de>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/ufed:master commit in: /
Date: Fri, 01 Feb 2013 10:50:11
Message-Id: 1359713705.f44fc180351f67a460acf1d46b03124660da1c9a.yamakuzure@gentoo
1 commit: f44fc180351f67a460acf1d46b03124660da1c9a
2 Author: Sven Eden <sven.eden <AT> gmx <DOT> de>
3 AuthorDate: Fri Feb 1 10:15:05 2013 +0000
4 Commit: Sven Eden <sven.eden <AT> gmx <DOT> de>
5 CommitDate: Fri Feb 1 10:15:05 2013 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/ufed.git;a=commit;h=f44fc180
7
8 Fixed setPrevItem(), setNextItem() and drawFlags() to handle the skipping of individual filtered out description lines. Note: this surely can be optimized. Later.
9
10 ---
11 ufed-curses.c | 176 ++++++++++++++++++++++++++++++++++++++++-----------------
12 1 files changed, 123 insertions(+), 53 deletions(-)
13
14 diff --git a/ufed-curses.c b/ufed-curses.c
15 index bc55ca1..2808055 100644
16 --- a/ufed-curses.c
17 +++ b/ufed-curses.c
18 @@ -42,8 +42,8 @@ void draw(bool withSep);
19 void drawScrollbar(void);
20 int getListHeight(void);
21 void resetDisplay(bool withSep);
22 -void setNextItem(int count, bool strict);
23 -void setPrevItem(int count, bool strict);
24 +bool setNextItem(int count, bool strict);
25 +bool setPrevItem(int count, bool strict);
26
27
28 /* internal functions */
29 @@ -197,25 +197,28 @@ void drawFlags() {
30 topline, currentflag->listline)
31
32 sFlag* flag = currentflag;
33 + sFlag* last = currentflag;
34
35 int line = flag->listline - topline;
36
37 /* move to the top of the displayed list */
38 while ((flag != flags) && (line > 0)) {
39 flag = flag->prev;
40 - if (isFlagLegal(flag))
41 + if (isFlagLegal(flag)) {
42 line -= getFlagHeight(flag);
43 + last = flag;
44 + }
45 }
46
47 /* If the above move ended up with flag == flags
48 - * topline and line must be adapted to the current
49 - * flag.
50 + * topline and line must be adapted to the last
51 + * found not filtered flag.
52 * This can happen if the flag filter is toggled
53 * and the current flag is the first not filtered.
54 */
55 if ((flag == flags) && !isFlagLegal(flag)) {
56 - flag = currentflag;
57 - topline = currentflag->listline;
58 + flag = last;
59 + topline = last->listline;
60 line = 0;
61 }
62
63 @@ -408,10 +411,14 @@ void draw(bool withSep) {
64 }
65
66 bool scrollcurrent() {
67 - if(currentflag->listline < topline)
68 - topline = max(currentflag->listline, currentflag->listline + currentflag->ndesc - wHeight(List));
69 - else if( (currentflag->listline + currentflag->ndesc) > (topline + wHeight(List)))
70 - topline = min(currentflag->listline + currentflag->ndesc - wHeight(List), currentflag->listline);
71 + int lsLine = currentflag->listline;
72 + int flHeight = getFlagHeight(currentflag);
73 + int btLine = lsLine + flHeight;
74 + int wdHeight = wHeight(List);
75 + if(lsLine < topline)
76 + topline = max(lsLine, btLine - wdHeight);
77 + else if( btLine > (topline + wdHeight))
78 + topline = min(btLine - wdHeight, lsLine);
79 else
80 return false;
81 drawFlags();
82 @@ -777,77 +784,140 @@ void resetDisplay(bool withSep)
83 /** @brief set currentflag to the next flag @a count lines away
84 * @param count set how many lines should be skipped
85 * @param strict if set to false, at least one item has to be skipped.
86 + * @return true if currentflag was changed, flase otherwise
87 */
88 -void setNextItem(int count, bool strict)
89 +bool setNextItem(int count, bool strict)
90 {
91 - bool result = true;
92 - sFlag* curr = currentflag;
93 - int skipped = 0;
94 - int oldTop = topline;
95 + bool result = true;
96 + sFlag* curr = currentflag;
97 + sFlag* lastFlag = NULL;
98 + int lastTop = 0;
99 + int skipped = 0;
100 + int oldTop = topline;
101 + int fHeight = 0;
102 +
103 + // It is crucial to start with a not filtered flag:
104 + while (!isFlagLegal(curr) && (curr->next != flags)) {
105 + topline += curr->ndesc;
106 + curr = curr->next;
107 + }
108 +
109 + // Break this if the current item is still filtered
110 + if (!isFlagLegal(curr)) {
111 + topline = oldTop;
112 + return false;
113 + }
114
115 while (result && (skipped < count)) {
116 - if (curr->next == flags)
117 - result = false; // The list is finished, no next item to display
118 - else
119 - curr = curr->next;
120 -
121 - // curr is only counted if it is not filtered out:
122 - if (isFlagLegal(curr))
123 - skipped += getFlagHeight(curr);
124 - else
125 - // Otherwise topline must be adapted or scrollcurrent() wreaks havoc!
126 + lastFlag = curr;
127 + lastTop = topline;
128 + fHeight = getFlagHeight(curr);
129 + skipped += fHeight;
130 + topline += curr->ndesc - fHeight;
131 + curr = curr->next;
132 +
133 + // Ensure a not filtered flag to continue
134 + while (!isFlagLegal(curr) && (curr->next != flags)) {
135 topline += curr->ndesc;
136 + curr = curr->next;
137 + }
138 +
139 + // It is possible to end up with the last flag
140 + // which might be filtered:
141 + if (curr->next == flags) {
142 + if (!isFlagLegal(curr)) {
143 + // Revert to last known legal state:
144 + curr = lastFlag;
145 + topline = lastTop;
146 + skipped -= getFlagHeight(curr);
147 + }
148 + // Did we fail ?
149 + if (skipped < count)
150 + result = false;
151 + }
152 } // End of trying to find a next item
153
154 if ( (result && strict) || (!strict && skipped) ) {
155 - // Move back again if curr ended up being filtered
156 - while (!isFlagLegal(curr)) {
157 - topline -= curr->ndesc;
158 - curr = curr->prev;
159 - }
160 drawflag(currentflag, FALSE);
161 currentflag = curr;
162 if (!scrollcurrent())
163 drawflag(currentflag, TRUE);
164 - } else
165 + result = true;
166 + } else {
167 topline = oldTop;
168 + result = false;
169 + }
170 +
171 + return result;
172 }
173
174
175 /* @brief set currentflag to the previous item @a count lines away
176 * @param count set how many lines should be skipped
177 * @param strict if set to false, at least one item has to be skipped.
178 + * @return true if currentflag was changed, flase otherwise
179 */
180 -void setPrevItem(int count, bool strict)
181 +bool setPrevItem(int count, bool strict)
182 {
183 - bool result = true;
184 - sFlag* curr = currentflag;
185 - int skipped = 0;
186 - int oldTop = topline;
187 + bool result = true;
188 + sFlag* curr = currentflag;
189 + sFlag* lastFlag = NULL;
190 + int lastTop = 0;
191 + int skipped = 0;
192 + int oldTop = topline;
193 + int fHeight = 0;
194 +
195 + // It is crucial to start with a not filtered flag:
196 + while (!isFlagLegal(curr) && (curr != flags)) {
197 + topline -= curr->ndesc;
198 + curr = curr->prev;
199 + }
200 + // Break this if the current item is still filtered
201 + if (!isFlagLegal(curr)) {
202 + topline = oldTop;
203 + return false;
204 + }
205
206 while (result && (skipped < count)) {
207 - if (curr == flags)
208 - result = false; // The list is finished, no previous item to display
209 - else
210 - curr = curr->prev;
211 -
212 - // curr is only counted if it is not filtered out:
213 - if (isFlagLegal(curr))
214 - skipped += getFlagHeight(curr);
215 - else
216 + lastFlag = curr;
217 + lastTop = topline;
218 + curr = curr->prev;
219 +
220 + // Ensure a not filtered flag to continue
221 + while (!isFlagLegal(curr) && (curr != flags)) {
222 topline -= curr->ndesc;
223 - } // End of trying to find next item
224 + curr = curr->prev;
225 + }
226
227 - if ( (result && strict) || (!strict && skipped) ) {
228 - // Move forth again if curr ended up being filtered
229 - while (!isFlagLegal(curr)) {
230 - topline += curr->ndesc;
231 - curr = curr->next;
232 + fHeight = getFlagHeight(curr);
233 + skipped += fHeight;
234 + topline -= curr->ndesc - fHeight;
235 +
236 + // It is possible to end up with the first flag
237 + // which might be filtered:
238 + if (curr == flags) {
239 + if (!isFlagLegal(curr)) {
240 + // Revert to last known legal state:
241 + skipped -= getFlagHeight(curr);
242 + curr = lastFlag;
243 + topline = lastTop;
244 + }
245 + // Did we fail ?
246 + if (skipped < count)
247 + result = false;
248 }
249 + } // End of trying to find a next item
250 +
251 + if ( (result && strict) || (!strict && skipped) ) {
252 drawflag(currentflag, FALSE);
253 currentflag = curr;
254 if (!scrollcurrent())
255 drawflag(currentflag, TRUE);
256 - } else
257 + result = true;
258 + } else {
259 topline = oldTop;
260 + result = false;
261 + }
262 +
263 + return result;
264 }