[Scummvm-git-logs] scummvm master -> 39028096bbac8906c74bccfa476d74d71b073720

sev- noreply at scummvm.org
Thu Feb 12 10:24:26 UTC 2026


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .

Summary:
b72707b61e GUI: Unify ListWidget and GroupedListWidget setSelected implementation
2cf0713e29 GUI: Scroll to selected item on UP/DOWN key navigation in List
39028096bb GUI: Refractor scroll logic in UP/DOWN key navigation in List


Commit: b72707b61e0dd99e7e1133b1b23061f45cfc720c
    https://github.com/scummvm/scummvm/commit/b72707b61e0dd99e7e1133b1b23061f45cfc720c
Author: Mohit Bankar (mohitbankar1212 at gmail.com)
Date: 2026-02-12T11:24:20+01:00

Commit Message:
GUI: Unify ListWidget and GroupedListWidget setSelected implementation

Remove duplicate setSelected() and findDataIndex() from GroupedListWidget
and use inherited implementation from ListWidget.

Changed paths:
    gui/widgets/grid.cpp
    gui/widgets/groupedlist.cpp
    gui/widgets/groupedlist.h
    gui/widgets/list.cpp
    gui/widgets/list.h


diff --git a/gui/widgets/grid.cpp b/gui/widgets/grid.cpp
index 57507da714d..e1e8f16176c 100644
--- a/gui/widgets/grid.cpp
+++ b/gui/widgets/grid.cpp
@@ -1245,8 +1245,8 @@ void GridWidget::setSelected(int id) {
 			// Clear previous selections and mark only this item
 			if (_multiSelectEnabled) {
 				clearSelection();
-				markSelectedItem(id, true);
 			}
+			markSelectedItem(id, true);
 			
 			scrollToEntry(id, false);
 			break;
diff --git a/gui/widgets/groupedlist.cpp b/gui/widgets/groupedlist.cpp
index e4162dfd2ca..54b1efc1412 100644
--- a/gui/widgets/groupedlist.cpp
+++ b/gui/widgets/groupedlist.cpp
@@ -189,48 +189,6 @@ void GroupedListWidget::saveClosedGroups(const Common::U32String &groupName) {
 	ConfMan.flushToDisk();
 }
 
-int GroupedListWidget::findDataIndex(int data_index) const {
-	// The given index is an index in the _dataList.
-	// We want the index in the current _listIndex (which may be filtered and sorted) for this data.
-	// Sanity check to avoid iterating on the _listIndex if we know the given index is invalid.
-	if (data_index < -1 || data_index >= (int)_dataList.size())
-		return -1;
-	for (uint i = 0; i < _listIndex.size(); ++i) {
-		if (_listIndex[i] == data_index)
-			return i;
-	}
-	return -1;
-}
-
-void GroupedListWidget::setSelected(int item) {
-	if (item < -1 || item >= (int)_dataList.size())
-		return;
-
-	// We only have to do something if the widget is enabled and the selection actually changes
-	if (isEnabled() && (_selectedItem == -1 || _selectedItem >= (int)_list.size() || _listIndex[_selectedItem] != item)) {
-		if (_editMode)
-			abortEditMode();
-
-		_selectedItem = findDataIndex(item);
-
-		// Clear previous selections and mark only this item
-		if (_multiSelectEnabled) {
-			clearSelection();
-			markSelectedItem(_selectedItem, true);
-		}
-
-		// Notify clients that the selection changed.
-		sendCommand(kListSelectionChangedCmd, _selectedItem);
-
-		if (_selectedItem != -1 && !isItemVisible(_selectedItem)) {
-			// scroll selected item to center if possible
-			_currentPos = _selectedItem - _entriesPerPage / 2;
-			scrollToCurrent();
-		}
-		markAsDirty();
-	}
-}
-
 void GroupedListWidget::handleMouseDown(int x, int y, int button, int clickCount) {
 	if (!isEnabled())
 		return;
diff --git a/gui/widgets/groupedlist.h b/gui/widgets/groupedlist.h
index 99ed877529b..f3171785abe 100644
--- a/gui/widgets/groupedlist.h
+++ b/gui/widgets/groupedlist.h
@@ -55,7 +55,6 @@ public:
 	void loadClosedGroups(const Common::U32String &groupName);
 	void saveClosedGroups(const Common::U32String &groupName);
 
-	void setSelected(int item);
 	int getSelected() const { return (_selectedItem == -1) ? _selectedItem : _listIndex[_selectedItem]; }
 
 	void setFilter(const Common::U32String &filter, bool redraw = true);
@@ -77,7 +76,6 @@ protected:
 	void toggleGroup(int groupID);
 	void drawWidget() override;
 	ThemeEngine::WidgetStateInfo getItemState(int item) const override;
-	int findDataIndex(int) const;
 };
 
 } // End of namespace GUI
