From 7936c07b4100895c412e6068e5905ac0c6e44938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Sun, 27 Jun 2021 15:35:30 +0200 Subject: [PATCH] feat: add text zoom to file browser --- file-browser/include/gui_list_commands.h | 2 ++ file-browser/src/gui_list_commands.c | 25 ++++++++++++++++++++++++ file-browser/src/window_initial.c | 1 + 3 files changed, 28 insertions(+) diff --git a/file-browser/include/gui_list_commands.h b/file-browser/include/gui_list_commands.h index 92d1f401342de8c319e93b936324d8cdc2741ba9..59d85761d4026c9e930d64f746e507fd98a3b9ce 100644 --- a/file-browser/include/gui_list_commands.h +++ b/file-browser/include/gui_list_commands.h @@ -11,6 +11,8 @@ typedef struct { void *state; container_t *container; + font_t *font; + gui_t *gui; window_t *window; } gui_list_command_state_t; diff --git a/file-browser/src/gui_list_commands.c b/file-browser/src/gui_list_commands.c index c1d45369dc5a32b784fe4a3b72a912d6226a3b09..d25006154e6dfc3a4eef1d62f06f51021f0ec468 100644 --- a/file-browser/src/gui_list_commands.c +++ b/file-browser/src/gui_list_commands.c @@ -13,6 +13,22 @@ static void command_handler_gui_list_clicked(void *state, int amount) { } } +static void command_handler_zoom_in(void *state, + int amount) { + gui_list_command_state_t *click_state = (gui_list_command_state_t *)state; + if (click_state->window == click_state->gui->active_window && + click_state->font != NULL && amount != 0) { + click_state->font->size += amount > 0 ? 1 : -1; + gui_list_container_set_item_height(click_state->container, + click_state->font->size); + } +} + +static void command_handler_zoom_out(void *state, + int amount) { + command_handler_zoom_in(state, -amount); +} + static void command_handler_move(void *state, direction_t direction, int amount) { gui_list_command_state_t *click_state = (gui_list_command_state_t *)state; if (click_state->window == click_state->gui->active_window) { @@ -54,4 +70,13 @@ void gui_list_commands_register(commands_t *commands, gui_list_command_state_t * command_handler_move_right, state); commands_register(commands, IN_ENCODER_ROTATE, ROTATION_ENCODER_VERTICAL, command_handler_move_down, state); + + if (state->font != NULL) { + commands_register(commands, IN_KEYBOARD, KEYBOARD_ZOOM_IN, + command_handler_zoom_in, state); + commands_register(commands, IN_KEYBOARD, KEYBOARD_ZOOM_OUT, + command_handler_zoom_out, state); + commands_register(commands, IN_ENCODER_ROTATE, ROTATION_ENCODER_ZOOM, + command_handler_zoom_in, state); + } } diff --git a/file-browser/src/window_initial.c b/file-browser/src/window_initial.c index aad21606882b9db91a0d3aee5062507615fcf2f6..ecbc2227f55dc7e5b16f9096b5f6cada6ac71789 100644 --- a/file-browser/src/window_initial.c +++ b/file-browser/src/window_initial.c @@ -114,6 +114,7 @@ static void *initial_window_construct(window_t *window, void *state) { istate->click_state.container = istate->list_container; istate->click_state.state = state; istate->click_state.clicked = initial_window_item_clicked; + istate->click_state.font = &istate->font; istate->click_state.gui = istate->gui; istate->click_state.window = window;