From f181e3266233430bb41e7adc279c110a9be3ddc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Tue, 29 Jun 2021 16:21:02 +0200 Subject: [PATCH] feat: add text viewer better keyboard controls --- file-browser/src/file_execute.c | 2 +- text-viewer/src/text_viewer_handlers.c | 49 ++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/file-browser/src/file_execute.c b/file-browser/src/file_execute.c index c8e2e6cffeb958647e35dfb36f5de681a8df6adf..e0359a96431b1dbe8ff11901aebe629e3d7622e0 100644 --- a/file-browser/src/file_execute.c +++ b/file-browser/src/file_execute.c @@ -36,12 +36,12 @@ executing_file_error_t executing_file_execute(char *path, char *args) { execl(path, path, args, (char*)NULL); + // Is reached only in case of an error if (errno == EPERM) { fprintf(stderr, "Could not execute file: file is not executable\r\n"); exit(errno); } - // Is reached only in case of an error fprintf( stderr, "Could not execute file \"%s %s\": %s\r\n", path, args, fileaccess_get_error_text(file_operation_error_from_errno(errno))); diff --git a/text-viewer/src/text_viewer_handlers.c b/text-viewer/src/text_viewer_handlers.c index 161cff182c52e0b3bcd467647fff576edc67b24b..65ac7e75a029483dc4880dc4381045b564fba44a 100644 --- a/text-viewer/src/text_viewer_handlers.c +++ b/text-viewer/src/text_viewer_handlers.c @@ -1,5 +1,6 @@ #include "text_viewer_handlers.h" #include "direction.h" +#include "display_utils.h" #include "gui_component_text_view.h" #include "keyboard_const.h" #include "rotation_const.h" @@ -15,6 +16,22 @@ static void command_handler_move(void *state, direction_t direction, } } +static void command_handler_jump(void *state, direction_t direction, + int amount) { + component_t *text_view = (component_t *)state; + + if (direction == LEFT || direction == RIGHT) { + amount = DISPLAY_WIDTH * 0.6; + } else { + amount = DISPLAY_HEIGHT * 0.4; + } + + int32_t x = 0; + int32_t y = 0; + direction_move_xy(direction, &x, &y, amount); + gui_text_view_scroll(text_view, x, y); +} + static void command_handler_move_down(void *state, int amount) { command_handler_move(state, DOWN, amount); } @@ -30,6 +47,21 @@ static void command_handler_move_right(void *state, int amount) { command_handler_move(state, RIGHT, amount); } +static void command_handler_jump_up(void *state, int amount) { + command_handler_jump(state, UP, amount); +} + +static void command_handler_jump_down(void *state, int amount) { + command_handler_jump(state, DOWN, amount); +} + +static void command_handler_jump_right(void *state, int amount) { + command_handler_jump(state, RIGHT, amount); +} + +static void command_handler_jump_left(void *state, int amount) { + command_handler_jump(state, LEFT, amount); +} static void command_handler_reset(void *state, int amount) { gui_text_view_reset_scroll((component_t *)state); } @@ -77,11 +109,22 @@ void gui_text_view_register_commands(gui_t *gui, component_t *text_view) { command_handler_move_down, text_view); commands_register(gui->commands, IN_KEYBOARD, KEYBOARD_UP, command_handler_move_up, text_view); - commands_register(gui->commands, IN_KEYBOARD, 'r', command_handler_reset, + + commands_register(gui->commands, IN_KEYBOARD, KEYBOARD_JUMP_LEFT, + command_handler_jump_left, text_view); + commands_register(gui->commands, IN_KEYBOARD, KEYBOARD_JUMP_RIGHT, + command_handler_jump_right, text_view); + commands_register(gui->commands, IN_KEYBOARD, KEYBOARD_PAGE_DOWN, + command_handler_jump_down, text_view); + commands_register(gui->commands, IN_KEYBOARD, KEYBOARD_PAGE_UP, + command_handler_jump_up, text_view); + + commands_register(gui->commands, IN_KEYBOARD, KEYBOARD_HOME, command_handler_reset, text_view); - commands_register(gui->commands, IN_KEYBOARD, 't', + + commands_register(gui->commands, IN_KEYBOARD, KEYBOARD_END, command_handler_full_scroll, text_view); - commands_register(gui->commands, IN_KEYBOARD, 'f', + commands_register(gui->commands, IN_KEYBOARD, 'c', command_handler_zoom_reset, text_view); commands_register(gui->commands, IN_ENCODER_ROTATE,