Files
sbox-public/game/addons/base/code/UI/PopupButton.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

46 lines
877 B
C#

namespace Sandbox.UI
{
/// <summary>
/// A button that opens a <see cref="Popup"/> panel.
/// Useless on its own - you need to implement Open
/// </summary>
public abstract class PopupButton : Button
{
/// <summary>
/// The opened <see cref="UI.Popup"/>.
/// </summary>
protected Popup Popup;
public PopupButton()
{
AddClass( "popupbutton" );
}
protected override void OnClick( MousePanelEvent e )
{
base.OnClick( e );
Open();
}
/// <summary>
/// Open a popup. You should set <see cref="Popup"/> here.
/// </summary>
public abstract void Open();
public override void Tick()
{
base.Tick();
SetClass( "open", Popup.IsValid() && !Popup.IsDeleting );
SetClass( "active", Popup.IsValid() && !Popup.IsDeleting );
if ( Popup.IsValid() )
{
Popup.Style.Width = Box.Rect.Width * ScaleFromScreen;
}
}
}
}