Fix Label auto sizing to be relative to pivot and sync layout when editing
#2496
This commit is contained in:
@@ -296,6 +296,16 @@ namespace FlaxEditor.CustomEditors
|
||||
_values.Set(_parent.Values, value);
|
||||
}
|
||||
|
||||
private bool SyncParent()
|
||||
{
|
||||
// TODO: add attribute for types that want to sync their contents with a parent
|
||||
var type = Values.Type.Type;
|
||||
if (type == typeof(LocalizedString) ||
|
||||
type == typeof(FontReference))
|
||||
return true;
|
||||
return _parent != null && !(_parent is SyncPointEditor);
|
||||
}
|
||||
|
||||
internal virtual void RefreshInternal()
|
||||
{
|
||||
if (_values == null)
|
||||
@@ -317,7 +327,7 @@ namespace FlaxEditor.CustomEditors
|
||||
|
||||
// Propagate values up (eg. when member of structure gets modified, also structure should be updated as a part of the other object)
|
||||
var obj = _parent;
|
||||
while (obj._parent != null && !(obj._parent is SyncPointEditor))
|
||||
while (obj.SyncParent())
|
||||
{
|
||||
obj.Values.Set(obj._parent.Values, obj.Values);
|
||||
obj = obj._parent;
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace FlaxEngine
|
||||
/// <summary>
|
||||
/// The size of the font characters.
|
||||
/// </summary>
|
||||
[EditorOrder(10), Limit(1, 500, 0.1f), Tooltip("The size of the font characters.")]
|
||||
[EditorOrder(10), Limit(1, 500, 0.5f), Tooltip("The size of the font characters.")]
|
||||
public float Size
|
||||
{
|
||||
get => _size;
|
||||
|
||||
@@ -57,12 +57,9 @@ namespace FlaxEngine.GUI
|
||||
get => _text;
|
||||
set
|
||||
{
|
||||
if (_text != value)
|
||||
{
|
||||
_text = value;
|
||||
_textSize = Float2.Zero;
|
||||
PerformLayout();
|
||||
}
|
||||
_text = value;
|
||||
_textSize = Float2.Zero;
|
||||
PerformLayout();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,15 +126,11 @@ namespace FlaxEngine.GUI
|
||||
get => _font;
|
||||
set
|
||||
{
|
||||
if (_font != value)
|
||||
_font = value;
|
||||
if (_autoWidth || _autoHeight || _autoFitText)
|
||||
{
|
||||
_font = value;
|
||||
|
||||
if (_autoWidth || _autoHeight || _autoFitText)
|
||||
{
|
||||
_textSize = Float2.Zero;
|
||||
PerformLayout();
|
||||
}
|
||||
_textSize = Float2.Zero;
|
||||
PerformLayout();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -161,9 +154,9 @@ namespace FlaxEngine.GUI
|
||||
public bool ClipText { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether set automatic width based on text contents.
|
||||
/// Gets or sets a value indicating whether set automatic width based on text contents. Control size is modified relative to the Pivot.
|
||||
/// </summary>
|
||||
[EditorOrder(85), DefaultValue(false), Tooltip("If checked, the control width will be based on text contents.")]
|
||||
[EditorOrder(85), DefaultValue(false), Tooltip("If checked, the control width will be based on text contents. Control size is modified relative to the Pivot.")]
|
||||
public bool AutoWidth
|
||||
{
|
||||
get => _autoWidth;
|
||||
@@ -178,9 +171,9 @@ namespace FlaxEngine.GUI
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether set automatic height based on text contents.
|
||||
/// Gets or sets a value indicating whether set automatic height based on text contents. Control size is modified relative to the Pivot.
|
||||
/// </summary>
|
||||
[EditorOrder(90), DefaultValue(false), Tooltip("If checked, the control height will be based on text contents.")]
|
||||
[EditorOrder(90), DefaultValue(false), Tooltip("If checked, the control height will be based on text contents. Control size is modified relative to the Pivot.")]
|
||||
public bool AutoHeight
|
||||
{
|
||||
get => _autoHeight;
|
||||
@@ -336,7 +329,9 @@ namespace FlaxEngine.GUI
|
||||
size.X = _textSize.X + Margin.Width;
|
||||
if (_autoHeight)
|
||||
size.Y = _textSize.Y + Margin.Height;
|
||||
var pivotRelative = PivotRelative;
|
||||
Size = size;
|
||||
PivotRelative = pivotRelative;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,6 +234,11 @@ namespace FlaxEngine.GUI
|
||||
if (_bounds.Size.Equals(ref value))
|
||||
return;
|
||||
var bounds = new Rectangle(_bounds.Location, value);
|
||||
if (_pivotRelativeSizing)
|
||||
{
|
||||
var delta = _bounds.Size - value;
|
||||
bounds.Location += delta * Pivot;
|
||||
}
|
||||
SetBounds(ref bounds);
|
||||
}
|
||||
}
|
||||
@@ -566,7 +571,7 @@ namespace FlaxEngine.GUI
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the anchor preset for the control. Can be use to auto-place the control for a given preset or can preserve the current control bounds.
|
||||
/// Sets the anchor preset for the control. Can be used to auto-place the control for a given preset or can preserve the current control bounds.
|
||||
/// </summary>
|
||||
/// <param name="anchorPreset">The anchor preset to set.</param>
|
||||
/// <param name="preserveBounds">True if preserve current control bounds, otherwise will align control position accordingly to the anchor location.</param>
|
||||
|
||||
Reference in New Issue
Block a user