fix: split search results in Settings by category

This commit is contained in:
daniel committed 2026-10-24 21:32:22 +02:00
1 parent 1bae77ec84
commit aae4db01ad
2 files changed
+25 -18

No files matched your search

+1 -1
View File
@@ -12,4 +12,4 @@
#pragma once
#define MONTAUK_BUILD_NUMBER 25
#define MONTAUK_BUILD_NUMBER 26
+24 -17
View File
@@ -391,19 +391,33 @@ static void relayout() {
int order[MAX_ENTRIES];
int count = 0;
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 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++) {
int s = match_score(e);
if (s < 0) continue;
// Insertion by score; entries are already in category/name order.
scores[e] = match_score(e);
int cat = g_entries[e].category;
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++;
while (j > 0 && scores[j - 1] > s) {
while (j > 0 && before(e, order[j - 1])) {
order[j] = order[j - 1];
scores[j] = scores[j - 1];
j--;
}
order[j] = e;
scores[j] = s;
}
} else {
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);
if (cols < 1) cols = 1;
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;
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 name_y = r.y + (r.h - fh * 2 - 2) / 2;
// Name, then the description (led by the category when the results mix
// categories).
// Name, then the description.
char name[48];
fit_text(item.name, name, sizeof(name), text_w,
fonts::system_bold ? fonts::system_bold : fonts::system_font, 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];
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);
}