From af54e6510f2f701db3b3a533514076c04cea4c66 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Wed, 30 Apr 2025 10:08:46 -0400 Subject: Separate erasing for re-render and clearing in tui Signed-off-by: Andrew Opalach --- src/fruits/cmc/ui/panes/list.c | 6 ++++-- src/fruits/cmc/ui/panes/list.h | 2 +- src/fruits/cmc/ui/panes/log.c | 4 +++- src/fruits/cmc/ui/panes/log.h | 2 +- src/fruits/cmc/ui/ui.c | 12 ++---------- src/fruits/cmc/ui/widgets/now_playing.c | 7 +++++++ src/fruits/cmc/ui/widgets/now_playing.h | 1 + src/fruits/cmc/ui/widgets/tile.h | 11 ++++++++++- 8 files changed, 29 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/fruits/cmc/ui/panes/list.c b/src/fruits/cmc/ui/panes/list.c index 0e853db..34e18f9 100644 --- a/src/fruits/cmc/ui/panes/list.c +++ b/src/fruits/cmc/ui/panes/list.c @@ -220,10 +220,10 @@ bool cmc_list_pane_tick(struct cmc_list_pane *lp) return tick; } -void cmc_list_pane_erase(struct cmc_list_pane *lp) +void cmc_list_pane_clear(struct cmc_list_pane *lp) { ncplane_erase(lp->n); - cmc_now_playing_erase(&lp->np); + cmc_now_playing_clear(&lp->np); } static void render_list_entries(struct cmc_list_pane *lp, struct cmc_list_tab *tab, s32 max_height) @@ -283,6 +283,8 @@ static void render_list_entries(struct cmc_list_pane *lp, struct cmc_list_tab *t void cmc_list_pane_render(struct cmc_list_pane *lp) { + ncplane_erase(lp->n); + cmc_now_playing_erase(&lp->np); if (lp->selected == -1) return; struct cmc_list_tab *tab = &al_array_at(lp->tabs, lp->selected); render_list_entries(lp, tab, lp->page_length); diff --git a/src/fruits/cmc/ui/panes/list.h b/src/fruits/cmc/ui/panes/list.h index bfeed59..3fb10f9 100644 --- a/src/fruits/cmc/ui/panes/list.h +++ b/src/fruits/cmc/ui/panes/list.h @@ -31,5 +31,5 @@ bool cmc_list_pane_layout(struct cmc_list_pane *lp, struct ncplane *parent); void cmc_list_pane_add_list(struct cmc_list_pane *lp, struct cmc_list *list); bool cmc_list_pane_handle_input(struct cmc_list_pane *lp, struct ncinput *input); bool cmc_list_pane_tick(struct cmc_list_pane *lp); -void cmc_list_pane_erase(struct cmc_list_pane *lp); +void cmc_list_pane_clear(struct cmc_list_pane *lp); void cmc_list_pane_render(struct cmc_list_pane *lp); diff --git a/src/fruits/cmc/ui/panes/log.c b/src/fruits/cmc/ui/panes/log.c index be9702c..370e91a 100644 --- a/src/fruits/cmc/ui/panes/log.c +++ b/src/fruits/cmc/ui/panes/log.c @@ -38,7 +38,7 @@ bool cmc_log_pane_tick(struct cmc_log_pane *lp) return false; } -void cmc_log_pane_erase(struct cmc_log_pane *lp) +void cmc_log_pane_clear(struct cmc_log_pane *lp) { ncplane_erase(lp->n); } @@ -47,6 +47,8 @@ void cmc_log_pane_render(struct cmc_log_pane *lp) { struct ncplane *n = lp->n; + ncplane_erase(n); + u32 max_height = ncplane_dim_y(n); u32 count = lp->messages.count; diff --git a/src/fruits/cmc/ui/panes/log.h b/src/fruits/cmc/ui/panes/log.h index d79c7e9..b647c89 100644 --- a/src/fruits/cmc/ui/panes/log.h +++ b/src/fruits/cmc/ui/panes/log.h @@ -14,5 +14,5 @@ bool cmc_log_pane_layout(struct cmc_log_pane *lp, struct ncplane *parent); void cmc_log_pane_push_message(struct cmc_log_pane *lp, char *message); bool cmc_log_pane_handle_input(struct cmc_log_pane *lp, struct ncinput *input); bool cmc_log_pane_tick(struct cmc_log_pane *lp); -void cmc_log_pane_erase(struct cmc_log_pane *lp); +void cmc_log_pane_clear(struct cmc_log_pane *lp); void cmc_log_pane_render(struct cmc_log_pane *lp); diff --git a/src/fruits/cmc/ui/ui.c b/src/fruits/cmc/ui/ui.c index 7a0d8a1..a5d9125 100644 --- a/src/fruits/cmc/ui/ui.c +++ b/src/fruits/cmc/ui/ui.c @@ -39,10 +39,10 @@ static void erase_previous_pane(struct cmc_ui *ui, u8 previous, u8 upcoming) { switch (previous) { case CMC_PANE_LIST: - cmc_list_pane_erase(&ui->lists); + cmc_list_pane_clear(&ui->lists); break; case CMC_PANE_LOG: - cmc_log_pane_erase(&ui->log); + cmc_log_pane_clear(&ui->log); break; } switch (upcoming) { @@ -69,14 +69,6 @@ void cmc_ui_queue_render(struct cmc_ui *ui) { //ncplane_erase(ui->n); - switch (ui->pane) { - case CMC_PANE_LIST: - cmc_list_pane_erase(&ui->lists); - break; - case CMC_PANE_LOG: - cmc_log_pane_erase(&ui->log); - } - if (ui->overlay_shown) ncplane_erase(ui->oln); switch (ui->pane) { diff --git a/src/fruits/cmc/ui/widgets/now_playing.c b/src/fruits/cmc/ui/widgets/now_playing.c index 845a572..ebb8361 100644 --- a/src/fruits/cmc/ui/widgets/now_playing.c +++ b/src/fruits/cmc/ui/widgets/now_playing.c @@ -80,6 +80,13 @@ void cmc_now_playing_erase(struct cmc_now_playing *np) ncplane_erase(np->n); } +void cmc_now_playing_clear(struct cmc_now_playing *np) +{ + cmc_now_playing_erase(np); + ncplane_erase(np->wave); + np->blitted = NULL; +} + void cmc_now_playing_render(struct cmc_now_playing *np, struct cmc_list_entry *entry) { u64 duration = 0, pos = 0; diff --git a/src/fruits/cmc/ui/widgets/now_playing.h b/src/fruits/cmc/ui/widgets/now_playing.h index 5993c59..5c89940 100644 --- a/src/fruits/cmc/ui/widgets/now_playing.h +++ b/src/fruits/cmc/ui/widgets/now_playing.h @@ -22,4 +22,5 @@ void cmc_now_playing_init(struct cmc_now_playing *np); bool cmc_now_playing_layout(struct cmc_now_playing *np, struct ncplane *parent, u32 y); bool cmc_now_playing_tick(struct cmc_now_playing *np, struct cmc_list_entry *entry); void cmc_now_playing_erase(struct cmc_now_playing *np); +void cmc_now_playing_clear(struct cmc_now_playing *np); void cmc_now_playing_render(struct cmc_now_playing *np, struct cmc_list_entry *entry); diff --git a/src/fruits/cmc/ui/widgets/tile.h b/src/fruits/cmc/ui/widgets/tile.h index 6f15c7d..a410207 100644 --- a/src/fruits/cmc/ui/widgets/tile.h +++ b/src/fruits/cmc/ui/widgets/tile.h @@ -1,5 +1,14 @@ #pragma once -struct cmc_tile { +/* + Use-case examples: + - Twitter timeline type. + - Image grid (static/dynamic size, with or without title). + + Implementation: + - Tile sets it's own size. + - Reel. +*/ +struct cmc_tile { }; -- cgit v1.2.3-101-g0448