diff --git a/gui/widgets/list.cpp b/gui/widgets/list.cpp
index ff930f81dc8..d72e8a3f8bc 100644
--- a/gui/widgets/list.cpp
+++ b/gui/widgets/list.cpp
@@ -160,42 +160,40 @@ Widget *ListWidget::findWidget(int x, int y) {
 	return this;
 }
 
-void ListWidget::setSelected(int item) {
-	// HACK/FIXME: If our _listIndex has a non zero size,
-	// we will need to look up, whether the user selected
-	// item is present in that list
-	if (!_filter.empty()) {
-		int filteredItem = -1;
-
-		for (uint i = 0; i < _listIndex.size(); ++i) {
-			if (_listIndex[i] == item) {
-				filteredItem = i;
-				break;
-			}
-		}
-
-		item = filteredItem;
+int ListWidget::findDataIndex(int dataIndex) const {
+	// The given index is an index in the _dataList.
+	// We want the index in the current _list (which may be filtered) for this data.
+	// Sanity check to avoid iterating on the _listIndex if we know the given index is invalid.
+	if (dataIndex < -1 || dataIndex >= (int)_dataList.size())
+		return -1;
+	for (uint i = 0; i < _listIndex.size(); ++i) {
+		if (_listIndex[i] == dataIndex)
+			return i;
 	}
+	return -1;
+}
 
-	assert(item >= -1 && item < (int)_list.size());
+void ListWidget::setSelected(int item) {
+	if (item < -1 || item >= (int)_list.size())
+		return;
 
 	// We only have to do something if the widget is enabled and the selection actually changes
-	if (isEnabled() && _selectedItem != item) {
+	if (isEnabled() && (_selectedItem == -1 || _selectedItem >= (int)_list.size() || _listIndex[_selectedItem] != item)) {
 		if (_editMode)
 			abortEditMode();
 
-		_selectedItem = item;
+		_selectedItem = findDataIndex(item);
 
 		// Clear previous selections and mark only this item
 		if (_multiSelectEnabled) {
 			clearSelection();
-			markSelectedItem(item, true);
 		}
+		markSelectedItem(_selectedItem, true);
 
 		// Notify clients that the selection changed.
 		sendCommand(kListSelectionChangedCmd, _selectedItem);
 
-		if (!isItemVisible(_selectedItem)) {
+		if (_selectedItem != -1 && !isItemVisible(_selectedItem)) {
 			// scroll selected item to center if possible
 			_currentPos = _selectedItem - _entriesPerPage / 2;
 			scrollToCurrent();
diff --git a/gui/widgets/list.h b/gui/widgets/list.h
index 7c895a357e7..71dce978a9b 100644
--- a/gui/widgets/list.h
+++ b/gui/widgets/list.h
@@ -195,6 +195,9 @@ protected:
 	void checkBounds();
 	void scrollToCurrent();
 
+	/// Find the visual position of a data item
+	int findDataIndex(int dataIndex) const;
+
 	virtual ThemeEngine::WidgetStateInfo getItemState(int item) const { return _state; }
 
 	void drawFormattedText(const Common::Rect &r, const Common::U32String &str, ThemeEngine::WidgetStateInfo state = ThemeEngine::kStateEnabled,


Commit: 2cf0713e29beee7a0323efd1e6d090906a49dc47
    https://github.com/scummvm/scummvm/commit/2cf0713e29beee7a0323efd1e6d090906a49dc47
Author: Mohit Bankar (mohitbankar1212 at gmail.com)
Date: 2026-02-12T11:24:20+01:00

Commit Message:
GUI: Scroll to selected item on UP/DOWN key navigation in List

Auto-scroll list when navigating with keyboard to keep selection visible.

Changed paths:
    gui/widgets/list.cpp


diff --git a/gui/widgets/list.cpp b/gui/widgets/list.cpp
index d72e8a3f8bc..0aaa6acb9a6 100644
--- a/gui/widgets/list.cpp
+++ b/gui/widgets/list.cpp
@@ -568,6 +568,9 @@ bool ListWidget::handleKeyDown(Common::KeyState state) {
 					_selectedItem++;
 					markSelectedItem(_selectedItem, true);
 					_lastSelectionStartItem = _selectedItem;
+					if (!isItemVisible(_selectedItem)) {
+						scrollToCurrent();
+					}
 				}
 			}
 			break;
@@ -619,6 +622,9 @@ bool ListWidget::handleKeyDown(Common::KeyState state) {
 					_selectedItem--;
 					markSelectedItem(_selectedItem, true);
 					_lastSelectionStartItem = _selectedItem;
+					if (!isItemVisible(_selectedItem)) {
+						scrollToCurrent();
+					}
 				}
 			}
 			break;


Commit: 39028096bbac8906c74bccfa476d74d71b073720
    https://github.com/scummvm/scummvm/commit/39028096bbac8906c74bccfa476d74d71b073720
Author: Mohit Bankar (mohitbankar1212 at gmail.com)
Date: 2026-02-12T11:24:20+01:00

Commit Message:
GUI: Refractor scroll logic in UP/DOWN key navigation in List

Move visibility check and scroll outside if/else blocks to apply
consistently to both shift selection and regular navigation.

Changed paths:
    gui/widgets/list.cpp


diff --git a/gui/widgets/list.cpp b/gui/widgets/list.cpp
index 0aaa6acb9a6..369eb7f57ec 100644
--- a/gui/widgets/list.cpp
+++ b/gui/widgets/list.cpp
@@ -561,17 +561,14 @@ bool ListWidget::handleKeyDown(Common::KeyState state) {
 					else
 						markSelectedItem(_selectedItem, false);
 					_selectedItem = newItem;
-					scrollToCurrent();
-					dirty = true;
 				} else {
 					clearSelection();
 					_selectedItem++;
 					markSelectedItem(_selectedItem, true);
 					_lastSelectionStartItem = _selectedItem;
-					if (!isItemVisible(_selectedItem)) {
-						scrollToCurrent();
-					}
 				}
+				if (!isItemVisible(_selectedItem))
+					scrollToCurrent();
 			}
 			break;
 
@@ -615,17 +612,14 @@ bool ListWidget::handleKeyDown(Common::KeyState state) {
 					else
 						markSelectedItem(_selectedItem, false);
 					_selectedItem = newItem;
-					scrollToCurrent();
-					dirty = true;
 				} else {
 					clearSelection();
 					_selectedItem--;
 					markSelectedItem(_selectedItem, true);
 					_lastSelectionStartItem = _selectedItem;
-					if (!isItemVisible(_selectedItem)) {
-						scrollToCurrent();
-					}
 				}
+				if (!isItemVisible(_selectedItem))
+					scrollToCurrent();
 			}
 			break;
 




More information about the Scummvm-git-logs mailing list