Fix handling spacing in collection editors to align label in a proper way with margin

This commit is contained in:
Wojtek Figat
2021-04-22 10:59:35 +02:00
parent 04836f037d
commit f7837f99c2
4 changed files with 49 additions and 3 deletions

View File

@@ -154,9 +154,20 @@ namespace FlaxEditor.CustomEditors.Editors
if (i != 0 && spacing > 0f)
{
if (layout.Children.Count > 0 && layout.Children[layout.Children.Count - 1] is PropertiesListElement propertiesListElement)
{
if (propertiesListElement.Labels.Count > 0)
{
var label = propertiesListElement.Labels[propertiesListElement.Labels.Count - 1];
var margin = label.Margin;
margin.Bottom += spacing;
label.Margin = margin;
}
propertiesListElement.Space(spacing);
}
else
{
layout.Space(spacing);
}
}
var overrideEditor = overrideEditorType != null ? (CustomEditor)Activator.CreateInstance(overrideEditorType) : null;

View File

@@ -61,7 +61,7 @@ namespace FlaxEditor.CustomEditors.Editors
var keyType = _editor.Values.Type.GetGenericArguments()[0];
if (keyType == typeof(string) || keyType.IsPrimitive)
{
var popup = RenamePopup.Show(Parent, Bounds, Text, false);
var popup = RenamePopup.Show(Parent, Rectangle.Margin(Bounds, Margin), Text, false);
popup.Validate += (renamePopup, value) =>
{
object newKey;
@@ -86,7 +86,7 @@ namespace FlaxEditor.CustomEditors.Editors
}
else if (keyType.IsEnum)
{
var popup = RenamePopup.Show(Parent, Bounds, Text, false);
var popup = RenamePopup.Show(Parent, Rectangle.Margin(Bounds, Margin), Text, false);
var picker = new EnumComboBox(keyType)
{
AnchorPreset = AnchorPresets.StretchAll,
@@ -220,9 +220,20 @@ namespace FlaxEditor.CustomEditors.Editors
if (i != 0 && spacing > 0f)
{
if (layout.Children.Count > 0 && layout.Children[layout.Children.Count - 1] is PropertiesListElement propertiesListElement)
{
if (propertiesListElement.Labels.Count > 0)
{
var label = propertiesListElement.Labels[propertiesListElement.Labels.Count - 1];
var margin = label.Margin;
margin.Bottom += spacing;
label.Margin = margin;
}
propertiesListElement.Space(spacing);
}
else
{
layout.Space(spacing);
}
}
var key = keys.ElementAt(i);

View File

@@ -112,7 +112,7 @@ namespace FlaxEditor.CustomEditors
OnAddElement(element);
return element;
}
/// <summary>
/// Adds new horizontal panel element.
/// </summary>
@@ -690,6 +690,17 @@ namespace FlaxEditor.CustomEditors
return element;
}
/// <summary>
/// Adds custom element to the layout.
/// </summary>
/// <param name="element">The element.</param>
public void AddElement(LayoutElement element)
{
if (element == null)
throw new ArgumentNullException();
OnAddElement(element);
}
/// <summary>
/// Called when element is added to the layout.
/// </summary>

View File

@@ -285,6 +285,19 @@ namespace FlaxEngine
return new Rectangle(Location - toExpand * 0.5f, Size + toExpand);
}
/// <summary>
/// Calculates a rectangle that includes the margins (inside).
/// </summary>
/// <param name="value">The rectangle.</param>
/// <param name="margin">The margin to apply to the rectangle.</param>
/// <returns>Rectangle inside the given rectangle after applying margins inside it.</returns>
public static Rectangle Margin(Rectangle value, GUI.Margin margin)
{
value.Location += margin.Location;
value.Size -= margin.Size;
return value;
}
/// <summary>
/// Calculates a rectangle that contains the union of a and b rectangles
/// </summary>