summaryrefslogtreecommitdiff
path: root/src/fruits/cmc/ui
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2025-04-08 19:29:43 -0400
committerAndrew Opalach <andrew@akon.city> 2025-04-08 19:29:43 -0400
commit832b3ab11fd6457c59aed9d5bf12ba40c117f15d (patch)
tree5d2d80755553fb2a7d71fd735f9566ba1997b3db /src/fruits/cmc/ui
parenta6d104090ef752126766ef237db1ff1dc6b966f0 (diff)
downloadcamu-832b3ab11fd6457c59aed9d5bf12ba40c117f15d.tar.gz
camu-832b3ab11fd6457c59aed9d5bf12ba40c117f15d.tar.bz2
camu-832b3ab11fd6457c59aed9d5bf12ba40c117f15d.zip
More cmc ui tweaking
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/fruits/cmc/ui')
-rw-r--r--src/fruits/cmc/ui/pane_list.c114
-rw-r--r--src/fruits/cmc/ui/ui.c2
2 files changed, 84 insertions, 32 deletions
diff --git a/src/fruits/cmc/ui/pane_list.c b/src/fruits/cmc/ui/pane_list.c
index 557f5f3..695ff60 100644
--- a/src/fruits/cmc/ui/pane_list.c
+++ b/src/fruits/cmc/ui/pane_list.c
@@ -1,6 +1,7 @@
#include <nnwt/thread.h>
#include "../../liana/list.h"
+#include "../../sink/util.h"
#include "../cmc.h"
@@ -232,53 +233,104 @@ static void render_list_entries(struct cmc_ui *ui, struct cmc_list_tab *tab, s32
static void render_now_playing(struct cmc_ui *ui, struct cmc_list_tab *tab, u32 y, u32 height)
{
- u32 width = ncplane_dim_x(ui->lp.n);
- if (tab && tab->list->entries.count > 0) {
- struct cmc_list *list = tab->list;
- struct cmc_list_entry *entry = al_array_at(list->entries, list->current);
- f32 percent = 1.0;
- if (entry->duration > 0) {
- u64 pos = entry->offset;
- u64 now = nn_get_timestamp();
- if (entry->start != LIANA_TIMESTAMP_INVALID && now > entry->start) {
- pos += now - entry->start;
- }
- percent = MIN(pos / (f32)entry->duration, 1.f);
+ struct ncplane *n = ui->lp.n;
+ u32 width = ncplane_dim_x(n);
+
+ struct cmc_list_entry *entry = NULL;
+ if (tab->list->entries.count > (u32)tab->list->current) {
+ entry = al_array_at(tab->list->entries, tab->list->current);
+ }
+
+ u64 pos = 0;
+ u64 duration = 0;
+ u64 remaining = 0;
+ u32 y_off = height - 6;
+
+ ncplane_set_styles(n, NCSTYLE_BOLD);
+ if (entry) {
+ pos = entry->offset;
+ duration = entry->duration;
+ u64 now = nn_get_timestamp();
+ bool paused = entry->start == LIANA_TIMESTAMP_INVALID;
+ if (!paused && now > entry->start) {
+ pos += now - entry->start;
}
- for (u32 i = 0; i < (width - 2) * percent; i++) {
- ncplane_putchar_yx(ui->lp.n, height - 6, i + 1, '-');
+ pos = MIN(pos, duration);
+ remaining = duration - pos;
+ //ncplane_putstr_yx(n, y_off, 2, "▸");
+ //ncplane_putstr_yx(n, y_off, 2, "▶");
+ //ncplane_putstr_yx(n, y_off, 2, "⏵ ");
+ //ncplane_putstr_yx(n, y_off, 2, "|");
+ //ncplane_putstr_yx(n, y_off, 2, "|");
+ //ncplane_putstr_yx(n, y_off, 2, "⏵");
+ //ncplane_putstr_yx(n, y_off, 2, "⏸");
+ if (remaining == 0) {
+ ncplane_putstr_yx(n, y_off - 1, 2, "∨");
+ } else {
+ ncplane_putstr_yx(n, y_off - 1, 2, paused ? "^": ">");
}
- cmc_ui_putnwstr_yx(ui->lp.n, height - 7, 2, entry->name.length, &entry->name);
+ } else {
+ ncplane_putstr_yx(n, y_off - 1, 2, "∨");
+ }
+ ncplane_set_styles(n, NCSTYLE_NONE);
+
+ f32 percent = 1.f;
+ if (duration > 0) percent = MIN(pos / (f32)duration, 1.f);
+ for (u32 i = 0; i < (width - 2) * percent; i++) {
+ ncplane_putchar_yx(n, y_off, i + 1, '-');
+ }
+
+ y_off--;
+
+ char timestr[16] = { 0 }; // max = 829128280:01:49\0
+ s32 offset = camu_print_time(timestr, sizeof(timestr), pos, true, 4);
+ ncplane_putstr_yx(n, y_off, 4, timestr);
+ ncplane_putstr_yx(n, y_off, 4 + offset, "⎹");
+
+ if (entry) {
+ cmc_ui_putnwstr_yx(n, y_off, 6 + offset, MIN(entry->name.length, (u32)40), &entry->name);
+ }
+
+ bool show_remaining = true;
+ if (show_remaining) {
+ offset = camu_print_time(timestr, sizeof(timestr), remaining, true, 4);
+ } else {
+ offset = camu_print_time(timestr, sizeof(timestr), duration, true, 4);
}
- ncplane_putchar_yx(ui->lp.n, height - 5, 2, 'A');
- ncplane_putchar_yx(ui->lp.n, height - 4, 2, 'A');
- ncplane_putchar_yx(ui->lp.n, height - 3, 2, 'A');
- ncplane_putchar_yx(ui->lp.n, height - 2, 2, 'A');
+ ncplane_putstr_yx(n, y_off, width - 4 - offset, "⎸");
+ // "=" Duration, "+" Segment, "-" Remaining.
+ if (show_remaining) {
+ ncplane_putstr_yx(n, y_off, width - 3 - offset, "-");
+ } else {
+ ncplane_putstr_yx(n, y_off, width - 3 - offset, "=");
+ }
+ ncplane_putstr_yx(n, y_off, width - 2 - offset, timestr);
+
+ ncplane_putchar_yx(n, height - 5, 2, 'A');
+ ncplane_putchar_yx(n, height - 4, 2, 'A');
+ ncplane_putchar_yx(n, height - 3, 2, 'A');
+ ncplane_putchar_yx(n, height - 2, 2, 'A');
+
/*
char buf[24];
al_snprintf(buf, sizeof(buf), "%u, %u | %u, %u", ui->last_mouse_x, ui->last_mouse_y, width, height);
- ncplane_putstr_yx(ui->lp.n, height - 5, 1, buf);
+ ncplane_putstr_yx(n, height - 5, 5, buf);
*/
+
u64 c = 0;
ncchannels_set_fg_default(&c);
- ncplane_cursor_move_yx(ui->lp.n, y, 0);
- ncplane_light_box(ui->lp.n, NCSTYLE_NONE, c, height - 1, width - 1, 0);
+ ncplane_cursor_move_yx(n, y, 0);
+ ncplane_light_box(n, NCSTYLE_NONE, c, height - 1, width - 1, 0);
}
void cmc_lp_render(struct cmc_ui *ui)
{
u32 height = ncplane_dim_y(ui->lp.n);
- struct cmc_list_tab *tab = NULL;
- if (ui->lp.tabs.count > 0) {
- tab = &al_array_at(ui->lp.tabs, ui->lp.current);
- }
+ if (ui->lp.tabs.count <= ui->lp.current) return;
+ struct cmc_list_tab *tab = &al_array_at(ui->lp.tabs, ui->lp.current);
tab->page_length = height - 8;
-
- if (tab) {
- render_list_entries(ui, tab, tab->page_length);
- }
-
+ render_list_entries(ui, tab, tab->page_length);
render_now_playing(ui, tab, tab->page_length, height);
}
diff --git a/src/fruits/cmc/ui/ui.c b/src/fruits/cmc/ui/ui.c
index bd76e56..10357c0 100644
--- a/src/fruits/cmc/ui/ui.c
+++ b/src/fruits/cmc/ui/ui.c
@@ -244,7 +244,7 @@ bool cmc_ui_init(struct cmc_ui *ui, struct nn_event_loop *loop, struct cmc *c)
nn_poll_start(&ui->input_poll, ui->loop);
nn_timer_init(&ui->render_timer, ui->loop, render_timer_callback, ui);
- nn_timer_set_repeat(&ui->render_timer, NNWT_TS_FROM_USEC(300000));
+ nn_timer_set_repeat(&ui->render_timer, NNWT_TS_FROM_USEC(200000));
nn_timer_again(&ui->render_timer);
return true;