summaryrefslogtreecommitdiffstats
path: root/screen_ui.cpp
diff options
context:
space:
mode:
authorandroid-build-prod (mdb) <android-build-team-robot@google.com>2018-05-03 07:05:21 +0200
committerandroid-build-merger <android-build-merger@google.com>2018-05-03 07:05:21 +0200
commit704d11fac27a29b3f19ffc78797139c2964f862a (patch)
tree1d43eaa24ff5811e00b210ff2aee92473ca460af /screen_ui.cpp
parentMerge "updater_sample: Add streaming to PayloadSpec" am: 3a79b36377 (diff)
parentMerge "screen_ui: Merge Menu::Start() into its ctor." (diff)
downloadandroid_bootable_recovery-704d11fac27a29b3f19ffc78797139c2964f862a.tar
android_bootable_recovery-704d11fac27a29b3f19ffc78797139c2964f862a.tar.gz
android_bootable_recovery-704d11fac27a29b3f19ffc78797139c2964f862a.tar.bz2
android_bootable_recovery-704d11fac27a29b3f19ffc78797139c2964f862a.tar.lz
android_bootable_recovery-704d11fac27a29b3f19ffc78797139c2964f862a.tar.xz
android_bootable_recovery-704d11fac27a29b3f19ffc78797139c2964f862a.tar.zst
android_bootable_recovery-704d11fac27a29b3f19ffc78797139c2964f862a.zip
Diffstat (limited to 'screen_ui.cpp')
-rw-r--r--screen_ui.cpp35
1 files changed, 15 insertions, 20 deletions
diff --git a/screen_ui.cpp b/screen_ui.cpp
index d3f373eae..56ca48ea8 100644
--- a/screen_ui.cpp
+++ b/screen_ui.cpp
@@ -52,14 +52,23 @@ static double now() {
return tv.tv_sec + tv.tv_usec / 1000000.0;
}
-Menu::Menu(bool scrollable, size_t max_items, size_t max_length)
+Menu::Menu(bool scrollable, size_t max_items, size_t max_length, const char* const* headers,
+ const char* const* items, int initial_selection)
: scrollable_(scrollable),
max_display_items_(max_items),
max_item_length_(max_length),
- text_headers_(nullptr),
+ text_headers_(headers),
menu_start_(0),
- selection_(0) {
+ selection_(initial_selection) {
CHECK_LE(max_items, static_cast<size_t>(std::numeric_limits<int>::max()));
+
+ // It's fine to have more entries than text_rows_ if scrollable menu is supported.
+ size_t max_items_count = scrollable_ ? std::numeric_limits<int>::max() : max_display_items_;
+ for (size_t i = 0; i < max_items_count && items[i] != nullptr; ++i) {
+ text_items_.emplace_back(items[i], strnlen(items[i], max_item_length_));
+ }
+
+ CHECK(!text_items_.empty());
}
const char* const* Menu::text_headers() const {
@@ -85,7 +94,7 @@ size_t Menu::ItemsCount() const {
}
bool Menu::ItemsOverflow(std::string* cur_selection_str) const {
- if (!scrollable_ || static_cast<size_t>(ItemsCount()) <= max_display_items_) {
+ if (!scrollable_ || ItemsCount() <= max_display_items_) {
return false;
}
@@ -94,19 +103,6 @@ bool Menu::ItemsOverflow(std::string* cur_selection_str) const {
return true;
}
-void Menu::Start(const char* const* headers, const char* const* items, int initial_selection) {
- text_headers_ = headers;
-
- // It's fine to have more entries than text_rows_ if scrollable menu is supported.
- size_t max_items_count = scrollable_ ? std::numeric_limits<int>::max() : max_display_items_;
- for (size_t i = 0; i < max_items_count && items[i] != nullptr; ++i) {
- text_items_.emplace_back(items[i], strnlen(items[i], max_item_length_));
- }
-
- CHECK(!text_items_.empty());
- selection_ = initial_selection;
-}
-
// TODO(xunchang) modify the function parameters to button up & down.
int Menu::Select(int sel) {
CHECK_LE(ItemsCount(), static_cast<size_t>(std::numeric_limits<int>::max()));
@@ -987,9 +983,8 @@ void ScreenRecoveryUI::StartMenu(const char* const* headers, const char* const*
int initial_selection) {
pthread_mutex_lock(&updateMutex);
if (text_rows_ > 0 && text_cols_ > 1) {
- menu_ = std::make_unique<Menu>(scrollable_menu_, text_rows_, text_cols_ - 1);
- menu_->Start(headers, items, initial_selection);
-
+ menu_ = std::make_unique<Menu>(scrollable_menu_, text_rows_, text_cols_ - 1, headers, items,
+ initial_selection);
update_screen_locked();
}
pthread_mutex_unlock(&updateMutex);