aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao2017-08-14 01:48:55 -0500
committerTao Bao2017-08-15 17:10:21 -0500
commit2bbc6d642d1fbfb007905d95b629fe5f833b2a1b (patch)
tree3e6e9cdb3e14e52d19c0a029c8cb7ee71db73619 /screen_ui.cpp
parent0459799ea83d669df089c670f244771b7be211e3 (diff)
downloadplatform-bootable-recovery-2bbc6d642d1fbfb007905d95b629fe5f833b2a1b.tar.gz
platform-bootable-recovery-2bbc6d642d1fbfb007905d95b629fe5f833b2a1b.tar.xz
platform-bootable-recovery-2bbc6d642d1fbfb007905d95b629fe5f833b2a1b.zip
screen_ui: Word-wrap menu headers.
This CL adds ScreenRecoveryUI::DrawWrappedTextLines() to better handle long menu header texts. It does a word wrap at spaces, if available. This avoids fixed-length menu headers being truncated on small screens. Bug: 64293520 Test: On bullhead, boot into recovery with --prompt_and_wipe_data, and check the prompt texts. Change-Id: Ia22746583516dd230567a267584aca558429395e
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 8f792f16..e056512b 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
278 return offset; 278 return offset;
279} 279}
280 280
281int ScreenRecoveryUI::DrawWrappedTextLines(int x, int y, const char* const* lines) const {
282 int offset = 0;
283 for (size_t i = 0; lines != nullptr && lines[i] != nullptr; ++i) {
284 // The line will be wrapped if it exceeds text_cols_.
285 std::string line(lines[i]);
286 size_t next_start = 0;
287 while (next_start < line.size()) {
288 std::string sub = line.substr(next_start, text_cols_ + 1);
289 if (sub.size() <= text_cols_) {
290 next_start += sub.size();
291 } else {
292 // Line too long and must be wrapped to text_cols_ columns.
293 size_t last_space = sub.find_last_of(" \t\n");
294 if (last_space == std::string::npos) {
295 // No space found, just draw as much as we can
296 sub.resize(text_cols_);
297 next_start += text_cols_;
298 } else {
299 sub.resize(last_space);
300 next_start += last_space + 1;
301 }
302 }
303 offset += DrawTextLine(x, y + offset, sub.c_str(), false);
304 }
305 }
306 return offset;
307}
308
281static const char* REGULAR_HELP[] = { 309static const char* REGULAR_HELP[] = {
282 "Use volume up/down and power.", 310 "Use volume up/down and power.",
283 NULL 311 NULL
@@ -316,7 +344,7 @@ void ScreenRecoveryUI::draw_screen_locked() {
316 y += DrawTextLines(x, y, HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP); 344 y += DrawTextLines(x, y, HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP);
317 345
318 SetColor(HEADER); 346 SetColor(HEADER);
319 y += DrawTextLines(x, y, menu_headers_); 347 y += DrawWrappedTextLines(x, y, menu_headers_);
320 348
321 SetColor(MENU); 349 SetColor(MENU);
322 y += DrawHorizontalRule(y) + 4; 350 y += DrawHorizontalRule(y) + 4;