mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-04-18 05:17:53 -04:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
40 lines
786 B
C#
40 lines
786 B
C#
namespace Sandbox.UI.Navigation;
|
|
|
|
/// <summary>
|
|
/// A panel that will navigate to an href but also have .active class if href is active
|
|
/// </summary>
|
|
[ClassName( "a" )]
|
|
[Alias( "navlink" )]
|
|
public class NavLinkPanel : Panel
|
|
{
|
|
NavigationHost Navigator;
|
|
public string HRef { get; set; }
|
|
public string Match { get; set; }
|
|
|
|
public override void OnParentChanged()
|
|
{
|
|
base.OnParentChanged();
|
|
|
|
Navigator = Ancestors.OfType<NavigationHost>().FirstOrDefault();
|
|
}
|
|
|
|
protected override void OnClick( MousePanelEvent e )
|
|
{
|
|
if ( e.Button == "mouseleft" )
|
|
{
|
|
this.Navigate( HRef );
|
|
}
|
|
}
|
|
|
|
public override void Tick()
|
|
{
|
|
base.Tick();
|
|
|
|
if ( HRef == null )
|
|
return;
|
|
|
|
var active = Navigator?.CurrentUrlMatches( Match ?? HRef ) ?? false;
|
|
SetClass( "active", active );
|
|
}
|
|
}
|