[Bf-blender-cvs] [26afa23b3b8] master: Fix: use natural string sorting for attribute names
Jacques Lucke
noreply at git.blender.org
Mon Apr 25 16:01:08 CEST 2022
Commit: 26afa23b3b81234e60a57c28ed447e5fb920e4b3
Author: Jacques Lucke
Date: Mon Apr 25 16:00:43 2022 +0200
Branches: master
https://developer.blender.org/rB26afa23b3b81234e60a57c28ed447e5fb920e4b3
Fix: use natural string sorting for attribute names
===================================================================
M source/blender/editors/space_node/node_draw.cc
M source/blender/modifiers/intern/MOD_nodes.cc
===================================================================
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index 47d35ced371..90ab798bafc 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -1703,14 +1703,25 @@ static char *named_attribute_tooltip(bContext *UNUSED(C), void *argN, const char
std::stringstream ss;
ss << TIP_("Accessed attribute names:\n");
- Vector<std::pair<StringRefNull, NamedAttributeUsage>> sorted_used_attribute;
+
+ struct NameWithUsage {
+ StringRefNull name;
+ NamedAttributeUsage usage;
+ };
+
+ Vector<NameWithUsage> sorted_used_attribute;
for (auto &&item : arg.usage_by_attribute.items()) {
sorted_used_attribute.append({item.key, item.value});
}
- std::sort(sorted_used_attribute.begin(), sorted_used_attribute.end());
- for (const std::pair<StringRefNull, NamedAttributeUsage> &attribute : sorted_used_attribute) {
- const StringRefNull name = attribute.first;
- const NamedAttributeUsage usage = attribute.second;
+ std::sort(sorted_used_attribute.begin(),
+ sorted_used_attribute.end(),
+ [](const NameWithUsage &a, const NameWithUsage &b) {
+ return BLI_strcasecmp_natural(a.name.c_str(), b.name.c_str()) <= 0;
+ });
+
+ for (const NameWithUsage &attribute : sorted_used_attribute) {
+ const StringRefNull name = attribute.name;
+ const NamedAttributeUsage usage = attribute.usage;
ss << " \u2022 \"" << name << "\": ";
Vector<std::string> usages;
if ((usage & NamedAttributeUsage::Read) != NamedAttributeUsage::None) {
diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc
index 85b6cf6a2cd..ab33c27e213 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -1648,15 +1648,24 @@ static void used_attributes_panel_draw(const bContext *UNUSED(C), Panel *panel)
return;
}
- Vector<std::pair<StringRefNull, NamedAttributeUsage>> sorted_used_attribute;
+ struct NameWithUsage {
+ StringRefNull name;
+ NamedAttributeUsage usage;
+ };
+
+ Vector<NameWithUsage> sorted_used_attribute;
for (auto &&item : usage_by_attribute.items()) {
sorted_used_attribute.append({item.key, item.value});
}
- std::sort(sorted_used_attribute.begin(), sorted_used_attribute.end());
+ std::sort(sorted_used_attribute.begin(),
+ sorted_used_attribute.end(),
+ [](const NameWithUsage &a, const NameWithUsage &b) {
+ return BLI_strcasecmp_natural(a.name.c_str(), b.name.c_str()) <= 0;
+ });
- for (const auto &pair : sorted_used_attribute) {
- const StringRefNull attribute_name = pair.first;
- const NamedAttributeUsage usage = pair.second;
+ for (const NameWithUsage &attribute : sorted_used_attribute) {
+ const StringRefNull attribute_name = attribute.name;
+ const NamedAttributeUsage usage = attribute.usage;
/* #uiLayoutRowWithHeading doesn't seem to work in this case. */
uiLayout *split = uiLayoutSplit(layout, 0.4f, false);
More information about the Bf-blender-cvs
mailing list