Files
sbox-public/engine/Sandbox.Engine/Systems/UI/Panel/Panel.Util.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

53 lines
1.0 KiB
C#

using System.Threading;
namespace Sandbox.UI;
public partial class Panel
{
internal float TimeNow => PanelRealTime.TimeNow;
internal float TimeDelta => PanelRealTime.TimeDelta;
/// <summary>
/// Can be used to store random data without sub-classing the panel.
/// </summary>
[Hide]
public object UserData { get; set; }
CancellationTokenSource _deleteTokenSource;
/// <summary>
/// Get a token that is cancelled when the panel is deleted
/// </summary>
[Hide]
public CancellationToken DeletionToken
{
get
{
if ( IsDeleting || !IsValid )
return CancellationToken.None;
_deleteTokenSource ??= new CancellationTokenSource();
return _deleteTokenSource.Token;
}
}
}
static class PanelRealTime
{
public static float TimeNow;
public static float TimeDelta;
public static void Update()
{
var delta = RealTime.Delta;
// If we're running lower than 30fps, clamp it to avoid weirdness
delta = delta.Clamp( 0.000f, 1.0f / 30.0f );
TimeDelta = delta;
TimeNow += TimeDelta;
}
}