A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

59 lines
1.5 KiB

using System.Collections.Generic;
namespace Avalonia.Styling.Activators
{
/// <summary>
/// An aggregate <see cref="IStyleActivator"/> which is active when any of its inputs are
/// active.
/// </summary>
internal class OrActivator : StyleActivatorBase, IStyleActivatorSink
{
private List<IStyleActivator>? _sources;
public int Count => _sources?.Count ?? 0;
public void Add(IStyleActivator activator)
{
_sources ??= new List<IStyleActivator>();
_sources.Add(activator);
}
void IStyleActivatorSink.OnNext(bool value) => ReevaluateIsActive();
protected override bool EvaluateIsActive()
{
if (_sources is null || _sources.Count == 0)
return true;
foreach (var source in _sources)
{
if (source.GetIsActive())
return true;
}
return false;
}
protected override void Initialize()
{
if (_sources is object)
{
foreach (var source in _sources)
{
source.Subscribe(this);
}
}
}
protected override void Deinitialize()
{
if (_sources is object)
{
foreach (var source in _sources)
{
source.Unsubscribe(this);
}
}
}
}
}