Просмотр исходного кода

Fix selection issue when multiple options have the same value

Michael Ragazzon 4 лет назад
Родитель
Сommit
ca1a674731
2 измененных файлов с 18 добавлено и 11 удалено
  1. 17 11
      Source/Core/Elements/WidgetDropDown.cpp
  2. 1 0
      Source/Core/Elements/WidgetDropDown.h

+ 17 - 11
Source/Core/Elements/WidgetDropDown.cpp

@@ -44,6 +44,7 @@ WidgetDropDown::WidgetDropDown(ElementFormControl* element)
 {
 {
 	parent_element = element;
 	parent_element = element;
 
 
+	lock_selection = false;
 	selection_dirty = false;
 	selection_dirty = false;
 	box_layout_dirty = false;
 	box_layout_dirty = false;
 	value_rml_dirty = false;
 	value_rml_dirty = false;
@@ -265,21 +266,24 @@ void WidgetDropDown::OnLayout()
 // Sets the value of the widget.
 // Sets the value of the widget.
 void WidgetDropDown::OnValueChange(const String& value)
 void WidgetDropDown::OnValueChange(const String& value)
 {
 {
-	Element* select_option = nullptr;
-	const int num_options = selection_element->GetNumChildren();
-	for (int i = 0; i < num_options; i++)
+	if (!lock_selection)
 	{
 	{
-		Element* option = selection_element->GetChild(i);
-		Variant* variant = option->GetAttribute("value");
-		if (variant && variant->Get<String>() == value)
+		Element* select_option = nullptr;
+		const int num_options = selection_element->GetNumChildren();
+		for (int i = 0; i < num_options; i++)
 		{
 		{
-			select_option = option;
-			break;
+			Element* option = selection_element->GetChild(i);
+			Variant* variant = option->GetAttribute("value");
+			if (variant && variant->Get<String>() == value)
+			{
+				select_option = option;
+				break;
+			}
 		}
 		}
-	}
 
 
-	if (select_option && !select_option->HasAttribute("selected"))
-		SetSelection(select_option, true);
+		if (select_option && !select_option->HasAttribute("selected"))
+			SetSelection(select_option);
+	}
 
 
 	Dictionary parameters;
 	Dictionary parameters;
 	parameters["value"] = value;
 	parameters["value"] = value;
@@ -312,7 +316,9 @@ void WidgetDropDown::SetSelection(Element* select_option, bool force)
 
 
 	if (force || (old_value != new_value))
 	if (force || (old_value != new_value))
 	{
 	{
+		lock_selection = true;
 		parent_element->SetAttribute("value", new_value);
 		parent_element->SetAttribute("value", new_value);
+		lock_selection = false;
 	}
 	}
 
 
 	value_rml_dirty = true;
 	value_rml_dirty = true;

+ 1 - 0
Source/Core/Elements/WidgetDropDown.h

@@ -116,6 +116,7 @@ private:
 	Element* selection_element;
 	Element* selection_element;
 	Element* value_element;
 	Element* value_element;
 
 
+	bool lock_selection;
 	bool selection_dirty;
 	bool selection_dirty;
 	bool value_rml_dirty;
 	bool value_rml_dirty;
 	bool value_layout_dirty;
 	bool value_layout_dirty;