Files
OldThink/Content.Client/UserInterface/Controls/StripeBack.cs

125 lines
3.3 KiB
C#
Raw Normal View History

using System.Numerics;
using Robust.Client.Graphics;
2019-10-18 14:28:24 +02:00
using Robust.Client.UserInterface.Controls;
2022-09-11 20:42:12 -07:00
namespace Content.Client.UserInterface.Controls
2019-10-18 14:28:24 +02:00
{
public sealed class StripeBack : Container
2019-10-18 14:28:24 +02:00
{
private const float PadSize = 4;
private const float EdgeSize = 2;
private static readonly Color EdgeColor = Color.FromHex("#525252ff");
private bool _hasTopEdge = true;
private bool _hasBottomEdge = true;
2020-09-07 12:20:22 +02:00
private bool _hasMargins = true;
2019-10-18 14:28:24 +02:00
public const string StylePropertyBackground = "background";
public bool HasTopEdge
{
get => _hasTopEdge;
set
{
_hasTopEdge = value;
2021-02-21 12:38:56 +01:00
InvalidateMeasure();
2019-10-18 14:28:24 +02:00
}
}
public bool HasBottomEdge
{
get => _hasBottomEdge;
set
{
_hasBottomEdge = value;
2021-02-21 12:38:56 +01:00
InvalidateMeasure();
2019-10-18 14:28:24 +02:00
}
}
2020-09-07 12:20:22 +02:00
public bool HasMargins
{
get => _hasMargins;
set
{
_hasMargins = value;
2021-02-21 12:38:56 +01:00
InvalidateMeasure();
2020-09-07 12:20:22 +02:00
}
}
2021-02-21 12:38:56 +01:00
protected override Vector2 MeasureOverride(Vector2 availableSize)
2019-10-18 14:28:24 +02:00
{
2020-09-07 12:20:22 +02:00
var padSize = HasMargins ? PadSize : 0;
2021-02-21 12:38:56 +01:00
var padSizeTotal = 0f;
2020-09-07 12:20:22 +02:00
2019-10-18 14:28:24 +02:00
if (HasBottomEdge)
2021-02-21 12:38:56 +01:00
padSizeTotal += padSize + EdgeSize;
2019-10-18 14:28:24 +02:00
if (HasTopEdge)
2021-02-21 12:38:56 +01:00
padSizeTotal += padSize + EdgeSize;
var size = Vector2.Zero;
availableSize.Y -= padSizeTotal;
foreach (var child in Children)
2019-10-18 14:28:24 +02:00
{
2021-02-21 12:38:56 +01:00
child.Measure(availableSize);
size = Vector2.Max(size, child.DesiredSize);
2019-10-18 14:28:24 +02:00
}
return size + new Vector2(0, padSizeTotal);
2019-10-18 14:28:24 +02:00
}
2021-02-21 12:38:56 +01:00
protected override Vector2 ArrangeOverride(Vector2 finalSize)
2019-10-18 14:28:24 +02:00
{
2021-02-21 12:38:56 +01:00
var box = new UIBox2(Vector2.Zero, finalSize);
2019-10-18 14:28:24 +02:00
2020-09-07 12:20:22 +02:00
var padSize = HasMargins ? PadSize : 0;
2019-10-18 14:28:24 +02:00
if (HasTopEdge)
{
2020-09-07 12:20:22 +02:00
box += (0, padSize + EdgeSize, 0, 0);
2019-10-18 14:28:24 +02:00
}
if (HasBottomEdge)
{
2020-09-07 12:20:22 +02:00
box += (0, 0, 0, -(padSize + EdgeSize));
2019-10-18 14:28:24 +02:00
}
foreach (var child in Children)
{
2021-02-21 12:38:56 +01:00
child.Arrange(box);
2019-10-18 14:28:24 +02:00
}
2021-02-21 12:38:56 +01:00
return finalSize;
2019-10-18 14:28:24 +02:00
}
2021-02-21 12:38:56 +01:00
2019-10-18 14:28:24 +02:00
protected override void Draw(DrawingHandleScreen handle)
{
UIBox2 centerBox = PixelSizeBox;
2020-09-07 12:20:22 +02:00
var padSize = HasMargins ? PadSize : 0;
2019-10-18 14:28:24 +02:00
if (HasTopEdge)
{
2020-09-07 12:20:22 +02:00
centerBox += (0, (padSize + EdgeSize) * UIScale, 0, 0);
handle.DrawRect(new UIBox2(0, padSize * UIScale, PixelWidth, centerBox.Top), EdgeColor);
2019-10-18 14:28:24 +02:00
}
if (HasBottomEdge)
{
2020-09-07 12:20:22 +02:00
centerBox += (0, 0, 0, -((padSize + EdgeSize) * UIScale));
2021-02-21 12:38:56 +01:00
handle.DrawRect(new UIBox2(0, centerBox.Bottom, PixelWidth, PixelHeight - padSize * UIScale),
EdgeColor);
2019-10-18 14:28:24 +02:00
}
GetActualStyleBox()?.Draw(handle, centerBox, UIScale);
2019-10-18 14:28:24 +02:00
}
private StyleBox? GetActualStyleBox()
2019-10-18 14:28:24 +02:00
{
return TryGetStyleProperty(StylePropertyBackground, out StyleBox? box) ? box : null;
2019-10-18 14:28:24 +02:00
}
}
}