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);
|
drawCaret(true);
|
||||||
|
|
||||||
// Copy everything
|
// Copy everything
|
||||||
_dataList = list;
|
copyListData(list);
|
||||||
_list = list;
|
_list = list;
|
||||||
|
|
||||||
_filter.clear();
|
_filter.clear();
|
||||||
|
@ -84,27 +84,6 @@ void GroupedListWidget::setMetadataNames(const Common::StringMap &metadata) {
|
||||||
_metadataNames = 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) {
|
void GroupedListWidget::setGroupHeaderFormat(const Common::U32String &prefix, const Common::U32String &suffix) {
|
||||||
_groupHeaderPrefix = prefix;
|
_groupHeaderPrefix = prefix;
|
||||||
_groupHeaderSuffix = suffix;
|
_groupHeaderSuffix = suffix;
|
||||||
|
@ -174,7 +153,7 @@ void GroupedListWidget::sortGroups() {
|
||||||
|
|
||||||
if (_groupExpanded[groupID]) {
|
if (_groupExpanded[groupID]) {
|
||||||
for (int *k = _itemsInGroup[groupID].begin(); k != _itemsInGroup[groupID].end(); ++k) {
|
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);
|
_listIndex.push_back(*k);
|
||||||
++curListSize;
|
++curListSize;
|
||||||
}
|
}
|
||||||
|
@ -459,8 +438,8 @@ void GroupedListWidget::setFilter(const Common::U32String &filter, bool redraw)
|
||||||
_list.clear();
|
_list.clear();
|
||||||
_listIndex.clear();
|
_listIndex.clear();
|
||||||
|
|
||||||
for (Common::U32StringArray::iterator i = _dataList.begin(); i != _dataList.end(); ++i, ++n) {
|
for (auto i = _dataList.begin(); i != _dataList.end(); ++i, ++n) {
|
||||||
tmp = *i;
|
tmp = i->clean;
|
||||||
tmp.toLowercase();
|
tmp.toLowercase();
|
||||||
bool matches = true;
|
bool matches = true;
|
||||||
tok.reset();
|
tok.reset();
|
||||||
|
@ -472,7 +451,7 @@ void GroupedListWidget::setFilter(const Common::U32String &filter, bool redraw)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matches) {
|
if (matches) {
|
||||||
_list.push_back(*i);
|
_list.push_back(i->orig);
|
||||||
_listIndex.push_back(n);
|
_listIndex.push_back(n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,6 @@ public:
|
||||||
void setList(const Common::U32StringArray &list, const ColorList *colors = nullptr);
|
void setList(const Common::U32StringArray &list, const ColorList *colors = nullptr);
|
||||||
void setAttributeValues(const Common::U32StringArray &attrValues);
|
void setAttributeValues(const Common::U32StringArray &attrValues);
|
||||||
void setMetadataNames(const Common::StringMap &metadata);
|
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 append(const Common::String &s, ThemeEngine::FontColor color = ThemeEngine::kFontColorNormal);
|
||||||
void setGroupHeaderFormat(const Common::U32String &prefix, const Common::U32String &suffix);
|
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;
|
_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 {
|
bool ListWidget::containsWidget(Widget *w) const {
|
||||||
if (w == _scrollBar || _scrollBar->containsWidget(w))
|
if (w == _scrollBar || _scrollBar->containsWidget(w))
|
||||||
return true;
|
return true;
|
||||||
|
@ -179,7 +194,7 @@ void ListWidget::setList(const Common::U32StringArray &list, const ColorList *co
|
||||||
drawCaret(true);
|
drawCaret(true);
|
||||||
|
|
||||||
// Copy everything
|
// Copy everything
|
||||||
_dataList = list;
|
copyListData(list);
|
||||||
_list = list;
|
_list = list;
|
||||||
_filter.clear();
|
_filter.clear();
|
||||||
_listIndex.clear();
|
_listIndex.clear();
|
||||||
|
@ -214,7 +229,9 @@ void ListWidget::append(const Common::String &s, ThemeEngine::FontColor color) {
|
||||||
_listColors.push_back(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);
|
_list.push_back(s);
|
||||||
|
|
||||||
setFilter(_filter, false);
|
setFilter(_filter, false);
|
||||||
|
@ -763,7 +780,12 @@ void ListWidget::setFilter(const Common::U32String &filter, bool redraw) {
|
||||||
|
|
||||||
if (_filter.empty()) {
|
if (_filter.empty()) {
|
||||||
// No filter -> display everything
|
// No filter -> display everything
|
||||||
_list = _dataList;
|
|
||||||
|
_list.clear();
|
||||||
|
|
||||||
|
for (uint i = 0; i < _dataList.size(); ++i)
|
||||||
|
_list.push_back(_dataList[i].orig);
|
||||||
|
|
||||||
_listIndex.clear();
|
_listIndex.clear();
|
||||||
} else {
|
} else {
|
||||||
// Restrict the list to everything which matches all tokens in _filter, ignoring case.
|
// 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();
|
_list.clear();
|
||||||
_listIndex.clear();
|
_listIndex.clear();
|
||||||
|
|
||||||
for (Common::U32StringArray::iterator i = _dataList.begin(); i != _dataList.end(); ++i, ++n) {
|
for (auto i = _dataList.begin(); i != _dataList.end(); ++i, ++n) {
|
||||||
tmp = *i;
|
tmp = i->clean;
|
||||||
tmp.toLowercase();
|
tmp.toLowercase();
|
||||||
bool matches = true;
|
bool matches = true;
|
||||||
tok.reset();
|
tok.reset();
|
||||||
|
@ -788,7 +810,7 @@ void ListWidget::setFilter(const Common::U32String &filter, bool redraw) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matches) {
|
if (matches) {
|
||||||
_list.push_back(*i);
|
_list.push_back(i->orig);
|
||||||
_listIndex.push_back(n);
|
_listIndex.push_back(n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,9 +51,20 @@ public:
|
||||||
typedef Common::Array<ThemeEngine::FontColor> ColorList;
|
typedef Common::Array<ThemeEngine::FontColor> ColorList;
|
||||||
|
|
||||||
typedef bool (*FilterMatcher)(void *arg, int idx, const Common::U32String &item, Common::U32String token);
|
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:
|
protected:
|
||||||
Common::U32StringArray _list;
|
Common::U32StringArray _list;
|
||||||
Common::U32StringArray _dataList;
|
Common::U32StringArray _cleanedList;
|
||||||
|
ListDataArray _dataList;
|
||||||
ColorList _listColors;
|
ColorList _listColors;
|
||||||
Common::Array<int> _listIndex;
|
Common::Array<int> _listIndex;
|
||||||
bool _editable;
|
bool _editable;
|
||||||
|
@ -97,7 +108,7 @@ public:
|
||||||
Widget *findWidget(int x, int y) override;
|
Widget *findWidget(int x, int y) override;
|
||||||
|
|
||||||
void setList(const Common::U32StringArray &list, const ColorList *colors = nullptr);
|
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);
|
void append(const Common::String &s, ThemeEngine::FontColor color = ThemeEngine::kFontColorNormal);
|
||||||
|
|
||||||
|
@ -159,6 +170,8 @@ protected:
|
||||||
|
|
||||||
Common::Rect getEditRect() const override;
|
Common::Rect getEditRect() const override;
|
||||||
|
|
||||||
|
void copyListData(const Common::U32StringArray &list);
|
||||||
|
|
||||||
void receivedFocusWidget() override;
|
void receivedFocusWidget() override;
|
||||||
void lostFocusWidget() override;
|
void lostFocusWidget() override;
|
||||||
void checkBounds();
|
void checkBounds();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue