From 48e6f641436ccdcb0395f3daa8dadb701bf821fa Mon Sep 17 00:00:00 2001 From: Alex Duchesne Date: Wed, 25 Jan 2023 16:44:25 -0500 Subject: [PATCH] Launcher: Added alternative scroll mode/behavior (#77) --- launcher/main/gui.c | 23 ++++++++++++++++++----- launcher/main/gui.h | 8 ++++++++ launcher/main/main.c | 17 +++++++++++++++++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/launcher/main/gui.c b/launcher/main/gui.c index 319083217..f1373dbdf 100644 --- a/launcher/main/gui.c +++ b/launcher/main/gui.c @@ -29,6 +29,7 @@ retro_gui_t gui; #define SETTING_THEME "Theme" #define SETTING_COLOR_THEME "ColorTheme" #define SETTING_SHOW_PREVIEW "ShowPreview" +#define SETTING_SCROLL_MODE "ScrollMode" #define SETTING_HIDDEN_TABS "HiddenTabs" #define SETTING_HIDE_TAB(name) strcat((char[99]){"HideTab."}, (name)) @@ -48,6 +49,7 @@ void gui_init(void) .color_theme = rg_settings_get_number(NS_APP, SETTING_COLOR_THEME, 0), .start_screen = rg_settings_get_number(NS_APP, SETTING_START_SCREEN, START_SCREEN_AUTO), .show_preview = rg_settings_get_number(NS_APP, SETTING_SHOW_PREVIEW, PREVIEW_MODE_SAVE_COVER), + .scroll_mode = rg_settings_get_number(NS_APP, SETTING_SCROLL_MODE, SCROLL_MODE_CENTER), .width = rg_display_get_info()->screen.width, .height = rg_display_get_info()->screen.height, }; @@ -226,6 +228,7 @@ void gui_save_config(void) rg_settings_set_number(NS_APP, SETTING_SELECTED_TAB, gui.selected_tab); rg_settings_set_number(NS_APP, SETTING_START_SCREEN, gui.start_screen); rg_settings_set_number(NS_APP, SETTING_SHOW_PREVIEW, gui.show_preview); + rg_settings_set_number(NS_APP, SETTING_SCROLL_MODE, gui.scroll_mode); rg_settings_set_number(NS_APP, SETTING_COLOR_THEME, gui.color_theme); rg_settings_set_number(NS_APP, SETTING_STARTUP_MODE, gui.startup_mode); rg_settings_set_string(NS_APP, SETTING_HIDDEN_TABS, gui.hidden_tabs); @@ -326,15 +329,15 @@ void gui_scroll_list(tab_t *tab, scroll_whence_t mode, int arg) } else if (mode == SCROLL_PAGE) { - int start = list->items[cur_cursor].text[0]; + // int start = list->items[cur_cursor].text[0]; int direction = arg > 0 ? 1 : -1; - for (int max = max_visible_lines(tab, NULL) - 2; max > 0; --max) + for (int max = max_visible_lines(tab, NULL); max > 0; --max) { cur_cursor += direction; if (cur_cursor < 0 || cur_cursor >= list->length) break; - if (start != list->items[cur_cursor].text[0]) - break; + // if (start != list->items[cur_cursor].text[0]) + // break; } } @@ -448,6 +451,7 @@ void gui_draw_list(tab_t *tab) const listbox_t *list = &tab->listbox; int line_height, top = HEADER_HEIGHT + 6; int lines = max_visible_lines(tab, &line_height); + int line_offset = 0; if (tab->navpath) { @@ -458,9 +462,18 @@ void gui_draw_list(tab_t *tab) top += ((gui.height - top) - (lines * line_height)) / 2; + if (gui.scroll_mode == SCROLL_MODE_PAGING) + { + line_offset = (list->cursor / lines) * lines; + } + else // (gui.scroll_mode == SCROLL_MODE_CENTER) + { + line_offset = list->cursor - (lines / 2); + } + for (int i = 0; i < lines; i++) { - int idx = list->cursor + i - (lines / 2); + int idx = line_offset + i; int selected = idx == list->cursor; char *label = (idx >= 0 && idx < list->length) ? list->items[idx].text : ""; top += rg_gui_draw_text(0, top, gui.width, label, fg[selected], bg[selected], 0).height; diff --git a/launcher/main/gui.h b/launcher/main/gui.h index 274aa6a37..5bad88a8f 100644 --- a/launcher/main/gui.h +++ b/launcher/main/gui.h @@ -10,6 +10,13 @@ typedef enum { START_SCREEN_COUNT, } start_screen_t; +typedef enum { + SCROLL_MODE_CENTER, + SCROLL_MODE_PAGING, + // SCROLL_MODE_EDGE, + SCROLL_MODE_COUNT, +} scroll_mode_t; + typedef enum { TAB_ACTION, TAB_BACK, @@ -117,6 +124,7 @@ typedef struct { int color_theme; int start_screen; int show_preview; + int scroll_mode; int width; int height; image_t images[128]; diff --git a/launcher/main/main.c b/launcher/main/main.c index 92de7ccc2..1ed715be7 100644 --- a/launcher/main/main.c +++ b/launcher/main/main.c @@ -52,6 +52,22 @@ static rg_gui_event_t toggle_tabs_cb(rg_gui_option_t *option, rg_gui_event_t eve return RG_DIALOG_VOID; } +static rg_gui_event_t scroll_mode_cb(rg_gui_option_t *option, rg_gui_event_t event) +{ + const char *modes[SCROLL_MODE_COUNT] = {"Center", "Paging"}; + const int max = SCROLL_MODE_COUNT - 1; + + if (event == RG_DIALOG_PREV && --gui.scroll_mode < 0) + gui.scroll_mode = max; + if (event == RG_DIALOG_NEXT && ++gui.scroll_mode > max) + gui.scroll_mode = 0; + + gui.scroll_mode %= SCROLL_MODE_COUNT; + + strcpy(option->value, modes[gui.scroll_mode]); + return RG_DIALOG_VOID; +} + static rg_gui_event_t timezone_cb(rg_gui_option_t *option, rg_gui_event_t event) { if (event == RG_DIALOG_ENTER) @@ -153,6 +169,7 @@ static rg_gui_event_t launcher_options_cb(rg_gui_option_t *option, rg_gui_event_ { const rg_gui_option_t options[] = { {0, "Color theme ", "...", 1, &color_theme_cb}, + {0, "Scroll mode ", "...", 1, &scroll_mode_cb}, {0, "Preview ", "...", 1, &show_preview_cb}, {0, "Start screen", "...", 1, &start_screen_cb}, {0, "Hide tabs ", "...", 1, &toggle_tabs_cb},