[Scummvm-git-logs] scummvm master -> 828192db591545e888c2c9f0bc0167ee9d66a00e

sev- noreply at scummvm.org
Sat May 28 09:52:52 UTC 2022


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

Summary:
1edab21c6e GUI: Use color information from the strings in *ListWidget
828192db59 GUI: Reduced code duplication in GroupedListWidget


Commit: 1edab21c6eb3599d550d8da99ae76ac74d06db12
    https://github.com/scummvm/scummvm/commit/1edab21c6eb3599d550d8da99ae76ac74d06db12
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-05-28T10:46:34+02:00

Commit Message:
GUI: Use color information from the strings in *ListWidget

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


diff --git a/gui/widgets/groupedlist.cpp b/gui/widgets/groupedlist.cpp
index 02ca0e2c945..00ea08cfb4f 100644
--- a/gui/widgets/groupedlist.cpp
+++ b/gui/widgets/groupedlist.cpp
@@ -47,7 +47,7 @@ void GroupedListWidget::setList(const Common::U32StringArray &list, const ColorL
 		drawCaret(true);
 
 	// Copy everything
-	_dataList = list;
+	copyListData(list);
 	_list = list;
 
 	_filter.clear();
@@ -84,27 +84,6 @@ void GroupedListWidget::setMetadataNames(const Common::StringMap &metadata) {
 	_metadataNames = metadata;
 }
 
-void GroupedListWidget::append(const Common::String &s, ThemeEngine::FontColor color) {
-	if (_dataList.size() == _listColors.size()) {
-		// If the color list has the size of the data list, we append the color.
-		_listColors.push_back(color);
-	} else if (_listColors.empty() && color != ThemeEngine::kFontColorNormal) {
-		// If it's the first entry to use a non default color, we will fill
-		// up all other entries of the color list with the default color and
-		// add the requested color for the new entry.
-		for (uint i = 0; i < _dataList.size(); ++i)
-			_listColors.push_back(ThemeEngine::kFontColorNormal);
-		_listColors.push_back(color);
-	}
-
-	_dataList.push_back(s);
-	_list.push_back(s);
-
-	setFilter(_filter, false);
-
-	scrollBarRecalc();
-}
-
 void GroupedListWidget::setGroupHeaderFormat(const Common::U32String &prefix, const Common::U32String &suffix) {
 	_groupHeaderPrefix = prefix;
 	_groupHeaderSuffix = suffix;
@@ -174,7 +153,7 @@ void GroupedListWidget::sortGroups() {
 
 		if (_groupExpanded[groupID]) {
 			for (int *k = _itemsInGroup[groupID].begin(); k != _itemsInGroup[groupID].end(); ++k) {
-				_list.push_back(Common::U32String(_groupsVisible ? "    " : "") + _dataList[*k]);
+				_list.push_back(Common::U32String(_groupsVisible ? "    " : "") + _dataList[*k].orig);
 				_listIndex.push_back(*k);
 				++curListSize;
 			}
@@ -459,8 +438,8 @@ void GroupedListWidget::setFilter(const Common::U32String &filter, bool redraw)
 		_list.clear();
 		_listIndex.clear();
 
-		for (Common::U32StringArray::iterator i = _dataList.begin(); i != _dataList.end(); ++i, ++n) {
-			tmp = *i;
+		for (auto i = _dataList.begin(); i != _dataList.end(); ++i, ++n) {
+			tmp = i->clean;
 			tmp.toLowercase();
 			bool matches = true;
 			tok.reset();
@@ -472,7 +451,7 @@ void GroupedListWidget::setFilter(const Common::U32String &filter, bool redraw)
 			}
 
 			if (matches) {
-				_list.push_back(*i);
+				_list.push_back(i->orig);
 				_listIndex.push_back(n);
 			}
 		}
diff --git a/gui/widgets/groupedlist.h b/gui/widgets/groupedlist.h
index 526f542e48b..16ec124f232 100644
--- a/gui/widgets/groupedlist.h
+++ b/gui/widgets/groupedlist.h
@@ -49,7 +49,6 @@ public:
 	void setList(const Common::U32StringArray &list, const ColorList *colors = nullptr);
 	void setAttributeValues(const Common::U32StringArray &attrValues);
 	void setMetadataNames(const Common::StringMap &metadata);
-	const Common::U32StringArray &getList() const { return _dataList; }
 
 	void append(const Common::String &s, ThemeEngine::FontColor color = ThemeEngine::kFontColorNormal);
 	void setGroupHeaderFormat(const Common::U32String &prefix, const Common::U32String &suffix);
diff --git a/gui/widgets/list.cpp b/gui/widgets/list.cpp
index b3b7166fc4f..ed263ad9509 100644
--- a/gui/widgets/list.cpp
+++ b/gui/widgets/list.cpp
@@ -116,6 +116,21 @@ ListWidget::ListWidget(Dialog *boss, int x, int y, int w, int h, const Common::U
 	_scrollBarWidth = 0;
 }
 
+void ListWidget::copyListData(const Common::U32StringArray &list) {
+	Common::U32String stripped;
+
+	_dataList.clear();
+	_cleanedList.clear();
+
+	for (uint i = 0; i < list.size(); ++i) {
+		stripped = stripGUIformatting(list[i]);
+
+		_dataList.push_back(ListData(list[i], stripped));
+		_cleanedList.push_back(stripped);
+	}
+}
+
+
 bool ListWidget::containsWidget(Widget *w) const {
 	if (w == _scrollBar || _scrollBar->containsWidget(w))
 		return true;
@@ -179,7 +194,7 @@ void ListWidget::setList(const Common::U32StringArray &list, const ColorList *co
 		drawCaret(true);
 
 	// Copy everything
-	_dataList = list;
+	copyListData(list);
 	_list = list;
 	_filter.clear();
 	_listIndex.clear();
@@ -214,7 +229,9 @@ void ListWidget::append(const Common::String &s, ThemeEngine::FontColor color) {
 		_listColors.push_back(color);
 	}
 
-	_dataList.push_back(s);
+	Common::U32String stripped = stripGUIformatting(s);
+	_dataList.push_back(ListData(s, stripped));
+	_cleanedList.push_back(stripped);
 	_list.push_back(s);
 
 	setFilter(_filter, false);
@@ -763,7 +780,12 @@ void ListWidget::setFilter(const Common::U32String &filter, bool redraw) {
 
 	if (_filter.empty()) {
 		// No filter -> display everything
-		_list = _dataList;
+
+		_list.clear();
+
+		for (uint i = 0; i < _dataList.size(); ++i)
+			_list.push_back(_dataList[i].orig);
+
 		_listIndex.clear();
 	} else {
 		// Restrict the list to everything which matches all tokens in _filter, ignoring case.
@@ -775,8 +797,8 @@ void ListWidget::setFilter(const Common::U32String &filter, bool redraw) {
 		_list.clear();
 		_listIndex.clear();
 
-		for (Common::U32StringArray::iterator i = _dataList.begin(); i != _dataList.end(); ++i, ++n) {
-			tmp = *i;
+		for (auto i = _dataList.begin(); i != _dataList.end(); ++i, ++n) {
+			tmp = i->clean;
 			tmp.toLowercase();
 			bool matches = true;
 			tok.reset();
@@ -788,7 +810,7 @@ void ListWidget::setFilter(const Common::U32String &filter, bool redraw) {
 			}
 
 			if (matches) {
-				_list.push_back(*i);
+				_list.push_back(i->orig);
 				_listIndex.push_back(n);
 			}
 		}
diff --git a/gui/widgets/list.h b/gui/widgets/list.h
index b707a01db61..d528e6077c7 100644
--- a/gui/widgets/list.h
+++ b/gui/widgets/list.h
@@ -51,9 +51,20 @@ public:
 	typedef Common::Array<ThemeEngine::FontColor> ColorList;
 
 	typedef bool (*FilterMatcher)(void *arg, int idx, const Common::U32String &item, Common::U32String token);
+
+	struct ListData {
+		Common::U32String orig;
+		Common::U32String clean;
+
+		ListData(Common::U32String o, Common::U32String c) { orig = o; clean = c; }
+	};
+
+	typedef Common::Array<ListData> ListDataArray;
+
 protected:
 	Common::U32StringArray	_list;
-	Common::U32StringArray	_dataList;
+	Common::U32StringArray	_cleanedList;
+	ListDataArray	_dataList;
 	ColorList		_listColors;
 	Common::Array<int>	_listIndex;
 	bool			_editable;
@@ -97,7 +108,7 @@ public:
 	Widget *findWidget(int x, int y) override;
 
 	void setList(const Common::U32StringArray &list, const ColorList *colors = nullptr);
-	const Common::U32StringArray &getList()	const			{ return _dataList; }
+	const Common::U32StringArray &getList()	const			{ return _cleanedList; }
 
 	void append(const Common::String &s, ThemeEngine::FontColor color = ThemeEngine::kFontColorNormal);
 
@@ -159,6 +170,8 @@ protected:
 
 	Common::Rect getEditRect() const override;
 
+	void copyListData(const Common::U32StringArray &list);
+
 	void receivedFocusWidget() override;
 	void lostFocusWidget() override;
 	void checkBounds();


Commit: 828192db591545e888c2c9f0bc0167ee9d66a00e
    https://github.com/scummvm/scummvm/commit/828192db591545e888c2c9f0bc0167ee9d66a00e
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-05-28T10:46:37+02:00

Commit Message:
GUI: Reduced code duplication in GroupedListWidget

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


diff --git a/gui/widgets/groupedlist.cpp b/gui/widgets/groupedlist.cpp
index 00ea08cfb4f..e74350f6c26 100644
--- a/gui/widgets/groupedlist.cpp
+++ b/gui/widgets/groupedlist.cpp
@@ -43,30 +43,8 @@ GroupedListWidget::GroupedListWidget(Dialog *boss, const Common::String &name, c
 }
 
 void GroupedListWidget::setList(const Common::U32StringArray &list, const ColorList *colors) {
-	if (_editMode && _caretVisible)
-		drawCaret(true);
+	ListWidget::setList(list, colors);
 
-	// Copy everything
-	copyListData(list);
-	_list = list;
-
-	_filter.clear();
-	_listIndex.clear();
-	_listColors.clear();
-
-	if (colors) {
-		_listColors = *colors;
-		assert(_listColors.size() == _dataList.size());
-	}
-
-	int size = list.size();
-	if (_currentPos >= size)
-		_currentPos = size - 1;
-	if (_currentPos < 0)
-		_currentPos = 0;
-	_selectedItem = -1;
-	_editMode = false;
-	g_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);
 	groupByAttribute();
 	scrollBarRecalc();
 }
@@ -272,41 +250,6 @@ void GroupedListWidget::handleCommand(CommandSender *sender, uint32 cmd, uint32
 	}
 }
 
-void GroupedListWidget::reflowLayout() {
-	Widget::reflowLayout();
-
-	_leftPadding = g_gui.xmlEval()->getVar("Globals.ListWidget.Padding.Left", 0);
-	_rightPadding = g_gui.xmlEval()->getVar("Globals.ListWidget.Padding.Right", 0);
-	_topPadding = g_gui.xmlEval()->getVar("Globals.ListWidget.Padding.Top", 0);
-	_bottomPadding = g_gui.xmlEval()->getVar("Globals.ListWidget.Padding.Bottom", 0);
-	_hlLeftPadding = g_gui.xmlEval()->getVar("Globals.ListWidget.hlLeftPadding", 0);
-	_hlRightPadding = g_gui.xmlEval()->getVar("Globals.ListWidget.hlRightPadding", 0);
-
-	_scrollBarWidth = g_gui.xmlEval()->getVar("Globals.Scrollbar.Width", 0);
-
-	// HACK: Once we take padding into account, there are times where
-	// integer rounding leaves a big chunk of white space in the bottom
-	// of the list.
-	// We do a rough rounding on the decimal places of Entries Per Page,
-	// to add another entry even if it goes a tad over the padding.
-	frac_t entriesPerPage = intToFrac(_h - _topPadding - _bottomPadding) / kLineHeight;
-
-	// Our threshold before we add another entry is 0.9375 (0xF000 with FRAC_BITS being 16).
-	const frac_t threshold = intToFrac(15) / 16;
-
-	if ((frac_t)(entriesPerPage & FRAC_LO_MASK) >= threshold)
-		entriesPerPage += FRAC_ONE;
-
-	_entriesPerPage = fracToInt(entriesPerPage);
-	assert(_entriesPerPage > 0);
-
-	if (_scrollBar) {
-		_scrollBar->resize(_w - _scrollBarWidth, 0, _scrollBarWidth, _h, false);
-		scrollBarRecalc();
-		scrollToCurrent();
-	}
-}
-
 void GroupedListWidget::toggleGroup(int groupID) {
 	_groupExpanded[groupID] = !_groupExpanded[groupID];
 	sortGroups();
@@ -396,21 +339,6 @@ void GroupedListWidget::drawWidget() {
 	}
 }
 
-void GroupedListWidget::scrollToCurrent() {
-	// Only do something if the current item is not in our view port
-	if (_selectedItem != -1 && _selectedItem < _currentPos) {
-		// it's above our view
-		_currentPos = _selectedItem;
-	} else if (_selectedItem >= _currentPos + _entriesPerPage ) {
-		// it's below our view
-		_currentPos = _selectedItem - _entriesPerPage + 1;
-	}
-
-	checkBounds();
-	_scrollBar->_currentPos = _currentPos;
-	_scrollBar->recalc();
-}
-
 void GroupedListWidget::setFilter(const Common::U32String &filter, bool redraw) {
 	// FIXME: This method does not deal correctly with edit mode!
 	// Until we fix that, let's make sure it isn't called while editing takes place
diff --git a/gui/widgets/groupedlist.h b/gui/widgets/groupedlist.h
index 16ec124f232..292feb31009 100644
--- a/gui/widgets/groupedlist.h
+++ b/gui/widgets/groupedlist.h
@@ -50,7 +50,6 @@ public:
 	void setAttributeValues(const Common::U32StringArray &attrValues);
 	void setMetadataNames(const Common::StringMap &metadata);
 
-	void append(const Common::String &s, ThemeEngine::FontColor color = ThemeEngine::kFontColorNormal);
 	void setGroupHeaderFormat(const Common::U32String &prefix, const Common::U32String &suffix);
 	void groupByAttribute();
 
@@ -64,8 +63,6 @@ public:
 	void handleMouseWheel(int x, int y, int direction) override;
 	void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
 
-	void reflowLayout() override;
-
 	void setGroupsVisibility(bool val) { _groupsVisible = val; }
 
 	void startEditMode() override { error("Edit mode is not supported for Grouped Lists"); }
@@ -74,8 +71,6 @@ protected:
 	void sortGroups();
 	void toggleGroup(int groupID);
 	void drawWidget() override;
-
-	void scrollToCurrent();
 };
 
 } // End of namespace GUI




More information about the Scummvm-git-logs mailing list