← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-message-removal into lp:widelands

 

Notabilis has proposed merging lp:~widelands-dev/widelands/bug-message-removal into lp:widelands.

Commit message:
Modified row selection/display in tables and message list.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-message-removal/+merge/345475

The ingame message window behaves a bit strange when removing messages, e.g., after removing a message the first message in the list is highlighted (and selected for del-key) but the arrow-up/down-keys move from the old position.

This branch intends provide a more logically behavior by always selecting the message below the removed message(s), both optically and for keyboard input.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-message-removal into lp:widelands.
=== modified file 'src/ui_basic/table.cc'
--- src/ui_basic/table.cc	2018-05-07 05:35:32 +0000
+++ src/ui_basic/table.cc	2018-05-13 14:46:24 +0000
@@ -431,6 +431,7 @@
 	selection_ = i;
 	if (is_multiselect_) {
 		multiselect_.insert(selection_);
+		last_multiselect_ = selection_;
 	}
 
 	selected(selection_);
@@ -548,8 +549,11 @@
 	} else if (selection_ > i && selection_ != no_selection_index()) {
 		selection_--;
 	}
-	if (is_multiselect_ && selection_ != no_selection_index()) {
-		multiselect_.insert(selection_);
+	if (is_multiselect_) {
+		if (selection_ != no_selection_index()) {
+			multiselect_.insert(selection_);
+		}
+		last_multiselect_ = selection_;
 	}
 	layout();
 }

=== modified file 'src/wui/game_message_menu.cc'
--- src/wui/game_message_menu.cc	2018-05-07 05:35:32 +0000
+++ src/wui/game_message_menu.cc	2018-05-13 14:46:24 +0000
@@ -262,18 +262,32 @@
 
 	// Update messages in the list and remove messages
 	// that should no longer be shown
+	uint32_t removed = 0;
+	const auto& sel = list->selections();
+	const uint32_t max_index = (sel.empty() ? 0 : *sel.rbegin());
 	for (uint32_t j = list->size(); j; --j) {
 		MessageId id_((*list)[j - 1]);
 		if (Message const* const message = mq[id_]) {
 			if (should_be_hidden(*message)) {
+				removed++;
 				list->remove(j - 1);
 			} else {
 				update_record(list->get_record(j - 1), *message);
 			}
 		} else {
+			removed++;
 			list->remove(j - 1);
 		}
 	}
+	if (removed > 0) {
+		// If something was removed, select entry below lowest removed entry
+		uint32_t index = 0;
+		if (removed <= max_index) {
+			index = std::min(max_index - removed + 1, list->size() - 1);
+		}
+		list->select(index);
+		list->scroll_to_item(index);
+	}
 
 	// Add new messages to the list
 	for (const auto& temp_message : mq) {


Follow ups