mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-02 18:17:09 +02:00
* 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.
88 lines
2.4 KiB
C#
88 lines
2.4 KiB
C#
using System.Diagnostics.Contracts;
|
|
using Robust.Client.Graphics.Drawing;
|
|
using Robust.Shared.Maths;
|
|
|
|
namespace Robust.Client.UserInterface.Controls
|
|
{
|
|
public class ProgressBar : Range
|
|
{
|
|
public const string StylePropertyBackground = "background";
|
|
public const string StylePropertyForeground = "foreground";
|
|
|
|
private StyleBox _backgroundStyleBoxOverride;
|
|
private StyleBox _foregroundStyleBoxOverride;
|
|
|
|
public StyleBox BackgroundStyleBoxOverride
|
|
{
|
|
get => _backgroundStyleBoxOverride;
|
|
set
|
|
{
|
|
_backgroundStyleBoxOverride = value;
|
|
MinimumSizeChanged();
|
|
}
|
|
}
|
|
|
|
public StyleBox ForegroundStyleBoxOverride
|
|
{
|
|
get => _foregroundStyleBoxOverride;
|
|
set
|
|
{
|
|
_foregroundStyleBoxOverride = value;
|
|
MinimumSizeChanged();
|
|
}
|
|
}
|
|
|
|
[Pure]
|
|
private StyleBox _getBackground()
|
|
{
|
|
if (BackgroundStyleBoxOverride != null)
|
|
{
|
|
return BackgroundStyleBoxOverride;
|
|
}
|
|
|
|
TryGetStyleProperty(StylePropertyBackground, out StyleBox ret);
|
|
return ret;
|
|
}
|
|
|
|
[Pure]
|
|
private StyleBox _getForeground()
|
|
{
|
|
if (ForegroundStyleBoxOverride != null)
|
|
{
|
|
return ForegroundStyleBoxOverride;
|
|
}
|
|
|
|
TryGetStyleProperty(StylePropertyForeground, out StyleBox ret);
|
|
return ret;
|
|
}
|
|
|
|
protected internal override void Draw(DrawingHandleScreen handle)
|
|
{
|
|
base.Draw(handle);
|
|
|
|
var bg = _getBackground();
|
|
bg?.Draw(handle, SizeBox);
|
|
|
|
var fg = _getForeground();
|
|
if (fg == null)
|
|
{
|
|
return;
|
|
}
|
|
var minSize = fg.MinimumSize;
|
|
var size = Width * GetAsRatio() - minSize.X;
|
|
if (size > 0)
|
|
{
|
|
fg.Draw(handle, UIBox2.FromDimensions(0, 0, minSize.X + size, Height));
|
|
}
|
|
}
|
|
|
|
protected override Vector2 CalculateMinimumSize()
|
|
{
|
|
var bgSize = _getBackground()?.MinimumSize ?? Vector2.Zero;
|
|
var fgSize = _getForeground()?.MinimumSize ?? Vector2.Zero;
|
|
|
|
return Vector2.ComponentMax(bgSize, fgSize);
|
|
}
|
|
}
|
|
}
|