Merge lp:~widelands-dev/widelands/bugfix-1801208 into lp:widelands

Proposed by Arty
Status: Merged
Merged at revision: 8923
Proposed branch: lp:~widelands-dev/widelands/bugfix-1801208
Merge into: lp:widelands
Diff against target: 48 lines (+14/-4)
2 files modified
src/ui_basic/multilinetextarea.cc (+12/-3)
src/ui_basic/multilinetextarea.h (+2/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bugfix-1801208
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+358594@code.launchpad.net

Commit message

Changed some types from uint to int to avoid overflows in calculations.

Forced the text anchor for drawing multiline text areas to be non-negative, so that text alignment wouldn't be based on overlong lines. (Otherwise short lines wouldn't be aligned properly, possibly even be outside the visible area.)

To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4206. State: errored. Details: https://travis-ci.org/widelands/widelands/builds/453338126.
Appveyor build 4002. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bugfix_1801208-4002.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Code LGTM :)

@bunnybot merge

review: Approve
Revision history for this message
bunnybot (widelandsofficial) wrote :

Refusing to merge, since Travis is not green. Use @bunnybot merge force for merging anyways.

Travis build 4206. State: errored. Details: https://travis-ci.org/widelands/widelands/builds/453338126.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Transient failure on Travis

@bunnybot merge force

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ui_basic/multilinetextarea.cc'
2--- src/ui_basic/multilinetextarea.cc 2018-08-12 16:35:30 +0000
3+++ src/ui_basic/multilinetextarea.cc 2018-11-10 17:41:58 +0000
4@@ -30,7 +30,8 @@
5
6 namespace UI {
7
8-static const uint32_t RICHTEXT_MARGIN = 2;
9+// int instead of uint because of overflow situations
10+static const int32_t RICHTEXT_MARGIN = 2;
11
12 MultilineTextarea::MultilineTextarea(Panel* const parent,
13 const int32_t x,
14@@ -141,11 +142,19 @@
15 int anchor = 0;
16 Align alignment = mirror_alignment(align_, text_);
17 switch (alignment) {
18+ // TODO(Arty): We might want to revisit this after the font renderer can handle long strings
19+ // without whitespaces differently.
20+ // Currently, such long unbreakable strings are silently assumed to fit the line exactly,
21+ // which means that rendered_text_->width() might actually be larger than the effective width
22+ // of the textarea. If we'd allow the anchor here to become negative in this case, it would
23+ // properly position the longest line (just truncated), BUT the positioning of shorter lines
24+ // would be off (possibly even outside the textarea, thus invisible) because their positioning
25+ // is calculated without regard for overlong lines.
26 case UI::Align::kCenter:
27- anchor = (get_eff_w() - rendered_text_->width()) / 2;
28+ anchor = std::max(0, (get_eff_w() - rendered_text_->width()) / 2);
29 break;
30 case UI::Align::kRight:
31- anchor = get_eff_w() - rendered_text_->width() - RICHTEXT_MARGIN;
32+ anchor = std::max(0, get_eff_w() - rendered_text_->width() - RICHTEXT_MARGIN);
33 break;
34 case UI::Align::kLeft:
35 anchor = RICHTEXT_MARGIN;
36
37=== modified file 'src/ui_basic/multilinetextarea.h'
38--- src/ui_basic/multilinetextarea.h 2018-07-08 09:18:33 +0000
39+++ src/ui_basic/multilinetextarea.h 2018-11-10 17:41:58 +0000
40@@ -60,7 +60,8 @@
41 }
42
43 void set_text(const std::string&);
44- uint32_t get_eff_w() const {
45+ // int instead of uint because of overflow situations
46+ int32_t get_eff_w() const {
47 return scrollbar_.is_enabled() ? get_w() - Scrollbar::kSize : get_w();
48 }
49

Subscribers

People subscribed via source and target branches

to status/vote changes: