← Back to team overview

widelands-dev team mailing list archive

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

 

Arty has proposed merging lp:~widelands-dev/widelands/bugfix-1801208 into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1801208 in widelands: "Message boxes with long unbreakable strings show empty "
  https://bugs.launchpad.net/widelands/+bug/1801208

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bugfix-1801208/+merge/358594
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bugfix-1801208 into lp:widelands.
=== modified file 'src/ui_basic/multilinetextarea.cc'
--- src/ui_basic/multilinetextarea.cc	2018-08-12 16:35:30 +0000
+++ src/ui_basic/multilinetextarea.cc	2018-11-10 17:41:58 +0000
@@ -30,7 +30,8 @@
 
 namespace UI {
 
-static const uint32_t RICHTEXT_MARGIN = 2;
+// int instead of uint because of overflow situations
+static const int32_t RICHTEXT_MARGIN = 2;
 
 MultilineTextarea::MultilineTextarea(Panel* const parent,
                                      const int32_t x,
@@ -141,11 +142,19 @@
 	int anchor = 0;
 	Align alignment = mirror_alignment(align_, text_);
 	switch (alignment) {
+	// TODO(Arty): We might want to revisit this after the font renderer can handle long strings
+	// without whitespaces differently.
+	// Currently, such long unbreakable strings are silently assumed to fit the line exactly,
+	// which means that rendered_text_->width() might actually be larger than the effective width
+	// of the textarea. If we'd allow the anchor here to become negative in this case, it would
+	// properly position the longest line (just truncated), BUT the positioning of shorter lines
+	// would be off (possibly even outside the textarea, thus invisible) because their positioning
+	// is calculated without regard for overlong lines.
 	case UI::Align::kCenter:
-		anchor = (get_eff_w() - rendered_text_->width()) / 2;
+		anchor = std::max(0, (get_eff_w() - rendered_text_->width()) / 2);
 		break;
 	case UI::Align::kRight:
-		anchor = get_eff_w() - rendered_text_->width() - RICHTEXT_MARGIN;
+		anchor = std::max(0, get_eff_w() - rendered_text_->width() - RICHTEXT_MARGIN);
 		break;
 	case UI::Align::kLeft:
 		anchor = RICHTEXT_MARGIN;

=== modified file 'src/ui_basic/multilinetextarea.h'
--- src/ui_basic/multilinetextarea.h	2018-07-08 09:18:33 +0000
+++ src/ui_basic/multilinetextarea.h	2018-11-10 17:41:58 +0000
@@ -60,7 +60,8 @@
 	}
 
 	void set_text(const std::string&);
-	uint32_t get_eff_w() const {
+	// int instead of uint because of overflow situations
+	int32_t get_eff_w() const {
 		return scrollbar_.is_enabled() ? get_w() - Scrollbar::kSize : get_w();
 	}
 


Follow ups