From 04706a991dbd2ea694f8c7dab3ae27a0b54fdbc0 Mon Sep 17 00:00:00 2001 From: "tanguy.cavagna" <tanguy.cavagna@etu.hesge.ch> Date: Thu, 12 May 2022 11:09:19 +0200 Subject: [PATCH] Menu resize on load --- ui/ui.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/ui/ui.c b/ui/ui.c index e27d45c..1ac6ac4 100644 --- a/ui/ui.c +++ b/ui/ui.c @@ -23,6 +23,21 @@ void set_colors() { init_pair(RED_PAIR, COLOR_RED, COLOR_BLACK); } +/** + * @brief Is the window too small + * + * @return true + * @return false + */ +bool window_too_small() { return (LINES < MENU_CHOICE_Y_OFFSET + MENU_MAX + 10); } + +/** + * @brief Modify the menu offset depending on the window size + * + * @return int + */ +int menu_offset_modifer() { return (window_too_small() ? 15 : 0); } + /** * @brief Get the selected menu choice * @@ -38,7 +53,7 @@ void draw_menu(int menu_item) { if (i == MENU_QUIT) attron(COLOR_PAIR(RED_PAIR)); - printw_center(menu_choices[i], MENU_CHOICE_Y_OFFSET + (i * 2)); + printw_center(menu_choices[i], MENU_CHOICE_Y_OFFSET + (i * 2) - menu_offset_modifer()); attroff(COLOR_PAIR(WHITE_PAIR)); attroff(A_STANDOUT); } @@ -103,18 +118,20 @@ int show_menu() { "\\__/ \\__| \\______/ \\__| \\__|\\_______/ \\________|\\________|"}; // Title print - for (int i = 0; i < 8; i++) - printw_center(title[i], i + TITLE_Y_OFFSET); + if (!window_too_small()) { + for (int i = 0; i < 8; i++) + printw_center(title[i], i + TITLE_Y_OFFSET); + } // Menu print attron(COLOR_PAIR(GREEN_PAIR)); attron(A_BOLD); - printw_center("====== MENU ======", MENU_CHOICE_Y_OFFSET - 3); + printw_center("====== MENU ======", MENU_CHOICE_Y_OFFSET - 3 - menu_offset_modifer()); attroff(A_BOLD); attron(COLOR_PAIR(WHITE_PAIR)); attron(A_DIM); - printw_center("Use arrow keys to move; Enter to chose", MENU_CHOICE_Y_OFFSET + 10); + printw_center("Use arrow keys to move; Enter to chose", MENU_CHOICE_Y_OFFSET + 10 - menu_offset_modifer()); attroff(A_DIM); // Menu choices handler -- GitLab