Fix handling spacing in collection editors to align label in a proper way with margin
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user