Files
RobustToolbox/Robust.Client/UserInterface/Controls/PanelContainer.cs
T
Pieter-Jan BriersandGitHub cb5f2ffae1 Refactor UI system. (#843)
* Refactor UI system.

Deferred updating is used for styling & layout. This fixes the awful time complexity of containers.
Removed SetDefaults and Initialize. They were a bad idea alright.

* Fix build on .NET Framework.
2019-08-14 22:03:51 +02:00

65 lines
1.7 KiB
C#

using JetBrains.Annotations;
using Robust.Client.Graphics.Drawing;
using Robust.Shared.Maths;
namespace Robust.Client.UserInterface.Controls
{
public class PanelContainer : Container
{
public const string StylePropertyPanel = "panel";
private StyleBox _panelOverride;
public StyleBox PanelOverride
{
get => _panelOverride;
set => _panelOverride = value;
}
protected internal override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);
var style = _getStyleBox();
style?.Draw(handle, PixelSizeBox);
}
protected internal override void SortChildren()
{
base.SortChildren();
var contentBox = _getStyleBox()?.GetContentBox(PixelSizeBox) ?? SizeBox;
foreach (var child in Children)
{
FitChildInPixelBox(child, (UIBox2i) contentBox);
}
}
protected override Vector2 CalculateMinimumSize()
{
var styleSize = _getStyleBox()?.MinimumSize ?? Vector2.Zero;
var childSize = Vector2.Zero;
foreach (var child in Children)
{
childSize = Vector2.ComponentMax(childSize, child.CombinedMinimumSize);
}
return styleSize / UIScale + childSize;
}
[System.Diagnostics.Contracts.Pure]
[CanBeNull]
private StyleBox _getStyleBox()
{
if (_panelOverride != null)
{
return _panelOverride;
}
TryGetStyleProperty(StylePropertyPanel, out StyleBox box);
return box;
}
}
}