Skip to content
Snippets Groups Projects
Commit 04706a99 authored by tanguy.cavagna's avatar tanguy.cavagna :desktop:
Browse files

Menu resize on load

parent 723e7da2
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,21 @@ void set_colors() { ...@@ -23,6 +23,21 @@ void set_colors() {
init_pair(RED_PAIR, COLOR_RED, COLOR_BLACK); 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 * @brief Get the selected menu choice
* *
...@@ -38,7 +53,7 @@ void draw_menu(int menu_item) { ...@@ -38,7 +53,7 @@ void draw_menu(int menu_item) {
if (i == MENU_QUIT) if (i == MENU_QUIT)
attron(COLOR_PAIR(RED_PAIR)); 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(COLOR_PAIR(WHITE_PAIR));
attroff(A_STANDOUT); attroff(A_STANDOUT);
} }
...@@ -103,18 +118,20 @@ int show_menu() { ...@@ -103,18 +118,20 @@ int show_menu() {
"\\__/ \\__| \\______/ \\__| \\__|\\_______/ \\________|\\________|"}; "\\__/ \\__| \\______/ \\__| \\__|\\_______/ \\________|\\________|"};
// Title print // Title print
for (int i = 0; i < 8; i++) if (!window_too_small()) {
printw_center(title[i], i + TITLE_Y_OFFSET); for (int i = 0; i < 8; i++)
printw_center(title[i], i + TITLE_Y_OFFSET);
}
// Menu print // Menu print
attron(COLOR_PAIR(GREEN_PAIR)); attron(COLOR_PAIR(GREEN_PAIR));
attron(A_BOLD); 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); attroff(A_BOLD);
attron(COLOR_PAIR(WHITE_PAIR)); attron(COLOR_PAIR(WHITE_PAIR));
attron(A_DIM); 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); attroff(A_DIM);
// Menu choices handler // Menu choices handler
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment