@ -1,6 +1,4 @@
# nullable enable
using System.Collections.Generic ;
using System.Collections.Generic ;
namespace Avalonia.Styling.Activators
namespace Avalonia.Styling.Activators
{
{
@ -11,49 +9,35 @@ namespace Avalonia.Styling.Activators
internal class AndActivator : StyleActivatorBase , IStyleActivatorSink
internal class AndActivator : StyleActivatorBase , IStyleActivatorSink
{
{
private List < IStyleActivator > ? _ sources ;
private List < IStyleActivator > ? _ sources ;
private ulong _f lags ;
private ulong _ mask ;
public int Count = > _ sources ? . Count ? ? 0 ;
public int Count = > _ sources ? . Count ? ? 0 ;
public override bool IsActive
{
get
{
if ( _ sources is null )
return false ;
foreach ( var source in _ sources )
{
if ( ! source . IsActive )
return false ;
}
return true ;
}
}
public void Add ( IStyleActivator activator )
public void Add ( IStyleActivator activator )
{
{
if ( IsSubscribed )
throw new AvaloniaInternalException ( "AndActivator is already subscribed." ) ;
_ sources ? ? = new List < IStyleActivator > ( ) ;
_ sources ? ? = new List < IStyleActivator > ( ) ;
_ sources . Add ( activator ) ;
_ sources . Add ( activator ) ;
}
}
void IStyleActivatorSink . OnNext ( bool value , int tag )
void IStyleActivatorSink . OnNext ( bool value , int tag ) = > ReevaluateIsActive ( ) ;
protected override bool EvaluateIsActive ( )
{
{
if ( value )
if ( _ sources is null | | _ sources . Count = = 0 )
{
return true ;
_f lags | = 1 ul < < tag ;
}
var count = _ sources . Count ;
else
var mask = ( 1 ul < < count ) - 1 ;
{
var flags = 0 UL ;
_f lags & = ~ ( 1 ul < < tag ) ;
}
if ( _ mask ! = 0 )
for ( var i = 0 ; i < count ; + + i )
{
{
PublishNext ( _f lags = = _ mask ) ;
if ( _ sources [ i ] . IsActive )
flags | = 1 ul < < i ;
}
}
return flags = = mask ;
}
}
protected override void Initialize ( )
protected override void Initialize ( )
@ -66,9 +50,6 @@ namespace Avalonia.Styling.Activators
{
{
source . Subscribe ( this , i + + ) ;
source . Subscribe ( this , i + + ) ;
}
}
_ mask = ( 1 ul < < Count ) - 1 ;
PublishNext ( _f lags = = _ mask ) ;
}
}
}
}
@ -81,8 +62,6 @@ namespace Avalonia.Styling.Activators
source . Unsubscribe ( this ) ;
source . Unsubscribe ( this ) ;
}
}
}
}
_ mask = 0 ;
}
}
}
}
}
}