From 3c1393ecb61cc218281cd0db4f4d48318b851889 Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 9 Aug 2021 17:42:31 +0100 Subject: [PATCH] ChoicePropertyComponent: Allow slightly more relaxed matching in getValue --- .../properties/juce_ChoicePropertyComponent.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/juce_gui_basics/properties/juce_ChoicePropertyComponent.cpp b/modules/juce_gui_basics/properties/juce_ChoicePropertyComponent.cpp index 4a2f8c697b..8396fb5899 100644 --- a/modules/juce_gui_basics/properties/juce_ChoicePropertyComponent.cpp +++ b/modules/juce_gui_basics/properties/juce_ChoicePropertyComponent.cpp @@ -82,14 +82,18 @@ public: var getValue() const override { - if (valueWithDefault != nullptr - && ! valueWithDefault->isUsingDefault()) + if (valueWithDefault != nullptr && ! valueWithDefault->isUsingDefault()) { - auto targetValue = sourceValue.getValue(); + const auto target = sourceValue.getValue(); + const auto equalsWithSameType = [&target] (const var& map) { return map.equalsWithSameType (target); }; - for (auto map : mappings) - if (map.equalsWithSameType (targetValue)) - return mappings.indexOf (map) + 1; + auto iter = std::find_if (mappings.begin(), mappings.end(), equalsWithSameType); + + if (iter == mappings.end()) + iter = std::find (mappings.begin(), mappings.end(), target); + + if (iter != mappings.end()) + return 1 + (int) std::distance (mappings.begin(), iter); } return -1;