Updating control size flags now notifies parent container.

This commit is contained in:
Pieter-Jan Briers
2019-07-29 23:05:15 +02:00
parent 39a2c9db86
commit a1d899ee31
10 changed files with 43 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
@@ -9,6 +9,7 @@ using Robust.Client.Interfaces.Graphics;
using Robust.Client.Interfaces.ResourceManagement;
using Robust.Client.Interfaces.UserInterface;
using Robust.Client.ResourceManagement.ResourceTypes;
using Robust.Client.UserInterface.Controls;
using Robust.Client.Utility;
using Robust.Shared.Interfaces.Reflection;
using Robust.Shared.IoC;
@@ -72,6 +73,8 @@ namespace Robust.Client.UserInterface
public event Action<Control> OnVisibilityChanged;
private int _uniqueChildId;
private SizeFlags _sizeFlagsHorizontal = SizeFlags.Fill;
private SizeFlags _sizeFlagsVertical = SizeFlags.Fill;
/// <summary>
/// The name of this control.
@@ -630,13 +633,37 @@ namespace Robust.Client.UserInterface
/// Horizontal size flags for container layout.
/// </summary>
[ViewVariables]
public SizeFlags SizeFlagsHorizontal { get; set; } = SizeFlags.Fill;
public SizeFlags SizeFlagsHorizontal
{
get => _sizeFlagsHorizontal;
set
{
_sizeFlagsHorizontal = value;
if (Parent is Container container)
{
container.SortChildren();
}
}
}
/// <summary>
/// Vertical size flags for container layout.
/// </summary>
[ViewVariables]
public SizeFlags SizeFlagsVertical { get; set; } = SizeFlags.Fill;
public SizeFlags SizeFlagsVertical
{
get => _sizeFlagsVertical;
set
{
_sizeFlagsVertical = value;
if (Parent is Container container)
{
container.SortChildren();
}
}
}
/// <summary>
/// Stretch ratio used to give shared of the available space in case multiple siblings are set to expand
@@ -656,8 +683,11 @@ namespace Robust.Client.UserInterface
throw new ArgumentOutOfRangeException(nameof(value), value, "Value must be greater than zero.");
}
// TODO: Notify parent container.
_sizeFlagsStretchRatio = value;
if (Parent is Container container)
{
container.SortChildren();
}
}
}

View File

@@ -44,7 +44,7 @@ namespace Robust.Client.UserInterface.Controls
public int? SeparationOverride { get; set; }
protected override void SortChildren()
protected internal override void SortChildren()
{
var separation = (int) (ActualSeparation * UIScale);

View File

@@ -8,7 +8,7 @@ namespace Robust.Client.UserInterface.Controls
[ControlWrap("CenterContainer")]
public class CenterContainer : Container
{
protected override void SortChildren()
protected internal override void SortChildren()
{
foreach (var child in Children)
{

View File

@@ -20,7 +20,7 @@ namespace Robust.Client.UserInterface.Controls
/// <summary>
/// Called when the container should re-sort its children.
/// </summary>
protected virtual void SortChildren()
protected internal virtual void SortChildren()
{
}

View File

@@ -132,7 +132,7 @@ namespace Robust.Client.UserInterface.Controls
return totalMinSize / UIScale;
}
protected override void SortChildren()
protected internal override void SortChildren()
{
var rows = Rows;

View File

@@ -19,7 +19,7 @@ namespace Robust.Client.UserInterface.Controls
public int? MarginRightOverride { get; set; }
public int? MarginLeftOverride { get; set; }
protected override void SortChildren()
protected internal override void SortChildren()
{
var top = MarginTopOverride ?? 0;
var bottom = MarginBottomOverride ?? 0;

View File

@@ -34,7 +34,7 @@ namespace Robust.Client.UserInterface.Controls
style?.Draw(handle, PixelSizeBox);
}
protected override void SortChildren()
protected internal override void SortChildren()
{
base.SortChildren();

View File

@@ -62,7 +62,7 @@ namespace Robust.Client.UserInterface.Controls
_vScrollBar.OnValueChanged += ev;
}
protected override void SortChildren()
protected internal override void SortChildren()
{
if (_vScrollBar?.Parent == null || _hScrollBar?.Parent == null)
{

View File

@@ -11,7 +11,7 @@ namespace Robust.Client.UserInterface.Controls
private protected abstract bool Vertical { get; }
protected override void SortChildren()
protected internal override void SortChildren()
{
base.SortChildren();

View File

@@ -230,7 +230,7 @@ namespace Robust.Client.UserInterface.Controls
FitChildInPixelBox(child, _getContentBox());
}
protected override void SortChildren()
protected internal override void SortChildren()
{
base.SortChildren();