From 1fe1afe863fde957051774cf2d9936c314d342a2 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Tue, 1 May 2018 15:56:05 -0700 Subject: Move menu headers/items to std::vector. Test: mmma -j bootable/recovery Test: Run recovery_unit_test on marlin. Test: Build and boot into recovery image on angler. Check the UI that shows menu ('View recovery log', 'Wipe data', 'Run locale test'). Test: Start recovery with '--prompt_and_wipe_data'. Check the UI. Change-Id: If8a4209e0bb4ca64f719f9f9465d3b3589a69cdc --- screen_ui.h | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'screen_ui.h') diff --git a/screen_ui.h b/screen_ui.h index 3b309fb13..fb811ce70 100644 --- a/screen_ui.h +++ b/screen_ui.h @@ -35,14 +35,15 @@ class Menu { public: // Constructs a Menu instance with the given |headers|, |items| and properties. Sets the initial // selection to |initial_selection|. - Menu(bool scrollable, size_t max_items, size_t max_length, const char* const* headers, - const char* const* items, int initial_selection); + Menu(bool scrollable, size_t max_items, size_t max_length, + const std::vector& headers, const std::vector& items, + size_t initial_selection); bool scrollable() const { return scrollable_; } - int selection() const { + size_t selection() const { return selection_; } @@ -66,7 +67,7 @@ class Menu { // /cache/recovery/last_log.1 // /cache/recovery/last_log.2 // ... - const char* const* text_headers() const; + const std::vector& text_headers() const; std::string TextItem(size_t index) const; // Checks if the menu items fit vertically on the screen. Returns true and set the @@ -84,15 +85,14 @@ class Menu { const size_t max_display_items_; // The length of each item to fit horizontally on a screen. const size_t max_item_length_; - - // Internal storage for the menu headers and items in text. - const char* const* text_headers_; + // The menu headers. + std::vector text_headers_; + // The actual menu items trimmed to fit the given properties. std::vector text_items_; - // The first item to display on the screen. size_t menu_start_; // Current menu selection. - int selection_; + size_t selection_; }; // Implementation of RecoveryUI appropriate for devices with a screen @@ -137,8 +137,9 @@ class ScreenRecoveryUI : public RecoveryUI { void ShowFile(const std::string& filename) override; // menu display - int ShowMenu(const char* const* headers, const char* const* items, int initial_selection, - bool menu_only, const std::function& key_handler) override; + size_t ShowMenu(const std::vector& headers, const std::vector& items, + size_t initial_selection, bool menu_only, + const std::function& key_handler) override; void KeyLongPress(int) override; @@ -166,8 +167,8 @@ class ScreenRecoveryUI : public RecoveryUI { // Displays some header text followed by a menu of items, which appears at the top of the screen // (in place of any scrolling ui_print() output, if necessary). - virtual void StartMenu(const char* const* headers, const char* const* items, - int initial_selection); + virtual void StartMenu(const std::vector& headers, + const std::vector& items, size_t initial_selection); // Sets the menu highlight to the given index, wrapping if necessary. Returns the actual item // selected. -- cgit v1.2.3