GUI: Use color information from the strings in *ListWidget
This commit is contained in:
parent
cfe040a6aa
commit
1edab21c6e
4 changed files with 48 additions and 35 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue