Skip to content

Commit

Permalink
Launcher: Added alternative scroll mode/behavior (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
ducalex committed Jan 25, 2023
1 parent 0077954 commit 48e6f64
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
23 changes: 18 additions & 5 deletions launcher/main/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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,
};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions launcher/main/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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];
Expand Down
17 changes: 17 additions & 0 deletions launcher/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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},
Expand Down

0 comments on commit 48e6f64

Please sign in to comment.