diff options
author | Jacques Lucke <jacques@blender.org> | 2022-04-25 17:00:43 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2022-04-25 17:00:58 +0300 |
commit | 26afa23b3b81234e60a57c28ed447e5fb920e4b3 (patch) | |
tree | 64b85ca363d551870258d2aefc5b1c303a560a36 /source/blender | |
parent | c2751f8a11fa6bd37b2c092ce8f893bc843bfe1e (diff) |
Fix: use natural string sorting for attribute names
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/space_node/node_draw.cc | 21 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_nodes.cc | 19 |
2 files changed, 30 insertions, 10 deletions
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); |