summaryrefslogtreecommitdiffstats
path: root/screen_ui.cpp
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2017-08-16 07:02:05 +0200
committerGerrit Code Review <noreply-gerritcodereview@google.com>2017-08-16 07:02:05 +0200
commit162b92323bdcb13baf619450d994f5045f1ee195 (patch)
tree62656a73a7ef12dce8e7c83a825cb6a267495278 /screen_ui.cpp
parentMerge "Add a new PatchChunk class in imgdiff" (diff)
parentscreen_ui: Word-wrap menu headers. (diff)
downloadandroid_bootable_recovery-162b92323bdcb13baf619450d994f5045f1ee195.tar
android_bootable_recovery-162b92323bdcb13baf619450d994f5045f1ee195.tar.gz
android_bootable_recovery-162b92323bdcb13baf619450d994f5045f1ee195.tar.bz2
android_bootable_recovery-162b92323bdcb13baf619450d994f5045f1ee195.tar.lz
android_bootable_recovery-162b92323bdcb13baf619450d994f5045f1ee195.tar.xz
android_bootable_recovery-162b92323bdcb13baf619450d994f5045f1ee195.tar.zst
android_bootable_recovery-162b92323bdcb13baf619450d994f5045f1ee195.zip
Diffstat (limited to 'screen_ui.cpp')
-rw-r--r--screen_ui.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/screen_ui.cpp b/screen_ui.cpp
index 8f792f162..e056512bd 100644
--- a/screen_ui.cpp
+++ b/screen_ui.cpp
@@ -278,6 +278,34 @@ int ScreenRecoveryUI::DrawTextLines(int x, int y, const char* const* lines) cons
return offset;
}
+int ScreenRecoveryUI::DrawWrappedTextLines(int x, int y, const char* const* lines) const {
+ int offset = 0;
+ for (size_t i = 0; lines != nullptr && lines[i] != nullptr; ++i) {
+ // The line will be wrapped if it exceeds text_cols_.
+ std::string line(lines[i]);
+ size_t next_start = 0;
+ while (next_start < line.size()) {
+ std::string sub = line.substr(next_start, text_cols_ + 1);
+ if (sub.size() <= text_cols_) {
+ next_start += sub.size();
+ } else {
+ // Line too long and must be wrapped to text_cols_ columns.
+ size_t last_space = sub.find_last_of(" \t\n");
+ if (last_space == std::string::npos) {
+ // No space found, just draw as much as we can
+ sub.resize(text_cols_);
+ next_start += text_cols_;
+ } else {
+ sub.resize(last_space);
+ next_start += last_space + 1;
+ }
+ }
+ offset += DrawTextLine(x, y + offset, sub.c_str(), false);
+ }
+ }
+ return offset;
+}
+
static const char* REGULAR_HELP[] = {
"Use volume up/down and power.",
NULL
@@ -316,7 +344,7 @@ void ScreenRecoveryUI::draw_screen_locked() {
y += DrawTextLines(x, y, HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP);
SetColor(HEADER);
- y += DrawTextLines(x, y, menu_headers_);
+ y += DrawWrappedTextLines(x, y, menu_headers_);
SetColor(MENU);
y += DrawHorizontalRule(y) + 4;