Fix UI after editing Dictionary key value

This commit is contained in:
Wojtek Figat
2021-06-17 14:11:25 +02:00
parent f0cb979c5e
commit 5ca2729a56
3 changed files with 18 additions and 2 deletions

View File

@@ -140,6 +140,7 @@ namespace FlaxEditor.CustomEditors.Editors
private bool _readOnly; private bool _readOnly;
private bool _notNullItems; private bool _notNullItems;
private bool _canEditKeys; private bool _canEditKeys;
private bool _keyEdited;
/// <summary> /// <summary>
/// Determines whether this editor[can edit the specified dictionary type. /// Determines whether this editor[can edit the specified dictionary type.
@@ -351,6 +352,7 @@ namespace FlaxEditor.CustomEditors.Editors
newValues[e] = dictionary[e]; newValues[e] = dictionary[e];
} }
SetValue(newValues); SetValue(newValues);
_keyEdited = true; // TODO: use custom UndoAction to rebuild UI after key modification
} }
/// <summary> /// <summary>
@@ -463,6 +465,13 @@ namespace FlaxEditor.CustomEditors.Editors
/// <inheritdoc /> /// <inheritdoc />
public override void Refresh() public override void Refresh()
{ {
if (_keyEdited)
{
_keyEdited = false;
RebuildLayout();
RebuildParentCollection();
}
base.Refresh(); base.Refresh();
// No support for different collections for now // No support for different collections for now

View File

@@ -89,7 +89,7 @@ namespace FlaxEditor.CustomEditors.Editors
else if (value is double asDouble) else if (value is double asDouble)
_element.Value = (float)asDouble; _element.Value = (float)asDouble;
else else
throw new Exception("Invalid value."); throw new Exception(string.Format("Invalid value type {0}.", value?.GetType().ToString() ?? "<null>"));
} }
} }
} }

View File

@@ -1,5 +1,6 @@
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. // Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
using System;
using System.Linq; using System.Linq;
using FlaxEditor.CustomEditors.Elements; using FlaxEditor.CustomEditors.Elements;
using FlaxEngine; using FlaxEngine;
@@ -77,7 +78,13 @@ namespace FlaxEditor.CustomEditors.Editors
} }
else else
{ {
_element.Value = (int)Values[0]; var value = Values[0];
if (value is int asInt)
_element.Value = asInt;
else if (value is float asFloat)
_element.Value = (int)asFloat;
else
throw new Exception(string.Format("Invalid value type {0}.", value?.GetType().ToString() ?? "<null>"));
} }
} }
} }