summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-01-12 20:01:11 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-01-12 20:01:11 +0200
commit42d72047cb3c6039b2423345e0220fceaacf0f78 (patch)
tree877280aba38a3f08151264b1a0700abf6706d5b7
parent8a9cc8bfafaee7d6810b831182f7f055c2827f8b (diff)
LookupWidget: Item icons are aligned horizontally
-rw-r--r--src/lookup.c2
-rw-r--r--src/lookup.h1
-rw-r--r--src/ui/lookupwidget.c34
3 files changed, 25 insertions, 12 deletions
diff --git a/src/lookup.c b/src/lookup.c
index 6ad8d708..af3d760d 100644
--- a/src/lookup.c
+++ b/src/lookup.c
@@ -27,6 +27,7 @@ iDefineTypeConstruction(LookupResult)
27void init_LookupResult(iLookupResult *d) { 27void init_LookupResult(iLookupResult *d) {
28 d->type = none_LookupResultType; 28 d->type = none_LookupResultType;
29 d->relevance = 0; 29 d->relevance = 0;
30 d->icon = 0;
30 init_String(&d->label); 31 init_String(&d->label);
31 init_String(&d->url); 32 init_String(&d->url);
32 init_String(&d->meta); 33 init_String(&d->meta);
@@ -43,6 +44,7 @@ iLookupResult *copy_LookupResult(const iLookupResult *d) {
43 iLookupResult *copy = new_LookupResult(); 44 iLookupResult *copy = new_LookupResult();
44 copy->type = d->type; 45 copy->type = d->type;
45 copy->relevance = d->relevance; 46 copy->relevance = d->relevance;
47 copy->icon = d->icon;
46 set_String(&copy->label, &d->label); 48 set_String(&copy->label, &d->label);
47 set_String(&copy->url, &d->url); 49 set_String(&copy->url, &d->url);
48 set_String(&copy->meta, &d->meta); 50 set_String(&copy->meta, &d->meta);
diff --git a/src/lookup.h b/src/lookup.h
index 64e2c974..771851a6 100644
--- a/src/lookup.h
+++ b/src/lookup.h
@@ -39,6 +39,7 @@ enum iLookupResultType {
39struct Impl_LookupResult { 39struct Impl_LookupResult {
40 enum iLookupResultType type; 40 enum iLookupResultType type;
41 float relevance; /* used for sorting results */ 41 float relevance; /* used for sorting results */
42 iChar icon;
42 iString label; 43 iString label;
43 iString url; 44 iString url;
44 iString meta; 45 iString meta;
diff --git a/src/ui/lookupwidget.c b/src/ui/lookupwidget.c
index 284d518e..1975610e 100644
--- a/src/ui/lookupwidget.c
+++ b/src/ui/lookupwidget.c
@@ -77,6 +77,7 @@ struct Impl_LookupItem {
77 iLookupResult *result; 77 iLookupResult *result;
78 int font; 78 int font;
79 int fg; 79 int fg;
80 iString icon;
80 iString text; 81 iString text;
81 iString command; 82 iString command;
82}; 83};
@@ -86,6 +87,10 @@ static void init_LookupItem(iLookupItem *d, const iLookupResult *res) {
86 d->result = res ? copy_LookupResult(res) : NULL; 87 d->result = res ? copy_LookupResult(res) : NULL;
87 d->font = uiContent_FontId; 88 d->font = uiContent_FontId;
88 d->fg = uiText_ColorId; 89 d->fg = uiText_ColorId;
90 init_String(&d->icon);
91 if (res && res->icon) {
92 appendChar_String(&d->icon, res->icon);
93 }
89 init_String(&d->text); 94 init_String(&d->text);
90 init_String(&d->command); 95 init_String(&d->command);
91} 96}
@@ -93,6 +98,7 @@ static void init_LookupItem(iLookupItem *d, const iLookupResult *res) {
93static void deinit_LookupItem(iLookupItem *d) { 98static void deinit_LookupItem(iLookupItem *d) {
94 deinit_String(&d->command); 99 deinit_String(&d->command);
95 deinit_String(&d->text); 100 deinit_String(&d->text);
101 deinit_String(&d->icon);
96 delete_LookupResult(d->result); 102 delete_LookupResult(d->result);
97} 103}
98 104
@@ -110,11 +116,20 @@ static void draw_LookupItem_(iLookupItem *d, iPaint *p, iRect rect, const iListW
110 ? permanent_ColorId | (isPressing || isCursor ? uiTextPressed_ColorId 116 ? permanent_ColorId | (isPressing || isCursor ? uiTextPressed_ColorId
111 : uiTextFramelessHover_ColorId) 117 : uiTextFramelessHover_ColorId)
112 : d->fg; 118 : d->fg;
113 const iInt2 size = measure_Text(d->font, cstr_String(&d->text)); 119 const iInt2 size = measureRange_Text(d->font, range_String(&d->text));
114 iInt2 pos = init_I2(left_Rect(rect) + 3 * gap_UI, mid_Rect(rect).y - size.y / 2); 120 iInt2 pos = init_I2(left_Rect(rect) + 3 * gap_UI, mid_Rect(rect).y - size.y / 2);
115 if (d->listItem.isSeparator) { 121 if (d->listItem.isSeparator) {
116 pos.y = bottom_Rect(rect) - lineHeight_Text(d->font); 122 pos.y = bottom_Rect(rect) - lineHeight_Text(d->font);
117 } 123 }
124 if (!isEmpty_String(&d->icon)) {
125 const iRect iconRect = { pos, init_I2(gap_UI * 5, height_Rect(rect)) };
126 const iInt2 iconSize = measureRange_Text(d->font, range_String(&d->icon));
127 drawRange_Text(d->font,
128 addX_I2(pos, width_Rect(iconRect) / 2 - iconSize.x / 2),
129 fg,
130 range_String(&d->icon));
131 pos.x += width_Rect(iconRect) + gap_UI;
132 }
118 drawRange_Text(d->font, pos, fg, range_String(&d->text)); 133 drawRange_Text(d->font, pos, fg, range_String(&d->text));
119} 134}
120 135
@@ -203,9 +218,8 @@ static void searchBookmarks_LookupJob_(iLookupJob *d) {
203 res->type = bookmark_LookupResultType; 218 res->type = bookmark_LookupResultType;
204 res->when = bm->when; 219 res->when = bm->when;
205 res->relevance = bookmarkRelevance_LookupJob_(d, bm); 220 res->relevance = bookmarkRelevance_LookupJob_(d, bm);
206 appendChar_String(&res->label, bm->icon); 221 res->icon = bm->icon;
207 appendChar_String(&res->label, ' '); 222 set_String(&res->label, &bm->title);
208 append_String(&res->label, &bm->title);
209 set_String(&res->url, &bm->url); 223 set_String(&res->url, &bm->url);
210 pushBack_PtrArray(&d->results, res); 224 pushBack_PtrArray(&d->results, res);
211 } 225 }
@@ -226,11 +240,8 @@ static void searchFeeds_LookupJob_(iLookupJob *d) {
226 res->relevance = relevance; 240 res->relevance = relevance;
227 set_String(&res->url, &entry->url); 241 set_String(&res->url, &entry->url);
228 set_String(&res->meta, &bm->title); 242 set_String(&res->meta, &bm->title);
229 if (bm->icon) { 243 set_String(&res->label, &entry->title);
230 appendChar_String(&res->label, bm->icon); 244 res->icon = bm->icon;
231 appendChar_String(&res->label, ' ');
232 }
233 append_String(&res->label, &entry->title);
234 pushBack_PtrArray(&d->results, res); 245 pushBack_PtrArray(&d->results, res);
235 } 246 }
236 } 247 }
@@ -285,10 +296,9 @@ static void searchIdentities_LookupJob_(iLookupJob *d) {
285 iLookupResult *res = new_LookupResult(); 296 iLookupResult *res = new_LookupResult();
286 res->type = identity_LookupResultType; 297 res->type = identity_LookupResultType;
287 res->relevance = identityRelevance_LookupJob_(d, identity); 298 res->relevance = identityRelevance_LookupJob_(d, identity);
288 appendChar_String(&res->label, identity->icon); 299 res->icon = identity->icon;
289 appendChar_String(&res->label, ' ');
290 iString *cn = subject_TlsCertificate(identity->cert); 300 iString *cn = subject_TlsCertificate(identity->cert);
291 append_String(&res->label, cn); 301 set_String(&res->label, cn);
292 delete_String(cn); 302 delete_String(cn);
293 set_String(&res->meta, 303 set_String(&res->meta,
294 collect_String( 304 collect_String(