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

View File

@@ -89,7 +89,7 @@ namespace FlaxEditor.CustomEditors.Editors
else if (value is double asDouble)
_element.Value = (float)asDouble;
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.
using System;
using System.Linq;
using FlaxEditor.CustomEditors.Elements;
using FlaxEngine;
@@ -77,7 +78,13 @@ namespace FlaxEditor.CustomEditors.Editors
}
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>"));
}
}
}