title: Unity3D Custom editor focus change with EditorGUILayout.LabelField
body: <p>I've an issue working with custom editor, my editing focus is changed without any action from my part.
  Basically, this is a screen of my custom editor in a neutral state (just added empty translation entity):</p>
  
  <p><a href="https://i.stack.imgur.com/Zt48l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Zt48l.png" alt="enter image description here"></a></p>
  
  <p>And this is a screen when my focus got change without reason. As you can see, my editor detected that 2 keys was the same and notify it by a message at the top of the box, the issue is that I was actually editing the second box's "key" field, and my focus changed on the first box (highlighted blue). If I don't display the warning message, I don't have any issue so I guess it comes from there..</p>
  
  <p><a href="https://i.stack.imgur.com/y4EuP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/y4EuP.png" alt="enter image description here"></a></p>
  
  <p>This is my custom editor script :</p>
  
  <pre><code>    [CustomEditor(typeof(InternationalizationDatabaseSO))]
      public class InternationalizationDatabaseSOEditor : Editor
      {
          #region Constantes
          private const string ITEMS_PROPERTY_NAME = "_mItems";
  
          private const string ITEM_CATEGORY_NAME = "_mCategory";
          private const string ITEM_KEY_NAME = "_mKey";
          private const string ITEM_VALUES_NAME = "_mValues";
  
          private const string ITEM_VALUE_LANGUAGE = "_mLanguage";
          private const string ITEM_VALUE_VALUE = "_mValue";
          #endregion
  
          #region Attributs
          private InternationalizationDatabaseSO _mDatabase;
          #endregion
  
          #region Methods
          private void OnEnable()
          {
              Init();
          }
  
          private void Init()
          {
              _mDatabase = target as InternationalizationDatabaseSO;
          }
  
          public override void OnInspectorGUI()
          {
              serializedObject.Update();
  
              SerializedProperty itemsProperty = serializedObject.FindProperty(ITEMS_PROPERTY_NAME);
  
              int arraySize = itemsProperty.arraySize;
  
              EditorGUI.BeginDisabledGroup(false);
              {
                  EditorGUILayout.BeginHorizontal();
                  {
                      GUILayout.FlexibleSpace();
                      if (OnInspectorGUIButton("+", 40, 25, Color.white, Color.green))
                      {
                          itemsProperty.arraySize++;
                          itemsProperty.GetArrayElementAtIndex(itemsProperty.arraySize - 1).FindPropertyRelative(ITEM_CATEGORY_NAME).stringValue = "";
                          itemsProperty.GetArrayElementAtIndex(itemsProperty.arraySize - 1).FindPropertyRelative(ITEM_KEY_NAME).stringValue = "";
                          serializedObject.ApplyModifiedProperties();
                          Init();
                          return;
                      }
                  }
                  EditorGUILayout.EndHorizontal();
                  EditorGUILayout.Space();
  
                  for(int i = 0; i &lt; arraySize; i++)
                  {
                      if(OnInspectorGUIItem(i) == false)
                      {
                          serializedObject.ApplyModifiedProperties();
                          Init();
                          return;
                      }
                  }
              }
  
              EditorGUI.EndDisabledGroup();
              serializedObject.ApplyModifiedProperties();
          }
  
          private bool OnInspectorGUIItem(int index)
          {
              SerializedProperty itemsProperty = serializedObject.FindProperty(ITEMS_PROPERTY_NAME);
  
              SerializedProperty itemCategory = itemsProperty.GetArrayElementAtIndex(index).FindPropertyRelative(ITEM_CATEGORY_NAME);
              SerializedProperty itemKey = itemsProperty.GetArrayElementAtIndex(index).FindPropertyRelative(ITEM_KEY_NAME);
  
              EditorGUI.indentLevel += 1;
  
              EditorGUILayout.BeginVertical(GUI.skin.box);
              {
                  EditorGUILayout.Space();
                  EditorGUILayout.BeginHorizontal();
                  {
                      EditorGUILayout.BeginVertical();
                      {
                          if(KeyAlreadyExist(index, itemKey.stringValue))
                          {
                              OnInspectorGUIText("Key already exists", 12, Color.red, FontStyle.Bold, false);
                          }
                          OnInspectorGUIText("Key : " + itemKey.stringValue, 12, FontStyle.Normal, false);
                      }
                      EditorGUILayout.EndVertical();
  
                      GUILayout.FlexibleSpace();
                      if(OnInspectorGUIButton("-", 40, 25, Color.white, Color.red))
                      {
                          itemCategory.stringValue = "";
                          itemKey.stringValue = "";
                          itemsProperty.DeleteArrayElementAtIndex(index);
                          return false;
                      }
                  }
                  EditorGUILayout.EndHorizontal();
  
                  EditorGUILayout.Space();
  
                  EditorGUILayout.BeginVertical();
                  {
                      GUIStyle style = EditorStyles.foldout;
                      style.fontSize = 15;
                      style.fontStyle = FontStyle.Bold;
  
  
                      itemCategory.isExpanded = EditorGUILayout.Foldout(itemCategory.isExpanded, "General informations", style);
                      if(itemCategory.isExpanded)
                      {
                          EditorGUILayout.Space();
                          EditorGUILayout.PropertyField(itemCategory, new GUIContent("Category"));
                          EditorGUILayout.PropertyField(itemKey, new GUIContent("Key"));
                      }
  
                      if(OnInspectorGUIItemLanguage(index, itemsProperty.GetArrayElementAtIndex(index)) == false)
                      {
                          return false;
                      }
                  }
                  EditorGUILayout.EndVertical();
              }
              EditorGUILayout.EndVertical();
              EditorGUI.indentLevel -= 1;
              return true;
          }
  
          private bool OnInspectorGUIItemLanguage(int index, SerializedProperty propertyItem)
          {
              EditorGUILayout.BeginVertical();
              {
                  GUIStyle style = EditorStyles.foldout;
                  style.fontSize = 15;
                  style.normal.textColor = Color.black;
                  style.fontStyle = FontStyle.Bold;
  
                  SerializedProperty itemValues = propertyItem.FindPropertyRelative(ITEM_VALUES_NAME);
                  itemValues.isExpanded = EditorGUILayout.Foldout(itemValues.isExpanded, "Languages informations", style);
                  if(itemValues.isExpanded)
                  {
                      EditorGUILayout.Space();
                      EditorGUILayout.BeginVertical();
                      {
                          EditorGUILayout.BeginHorizontal();
                          {
                              int nbTranslation = itemValues.arraySize;
                              EditorGUILayout.LabelField("Nb translation : " + nbTranslation);
                              GUILayout.FlexibleSpace();
                              if (OnInspectorGUIButton("+", 20, 20, Color.white, Color.green))
                              {
                                  itemValues.arraySize++;
                                  itemValues.GetArrayElementAtIndex(itemValues.arraySize - 1).FindPropertyRelative(ITEM_VALUE_LANGUAGE).intValue = 0;
                                  itemValues.GetArrayElementAtIndex(itemValues.arraySize - 1).FindPropertyRelative(ITEM_VALUE_VALUE).stringValue = "";
                                  return false;
                              }
                          }
                          EditorGUILayout.EndHorizontal();
                          EditorGUILayout.Space();  
                          if (itemValues.arraySize &gt; 0)
                          {
                              string translatedLanguages = "{";
                              foreach (InternationalizationDatabaseItemLanguage item in _mDatabase.Items[index].Values)
                              {
                                  translatedLanguages += item.Language.ToString() + ", ";
                              }
                              if (translatedLanguages.Length &gt; 2)
                              {
                                  translatedLanguages = translatedLanguages.Remove(translatedLanguages.Length - 2);
                              }
                              translatedLanguages += "}";
  
                              //EditorStyles.label.stretchHeight = true;
                              EditorStyles.label.wordWrap = true;
                              EditorGUILayout.LabelField("Translated : \n" + translatedLanguages);
                              EditorGUILayout.Space();
  
                              for (int i = 0; i &lt; itemValues.arraySize; i++)
                              {
                                  EditorGUILayout.BeginVertical(GUI.skin.box);
                                  {
                                      EditorGUILayout.Space();
                                      InternationalizationDatabaseItemLanguage item = _mDatabase.Items[index].Values[i];
                                      SerializedProperty propLanguage = itemValues.GetArrayElementAtIndex(i).FindPropertyRelative(ITEM_VALUE_LANGUAGE);
                                      SerializedProperty propValue = itemValues.GetArrayElementAtIndex(i).FindPropertyRelative(ITEM_VALUE_VALUE);
  
                                      EditorGUILayout.BeginHorizontal();
                                      {
                                          if (LanguageAlreadyExist(index, i, _mDatabase.Items[index].Values[i].Language))
                                          {
                                              OnInspectorGUIText("Warning language translation already exist", 12, Color.red, FontStyle.Bold, false);
                                          }
  
                                          GUILayout.FlexibleSpace();
                                          if (OnInspectorGUIButton("-", 20, 20, Color.white, Color.red))
                                          {
                                              itemValues.DeleteArrayElementAtIndex(i);
                                              return false;
                                          }
                                      }
                                      EditorGUILayout.EndHorizontal();
  
                                      EditorGUILayout.Space();
                                      EditorGUILayout.PropertyField(propLanguage, new GUIContent("Language"));
                                      EditorGUILayout.PrefixLabel("Translation");
                                      propValue.stringValue = EditorGUILayout.TextArea(propValue.stringValue, GUILayout.Height(80));
  
                                  }
                                  EditorGUILayout.Space();
                                  EditorGUILayout.EndVertical();
                                  EditorGUILayout.Space();
                              }
                          }
                      }
                      EditorGUILayout.EndVertical();
                  }
              }
  
              EditorGUILayout.EndVertical();
              EditorGUILayout.Space();
              return true;
          }
  
          private bool KeyAlreadyExist(int currentIndex, string key)
          {
              for(int i = 0; i &lt; _mDatabase.Items.Count; i++)
              {
                  InternationalizationDatabaseItem item = _mDatabase.Items[i];
                  if(currentIndex != i &amp;&amp; item.Key == key &amp;&amp; string.IsNullOrEmpty(key) == false)
                  {
                      return true;
                  }
              }
  
              return false;
          }
  
          private bool LanguageAlreadyExist(int indexInDatabase, int currentIndex, SystemLanguage language)
          {
              for (int i = 0; i &lt; _mDatabase.Items[indexInDatabase].Values.Count; i++)
              {
                  InternationalizationDatabaseItemLanguage item = _mDatabase.Items[indexInDatabase].Values[i];
                  if (currentIndex != i &amp;&amp; item.Language == language)
                  {
                      return true;
                  }
              }
  
              return false;
          }
  
          private void OnInspectorGUIText(string text, FontStyle fontStyle, bool prefixLabel)
          {
              GUIStyle style = new GUIStyle();
              style.fontStyle = fontStyle;
              style.wordWrap = true;
  
              if (prefixLabel)
              {
                  EditorGUILayout.PrefixLabel(text, GUIStyle.none, style);
              }
              else
              {
                  EditorGUILayout.LabelField(text, style);
              }
          }
  
          private void OnInspectorGUIText(string text, int fontSize, FontStyle fontStyle, bool prefixLabel)
          {
              GUIStyle style = new GUIStyle();
              style.fontSize = fontSize;
              style.fontStyle = fontStyle;
              style.wordWrap = true;
  
              if (prefixLabel)
              {
                  EditorGUILayout.PrefixLabel(text, GUIStyle.none, style);
              }
              else
              {
                  EditorGUILayout.LabelField(text, style);
              }
          }
  
          private void OnInspectorGUIText(string text, int fontSize, Color textColor, FontStyle fontStyle, bool prefixLabel)
          {
              GUIStyle style = new GUIStyle();
              style.fontSize = fontSize;
              style.normal.textColor = textColor;
              style.fontStyle = fontStyle;
              style.wordWrap = true;
  
              if(prefixLabel)
              {
                  EditorGUILayout.PrefixLabel(text, GUIStyle.none, style);
              }
              else
              {
                  EditorGUILayout.LabelField(text, style);
              }
          }
  
          private bool OnInspectorGUIButton(string label, int width, int height, Color textColor, Color backgroundColor)
          {
              Color saveColor = GUI.backgroundColor;
              GUILayoutOption[] options = { GUILayout.Width(width), GUILayout.Height(height) };
              GUIStyle style = new GUIStyle(GUI.skin.button);
              style.normal.textColor = textColor;
              GUI.backgroundColor = backgroundColor;
  
              bool pressed = GUILayout.Button(label, style, options);
              GUI.backgroundColor = saveColor;
  
              return pressed;
          }
  
          #endregion
      }
  </code></pre>
  
  <p>Have you any suggestion ? Thanks</p>
  
  <p>Have a nice day. </p>