summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2018-05-09 23:32:38 +0200
committerandroid-build-merger <android-build-merger@google.com>2018-05-09 23:32:38 +0200
commit6b540e6b23a1e0aed7db8bf6d52f6069f2700b71 (patch)
tree1e984a1d6f0242f78fb65ddce0a8766688519e06
parentMerge "updater_sample: update tools" am: daa86e9024 am: 9fdeb57ab0 (diff)
parentMerge "screen_ui: Fix an issue when displaying wrapped text." am: 1d4ef4ba4b (diff)
downloadandroid_bootable_recovery-6b540e6b23a1e0aed7db8bf6d52f6069f2700b71.tar
android_bootable_recovery-6b540e6b23a1e0aed7db8bf6d52f6069f2700b71.tar.gz
android_bootable_recovery-6b540e6b23a1e0aed7db8bf6d52f6069f2700b71.tar.bz2
android_bootable_recovery-6b540e6b23a1e0aed7db8bf6d52f6069f2700b71.tar.lz
android_bootable_recovery-6b540e6b23a1e0aed7db8bf6d52f6069f2700b71.tar.xz
android_bootable_recovery-6b540e6b23a1e0aed7db8bf6d52f6069f2700b71.tar.zst
android_bootable_recovery-6b540e6b23a1e0aed7db8bf6d52f6069f2700b71.zip
-rw-r--r--screen_ui.cpp12
-rw-r--r--screen_ui.h5
2 files changed, 10 insertions, 7 deletions
diff --git a/screen_ui.cpp b/screen_ui.cpp
index 90e0e30af..c0fb2cfba 100644
--- a/screen_ui.cpp
+++ b/screen_ui.cpp
@@ -468,20 +468,22 @@ int ScreenRecoveryUI::DrawTextLines(int x, int y, const std::vector<std::string>
int ScreenRecoveryUI::DrawWrappedTextLines(int x, int y,
const std::vector<std::string>& lines) const {
+ // Keep symmetrical margins based on the given offset (i.e. x).
+ size_t text_cols = (ScreenWidth() - x * 2) / char_width_;
int offset = 0;
for (const auto& line : lines) {
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_) {
+ 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.
+ // 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_;
+ sub.resize(text_cols);
+ next_start += text_cols;
} else {
sub.resize(last_space);
next_start += last_space + 1;
diff --git a/screen_ui.h b/screen_ui.h
index d4923f566..293696d22 100644
--- a/screen_ui.h
+++ b/screen_ui.h
@@ -224,8 +224,9 @@ class ScreenRecoveryUI : public RecoveryUI {
virtual void DrawTextIcon(int x, int y, GRSurface* surface) const;
// Draws multiple text lines. Returns the offset it should be moving along Y-axis.
int DrawTextLines(int x, int y, const std::vector<std::string>& lines) const;
- // Similar to DrawTextLines() to draw multiple text lines, but additionally wraps long lines.
- // Returns the offset it should be moving along Y-axis.
+ // Similar to DrawTextLines() to draw multiple text lines, but additionally wraps long lines. It
+ // keeps symmetrical margins of 'x' at each end of a line. Returns the offset it should be moving
+ // along Y-axis.
int DrawWrappedTextLines(int x, int y, const std::vector<std::string>& lines) const;
Icon currentIcon;