// -----------------------------------------------------------------------
//
// Copyright 2014 Tricycle. All rights reserved.
//
// -----------------------------------------------------------------------
namespace Perspex
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using Perspex.Controls;
public class Style
{
private bool applied;
public Style()
{
this.Setters = new List();
}
public Func Selector
{
get;
set;
}
public IEnumerable Setters
{
get;
set;
}
public void Attach(Control control)
{
Match match = this.Selector(control);
if (match != null)
{
List> o = new List>();
while (match != null)
{
if (match.Observable != null)
{
o.Add(match.Observable);
}
match = match.Previous;
}
List subjects = new List();
foreach (Setter setter in this.Setters)
{
SetterSubject subject = setter.CreateSubject(control);
subjects.Add(subject);
control.SetValue(setter.Property, subject);
}
Observable.CombineLatest(o).Subscribe(x =>
{
bool on = x.All(y => y);
foreach (SetterSubject subject in subjects)
{
subject.Push(on);
}
});
}
}
}
}