← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1526911-cursor-positioning into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1526911-cursor-positioning into lp:widelands.

Commit message:
Some cursor fixes for edit boxes:
- Fixed cursor y position for empty Editboxes.
- Moved test for empty player names from editor player tool to map saving.
- In a new MultilineEditbox, position cursor at end of text.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1526911 in widelands: "Textboxes: inconsistent cursor positioning"
  https://bugs.launchpad.net/widelands/+bug/1526911

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1526911-cursor-positioning/+merge/290954

Cursor position for BiDi languages is still broken, but that's a separate issue.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1526911-cursor-positioning into lp:widelands.
=== modified file 'src/editor/ui_menus/editor_player_menu.cc'
--- src/editor/ui_menus/editor_player_menu.cc	2016-03-14 18:10:09 +0000
+++ src/editor/ui_menus/editor_player_menu.cc	2016-04-05 07:39:22 +0000
@@ -334,10 +334,6 @@
 	std::string text = plr_names_[m]->text();
 	EditorInteractive& menu = eia();
 	Widelands::Map & map = menu.egbase().map();
-	if (text == "") {
-		text = map.get_scenario_player_name(m + 1);
-		plr_names_[m]->set_text(text);
-	}
 	map.set_scenario_player_name(m + 1, text);
 	plr_names_[m]->set_text(map.get_scenario_player_name(m + 1));
 	menu.set_need_save(true);

=== modified file 'src/map_io/map_player_names_and_tribes_packet.cc'
--- src/map_io/map_player_names_and_tribes_packet.cc	2015-11-28 22:29:26 +0000
+++ src/map_io/map_player_names_and_tribes_packet.cc	2016-04-05 07:39:22 +0000
@@ -20,6 +20,7 @@
 #include "map_io/map_player_names_and_tribes_packet.h"
 
 #include <boost/format.hpp>
+#include <boost/algorithm/string/trim.hpp>
 
 #include "logic/editor_game_base.h"
 #include "logic/game_data_error.h"
@@ -96,8 +97,16 @@
 	iterate_player_numbers(p, nr_players) {
 		const std::string section_key = (boost::format("player_%u")
 													% static_cast<unsigned int>(p)).str();
+
+		// Make sure that no player name is empty, and trim leading/trailing whitespaces.
+		std::string player_name = map.get_scenario_player_name(p);
+		boost::trim(player_name);
+		if (player_name.empty()) {
+			player_name =  (boost::format(_("Player %u")) % static_cast<unsigned int>(p)).str();
+		}
+
 		Section & s = prof.create_section(section_key.c_str());
-		s.set_string("name",      map.get_scenario_player_name     (p));
+		s.set_string("name",      player_name);
 		s.set_string("tribe",     map.get_scenario_player_tribe    (p));
 		s.set_string("ai",        map.get_scenario_player_ai       (p));
 		s.set_bool  ("closeable", map.get_scenario_player_closeable(p));

=== modified file 'src/ui_basic/editbox.cc'
--- src/ui_basic/editbox.cc	2016-03-10 15:00:32 +0000
+++ src/ui_basic/editbox.cc	2016-04-05 07:39:22 +0000
@@ -396,8 +396,11 @@
 
 	const Image* entry_text_im = UI::g_fh1->render(as_editorfont(m_->text, m_->fontsize));
 
-	int linewidth = entry_text_im->width();
-	int lineheight = entry_text_im->height();
+	const int linewidth = entry_text_im->width();
+	const int lineheight = m_->text.empty() ?
+							  UI::g_fh1->render(as_editorfont(UI::g_fh1->fontset()->representative_character(),
+																		 m_->fontsize))->height() :
+							  entry_text_im->height();
 
 	Point point(kMargin, get_h() / 2);
 

=== modified file 'src/ui_basic/multilineeditbox.cc'
--- src/ui_basic/multilineeditbox.cc	2016-03-25 17:01:05 +0000
+++ src/ui_basic/multilineeditbox.cc	2016-04-05 07:39:22 +0000
@@ -138,11 +138,11 @@
 		return;
 
 	d_->text = text;
-	while (d_->text.size() > d_->maxbytes)
+	while (d_->text.size() > d_->maxbytes) {
 		d_->erase_bytes(d_->prev_char(d_->text.size()), d_->text.size());
+	}
 
-	if (d_->cursor_pos > d_->text.size())
-		d_->cursor_pos = d_->text.size();
+	d_->set_cursor_pos(d_->text.size());
 
 	d_->update();
 	d_->scroll_cursor_into_view();


Follow ups