fix: split search results in Settings by category
This commit is contained in:
1 parent
1bae77ec84
commit
aae4db01ad
2 files changed
+25
-18
No files matched your search
@@ -12,4 +12,4 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define MONTAUK_BUILD_NUMBER 25
|
#define MONTAUK_BUILD_NUMBER 26
|
||||||
@@ -391,19 +391,33 @@ static void relayout() {
|
|||||||
int order[MAX_ENTRIES];
|
int order[MAX_ENTRIES];
|
||||||
int count = 0;
|
int count = 0;
|
||||||
if (searching()) {
|
if (searching()) {
|
||||||
|
// Results are grouped by category like All Settings: the group holding
|
||||||
|
// the best match comes first, and matches within a group by score, so
|
||||||
|
// the first tile is still the best match.
|
||||||
int scores[MAX_ENTRIES];
|
int scores[MAX_ENTRIES];
|
||||||
|
int cat_best[MAX_CATEGORIES];
|
||||||
|
for (int i = 0; i < g_category_count; i++) cat_best[i] = -1;
|
||||||
for (int e = 0; e < g_entry_count; e++) {
|
for (int e = 0; e < g_entry_count; e++) {
|
||||||
int s = match_score(e);
|
scores[e] = match_score(e);
|
||||||
if (s < 0) continue;
|
int cat = g_entries[e].category;
|
||||||
// Insertion by score; entries are already in category/name order.
|
if (scores[e] >= 0 && (cat_best[cat] < 0 || scores[e] < cat_best[cat]))
|
||||||
|
cat_best[cat] = scores[e];
|
||||||
|
}
|
||||||
|
auto before = [&](int a, int b) {
|
||||||
|
int ca = g_entries[a].category, cb = g_entries[b].category;
|
||||||
|
if (cat_best[ca] != cat_best[cb]) return cat_best[ca] < cat_best[cb];
|
||||||
|
if (ca != cb) return ca < cb;
|
||||||
|
return scores[a] < scores[b];
|
||||||
|
};
|
||||||
|
for (int e = 0; e < g_entry_count; e++) {
|
||||||
|
if (scores[e] < 0) continue;
|
||||||
|
// Insertion; entries are already in category/name order.
|
||||||
int j = count++;
|
int j = count++;
|
||||||
while (j > 0 && scores[j - 1] > s) {
|
while (j > 0 && before(e, order[j - 1])) {
|
||||||
order[j] = order[j - 1];
|
order[j] = order[j - 1];
|
||||||
scores[j] = scores[j - 1];
|
|
||||||
j--;
|
j--;
|
||||||
}
|
}
|
||||||
order[j] = e;
|
order[j] = e;
|
||||||
scores[j] = s;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int e = 0; e < g_entry_count; e++)
|
for (int e = 0; e < g_entry_count; e++)
|
||||||
@@ -415,7 +429,7 @@ static void relayout() {
|
|||||||
int cols = (body.w + TILE_GAP) / (TILE_MIN_W + TILE_GAP);
|
int cols = (body.w + TILE_GAP) / (TILE_MIN_W + TILE_GAP);
|
||||||
if (cols < 1) cols = 1;
|
if (cols < 1) cols = 1;
|
||||||
int tile_w = (body.w - (cols - 1) * TILE_GAP) / cols;
|
int tile_w = (body.w - (cols - 1) * TILE_GAP) / cols;
|
||||||
bool grouped = !searching() && g_category == CAT_ALL;
|
bool grouped = searching() || g_category == CAT_ALL;
|
||||||
|
|
||||||
g_placed_count = 0;
|
g_placed_count = 0;
|
||||||
int y = HEADER_H, col = 0, prev_cat = -1;
|
int y = HEADER_H, col = 0, prev_cat = -1;
|
||||||
@@ -632,22 +646,15 @@ static void draw_tile(Canvas& c, int i, const mtk::Theme& theme) {
|
|||||||
int text_w = r.w - (tx - r.x) - 14;
|
int text_w = r.w - (tx - r.x) - 14;
|
||||||
int name_y = r.y + (r.h - fh * 2 - 2) / 2;
|
int name_y = r.y + (r.h - fh * 2 - 2) / 2;
|
||||||
|
|
||||||
// Name, then the description (led by the category when the results mix
|
// Name, then the description.
|
||||||
// categories).
|
|
||||||
char name[48];
|
char name[48];
|
||||||
fit_text(item.name, name, sizeof(name), text_w,
|
fit_text(item.name, name, sizeof(name), text_w,
|
||||||
fonts::system_bold ? fonts::system_bold : fonts::system_font, fonts::UI_SIZE);
|
fonts::system_bold ? fonts::system_bold : fonts::system_font, fonts::UI_SIZE);
|
||||||
draw_bold(c, tx, name_y, name, theme.text, fonts::UI_SIZE);
|
draw_bold(c, tx, name_y, name, theme.text, fonts::UI_SIZE);
|
||||||
|
|
||||||
char line[128];
|
|
||||||
if (searching())
|
|
||||||
snprintf(line, sizeof(line), "%s%s%s", g_categories[g_entries[e].category].name,
|
|
||||||
item.description[0] ? " - " : "", item.description);
|
|
||||||
else
|
|
||||||
montauk::strncpy(line, item.description[0] ? item.description : "Open settings",
|
|
||||||
sizeof(line));
|
|
||||||
char desc[128];
|
char desc[128];
|
||||||
fit_text(line, desc, sizeof(desc), text_w);
|
fit_text(item.description[0] ? item.description : "Open settings", desc, sizeof(desc),
|
||||||
|
text_w);
|
||||||
c.text(tx, name_y + fh + 2, desc, theme.text_subtle);
|
c.text(tx, name_y + fh + 2, desc, theme.text_subtle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user