From 72046f2e0c7d475d938d166a5fe2987bb42344a7 Mon Sep 17 00:00:00 2001 From: Simon <33755707+Crotex@users.noreply.github.com> Date: Thu, 9 Jan 2020 14:31:00 +0100 Subject: [PATCH] Added paging Fixes #2 --- menu.c | 4 ++-- menu.h | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/menu.c b/menu.c index 982c135..721e23d 100644 --- a/menu.c +++ b/menu.c @@ -40,7 +40,7 @@ void get_console_dimensions(int* width, int* height) *height = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; } -void page(const struct MenuPage *pages, const size_t page_count) { +void page(const struct MenuPage *pages, const size_t page_count, const bool infinite_loop) { unsigned int page_index = 0; bool action_performed, loop, pageChanged = true; char pageKey, itemKey; @@ -87,7 +87,7 @@ void page(const struct MenuPage *pages, const size_t page_count) { } while (loop || pageChanged); page_index = 0; - } while (1); + } while (infinite_loop); } void show_menu(const int itemc, const struct MenuItem itemv[], const char title[], const struct MenuBorder *border) diff --git a/menu.h b/menu.h index 92981a7..63d3845 100644 --- a/menu.h +++ b/menu.h @@ -3,7 +3,6 @@ #include "pch.h" - /// Represents one menu item in a menu. struct MenuItem { char* text; @@ -11,8 +10,6 @@ struct MenuItem { void* (*action)(void); }; - - /// Represents a border in which a menu is displayed. struct MenuBorder { char line_vertical; @@ -27,6 +24,7 @@ struct MenuBorder { const extern struct MenuBorder DEFAULT, MODERN, NO_BORDER, SOLID; + /// Represents a page in the menu. struct MenuPage { const struct MenuItem* items; @@ -36,6 +34,13 @@ struct MenuPage { const struct MenuBorder* border; }; + +/// Constructs a menu with a specific amount of pages +/// An array of all pages to display. +/// The length of the array pages. +/// Always display the first page after a loopback=false item finished executing. +void page(const struct MenuPage* pages, const size_t page_count, const bool infinite_loop); + /// Displaces a CUI menu to the user /// The length of the array itemv of menu items. /// An array of all menu items to display in the menu.