summaryrefslogtreecommitdiff
path: root/src/fruits/cmc/ui/panes/list.c
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2026-08-26 17:58:15 -0400
committerAndrew Opalach <andrew@akon.city> 2026-08-26 17:58:15 -0400
commitb112da5b9825262b3b779bd699a4cf4bca8b6d01 (patch)
tree7742d66d3aac6bc007c638377f81da738e9886be /src/fruits/cmc/ui/panes/list.c
parent197d41a3e23cab35848f623c6133baccc62aacbe (diff)
downloadcamu-b112da5b9825262b3b779bd699a4cf4bca8b6d01.tar.gz
camu-b112da5b9825262b3b779bd699a4cf4bca8b6d01.tar.bz2
camu-b112da5b9825262b3b779bd699a4cf4bca8b6d01.zip
Rough cmc UI tweaking
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/fruits/cmc/ui/panes/list.c')
-rw-r--r--src/fruits/cmc/ui/panes/list.c57
1 files changed, 55 insertions, 2 deletions
diff --git a/src/fruits/cmc/ui/panes/list.c b/src/fruits/cmc/ui/panes/list.c
index b599cc5..388e22f 100644
--- a/src/fruits/cmc/ui/panes/list.c
+++ b/src/fruits/cmc/ui/panes/list.c
@@ -226,11 +226,36 @@ void cmc_list_pane_clear(struct cmc_list_pane *lp)
cmc_now_playing_clear(&lp->np);
}
+static u32 count_headers(struct cmc_list *list)
+{
+ struct cmc_list_entry *entry;
+ str header = AL_STR_EMPTY;
+ u32 count = 0;
+ al_array_foreach(list->entries, i, entry) {
+ u32 rslash = al_str_rfind(&entry->brief, '/');
+ str remain = al_str_substr(&entry->brief, 0, rslash);
+ rslash = al_str_rfind(&remain, '/');
+ str new_header;
+ if (rslash != AL_STR_NO_POS) {
+ new_header = al_str_substr(&remain, rslash + 1, remain.length);
+ } else {
+ new_header = remain;
+ }
+ if (al_str_is_empty(&header) || !al_str_eq(&header, &new_header)) {
+ header = new_header;
+ count++;
+ }
+ }
+ return count;
+}
+
static void render_list_entries(struct cmc_list_pane *lp, struct cmc_list_tab *tab, s32 max_height)
{
struct cmc_list *list = tab->list;
struct ncplane *n = lp->n;
s32 tracked = tab->move.active ? tab->move.selected + tab->move.offset : tab->selected;
+ u32 headers = count_headers(list);
+ max_height -= headers;
s32 count = (s32)list->entries.count;
s32 midpoint = max_height / 2;
s32 rounded = (max_height + 1) / 2;
@@ -245,6 +270,9 @@ static void render_list_entries(struct cmc_list_pane *lp, struct cmc_list_tab *t
top = tracked - midpoint;
end = tracked + rounded;
}
+ str header = AL_STR_EMPTY;
+ s32 last_y = 0;
+ s32 y_offset = 0;
s32 index;
struct cmc_list_entry *entry;
for (s32 i = top; i < end; i++) {
@@ -258,14 +286,39 @@ static void render_list_entries(struct cmc_list_pane *lp, struct cmc_list_tab *t
}
}
entry = al_array_at(list->entries, index);
+ u32 rslash = al_str_rfind(&entry->brief, '/');
+ str part;
+ if (rslash != AL_STR_NO_POS) {
+ part = al_str_substr(&entry->brief, rslash + 1, entry->brief.length);
+ } else {
+ part = entry->brief;
+ }
+ str remain = al_str_substr(&entry->brief, 0, rslash);
+ rslash = al_str_rfind(&remain, '/');
+ str new_header;
+ if (rslash != AL_STR_NO_POS) {
+ new_header = al_str_substr(&remain, rslash + 1, remain.length);
+ } else {
+ new_header = remain;
+ }
+ if (al_str_is_empty(&header) || !al_str_eq(&header, &new_header)) {
+ header = new_header;
+ char *c_str = al_str_to_c_str(&header);
+ ncplane_set_styles(n, NCSTYLE_BOLD);
+ ncplane_putstr_yx(n, last_y, 0, c_str);
+ ncplane_set_styles(n, NCSTYLE_NONE);
+ al_free(c_str);
+ y_offset++;
+ }
bool on_current = list->current >= 0 && index == list->current;
bool styled = i == tracked;
if (styled) {
ncplane_set_styles(n, NCSTYLE_BOLD);
ncplane_set_fg_palindex(n, 4);
}
- s32 y = i - top;
- char *c_str = al_str_to_c_str(&entry->brief);
+ s32 y = i - top + y_offset;
+ last_y = y + 1;
+ char *c_str = al_str_to_c_str(&part);
if (tab->move.active && i == tracked) {
ncplane_putstr_yx(n, y, 0, c_str);
} else if (on_current) {