Browse Source

Styley culture.

pull/4/head
grokys 12 years ago
parent
commit
d324be3c11
  1. 3
      Perspex.UnitTests/Perspex.UnitTests.csproj
  2. 49
      Perspex.UnitTests/StyleTests.cs
  3. 1
      Perspex.UnitTests/packages.config
  4. 3
      Perspex.Windows/Perspex.Windows.csproj
  5. 1
      Perspex.Windows/packages.config
  6. 13
      Perspex/IBindingDescription.cs
  7. 13
      Perspex/Match.cs
  8. 4
      Perspex/Perspex.csproj
  9. 40
      Perspex/PerspexObject.cs
  10. 23
      Perspex/Selectors.cs
  11. 15
      Perspex/Setter.cs
  12. 23
      Perspex/Style.cs
  13. 1
      Perspex/packages.config
  14. 22
      TestApplication/Program.cs
  15. 3
      TestApplication/TestApplication.csproj
  16. 1
      TestApplication/packages.config
  17. BIN
      packages/Splat.1.1.1/Splat.1.1.1.nupkg
  18. 20
      packages/Splat.1.1.1/Splat.1.1.1.nuspec
  19. BIN
      packages/Splat.1.1.1/lib/MonoMac/Splat.dll
  20. BIN
      packages/Splat.1.1.1/lib/MonoMac/Splat.dll.mdb
  21. BIN
      packages/Splat.1.1.1/lib/Net45/Splat.dll
  22. BIN
      packages/Splat.1.1.1/lib/NetCore45/Splat.dll
  23. BIN
      packages/Splat.1.1.1/lib/NetCore45/Splat.pri
  24. BIN
      packages/Splat.1.1.1/lib/Portable-Net45+WinRT45+WP8/Splat.dll
  25. BIN
      packages/Splat.1.1.1/lib/Portable-Net45+WinRT45+WP8/Splat.dll.mdb
  26. BIN
      packages/Splat.1.1.1/lib/monoandroid/Splat.dll
  27. BIN
      packages/Splat.1.1.1/lib/monoandroid/Splat.dll.mdb
  28. BIN
      packages/Splat.1.1.1/lib/monotouch/Splat.dll
  29. BIN
      packages/Splat.1.1.1/lib/monotouch/Splat.dll.mdb
  30. BIN
      packages/Splat.1.1.1/lib/wp8/Splat.dll

3
Perspex.UnitTests/Perspex.UnitTests.csproj

@ -35,6 +35,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Splat">
<HintPath>..\packages\Splat.1.1.1\lib\Net45\Splat.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Reactive.Core, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>

49
Perspex.UnitTests/StyleTests.cs

@ -15,18 +15,33 @@ namespace Perspex.UnitTests
public class StyleTests
{
[TestMethod]
public void Style_Should_Update_And_Restore_Value()
public void Style_With_Only_Type_Selector_Should_Update_Value()
{
Style style = new Style
Style style = new Style(x => x.Select<TextBlock>())
{
Selector = x => x.Select<TextBlock>().Class("foo"),
Setters = new[]
{
new Setter
{
Property = TextBlock.TextProperty,
Value = "Foo",
}
new Setter(TextBlock.TextProperty, "Foo"),
},
};
TextBlock textBlock = new TextBlock
{
Text = "Original",
};
style.Attach(textBlock);
Assert.AreEqual("Foo", textBlock.Text);
}
[TestMethod]
public void Style_With_Class_Selector_Should_Update_And_Restore_Value()
{
Style style = new Style(x => x.Select<TextBlock>().Class("foo"))
{
Setters = new[]
{
new Setter(TextBlock.TextProperty, "Foo"),
},
};
@ -46,29 +61,19 @@ namespace Perspex.UnitTests
[TestMethod]
public void Later_Styles_Should_Override_Earlier()
{
Style style1 = new Style
Style style1 = new Style(x => x.Select<TextBlock>().Class("foo"))
{
Selector = x => x.Select<TextBlock>().Class("foo"),
Setters = new[]
{
new Setter
{
Property = TextBlock.TextProperty,
Value = "Foo",
}
new Setter(TextBlock.TextProperty, "Foo"),
},
};
Style style2 = new Style
Style style2 = new Style(x => x.Select<TextBlock>().Class("foo"))
{
Selector = x => x.Select<TextBlock>().Class("foo"),
Setters = new[]
{
new Setter
{
Property = TextBlock.TextProperty,
Value = "Bar",
}
new Setter(TextBlock.TextProperty, "Bar"),
},
};

1
Perspex.UnitTests/packages.config

@ -3,4 +3,5 @@
<package id="Rx-Core" version="2.1.30214.0" targetFramework="net45" />
<package id="Rx-Interfaces" version="2.1.30214.0" targetFramework="net45" />
<package id="Rx-Linq" version="2.1.30214.0" targetFramework="net45" />
<package id="Splat" version="1.1.1" targetFramework="net45" />
</packages>

3
Perspex.Windows/Perspex.Windows.csproj

@ -39,6 +39,9 @@
<Reference Include="SharpDX.DXGI">
<HintPath>..\packages\SharpDX.DXGI.2.5.0\lib\net40\SharpDX.DXGI.dll</HintPath>
</Reference>
<Reference Include="Splat">
<HintPath>..\packages\Splat.1.1.1\lib\Net45\Splat.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />

1
Perspex.Windows/packages.config

@ -8,5 +8,6 @@
<package id="SharpDX" version="2.5.0" targetFramework="net45" />
<package id="SharpDX.Direct2D1" version="2.5.0" targetFramework="net45" />
<package id="SharpDX.DXGI" version="2.5.0" targetFramework="net45" />
<package id="Splat" version="1.1.1" targetFramework="net45" />
<package id="StyleCop.MSBuild" version="4.7.46.0" targetFramework="net45" />
</packages>

13
Perspex/IBindingDescription.cs

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Perspex
{
public interface IBindingDescription
{
string Description { get; }
}
}

13
Perspex/Match.cs

@ -28,5 +28,18 @@ namespace Perspex
get;
set;
}
public string Token
{
get;
set;
}
public override string ToString()
{
string result = (this.Previous != null) ? this.Previous.ToString() : string.Empty;
result += this.Token;
return result;
}
}
}

4
Perspex/Perspex.csproj

@ -76,6 +76,7 @@
<Compile Include="Controls\ContentControl.cs" />
<Compile Include="Controls\Control.cs" />
<Compile Include="Controls\TextBlock.cs" />
<Compile Include="IBindingDescription.cs" />
<Compile Include="Layout\ILayoutable.cs" />
<Compile Include="Layout\ILayoutManager.cs" />
<Compile Include="Layout\ILayoutRoot.cs" />
@ -108,6 +109,9 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Splat">
<HintPath>..\packages\Splat.1.1.1\lib\Portable-Net45+WinRT45+WP8\Splat.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.Core">
<HintPath>..\packages\Rx-Core.2.1.30214.0\lib\Portable-Net45+WinRT45+WP8\System.Reactive.Core.dll</HintPath>
</Reference>

40
Perspex/PerspexObject.cs

@ -14,6 +14,7 @@ namespace Perspex
using System.Reactive;
using System.Reactive.Linq;
using System.Reflection;
using Splat;
/// <summary>
/// An object with <see cref="PerspexProperty"/> support.
@ -21,7 +22,7 @@ namespace Perspex
/// <remarks>
/// This class is analogous to DependencyObject in WPF.
/// </remarks>
public class PerspexObject
public class PerspexObject : IEnableLogger
{
/// <summary>
/// The registered properties by type.
@ -168,6 +169,12 @@ namespace Perspex
{
binding.Dispose.Dispose();
this.bindings.Remove(property);
this.Log().Debug(string.Format(
"Cleared binding on {0}.{1} (#{2:x8})",
this.GetType().Name,
property.Name,
this.GetHashCode()));
}
}
@ -177,6 +184,7 @@ namespace Perspex
/// <param name="property">The property.</param>
public void ClearValue(PerspexProperty property)
{
// TODO: Implement this by using SetValue(UnsetValue).
Contract.Requires<NullReferenceException>(property != null);
this.ClearBinding(property);
this.values.Remove(property);
@ -194,6 +202,13 @@ namespace Perspex
if (this.bindings.TryGetValue(property, out binding))
{
this.bindings.Remove(property);
this.Log().Debug(string.Format(
"Extracted binding on {0}.{1} (#{2:x8})",
this.GetType().Name,
property.Name,
this.GetHashCode()));
return (IObservable<object>)binding.Observable;
}
else
@ -214,6 +229,13 @@ namespace Perspex
if (this.bindings.TryGetValue(property, out binding))
{
this.bindings.Remove(property);
this.Log().Debug(string.Format(
"Extracted binding on {0}.{1} (#{2:x8})",
this.GetType().Name,
property.Name,
this.GetHashCode()));
return (IObservable<T>)binding.Observable;
}
else
@ -390,6 +412,8 @@ namespace Perspex
else
{
IObservable<object> observable = value as IObservable<object>;
IBindingDescription bindingDescription = value as IBindingDescription;
string description = (bindingDescription != null) ? bindingDescription.Description : value.GetType().Name;
if (observable == null)
{
@ -409,6 +433,13 @@ namespace Perspex
this.SetValueImpl(property, x);
}),
});
this.Log().Debug(string.Format(
"Bound {0}.{1} (#{2:x8}) to {3}",
this.GetType().Name,
property.Name,
this.GetHashCode(),
description));
}
}
@ -500,6 +531,13 @@ namespace Perspex
{
this.values[property] = value;
this.RaisePropertyChanged(property, oldValue, value);
this.Log().Debug(string.Format(
"Set value of {0}.{1} (#{2:x8}) to '{3}'",
this.GetType().Name,
property.Name,
this.GetHashCode(),
value));
}
}

23
Perspex/Selectors.cs

@ -27,6 +27,7 @@ namespace Perspex
return new Match
{
Control = control,
Token = typeof(T).Name,
};
}
else
@ -50,27 +51,7 @@ namespace Perspex
Control = selector.Control,
Observable = match,
Previous = selector,
};
}
else
{
return null;
}
}
public static Match PropertyEquals<T>(this Match selector, PerspexProperty<T> property, T value)
{
Contract.Requires<ArgumentNullException>(property != null);
if (selector != null)
{
IObservable<bool> match = selector.Control.GetObservable(property).Select(x => object.Equals(x, value));
return new Match
{
Control = selector.Control,
Observable = match,
Previous = selector,
Token = (name[0] == ':') ? name : '.' + name,
};
}
else

15
Perspex/Setter.cs

@ -38,13 +38,13 @@ namespace Perspex
set;
}
internal Subject CreateSubject(Control control)
internal Subject CreateSubject(Control control, string description)
{
object oldValue = control.GetValue(this.Property);
return new Subject(control, this.Value, oldValue);
return new Subject(control, this.Value, oldValue, description);
}
internal class Subject : IObservable<object>
internal class Subject : IObservable<object>, IBindingDescription
{
private Control control;
@ -54,12 +54,19 @@ namespace Perspex
private List<IObserver<object>> observers;
public Subject(Control control, object onValue, object offValue)
public Subject(Control control, object onValue, object offValue, string description)
{
this.control = control;
this.onValue = onValue;
this.offValue = offValue;
this.observers = new List<IObserver<object>>();
this.Description = description;
}
public string Description
{
get;
private set;
}
public IDisposable Subscribe(IObserver<object> observer)

23
Perspex/Style.cs

@ -44,6 +44,7 @@ namespace Perspex
if (match != null)
{
string description = "Style " + match.ToString();
List<IObservable<bool>> o = new List<IObservable<bool>>();
while (match != null)
@ -60,20 +61,30 @@ namespace Perspex
foreach (Setter setter in this.Setters)
{
Setter.Subject subject = setter.CreateSubject(control);
Setter.Subject subject = setter.CreateSubject(control, description);
subjects.Add(subject);
control.SetValue(setter.Property, subject);
}
Observable.CombineLatest(o).Subscribe(x =>
if (o.Count == 0)
{
bool on = x.All(y => y);
foreach (Setter.Subject subject in subjects)
{
subject.Push(on);
subject.Push(true);
}
});
}
else
{
Observable.CombineLatest(o).Subscribe(x =>
{
bool on = x.All(y => y);
foreach (Setter.Subject subject in subjects)
{
subject.Push(on);
}
});
}
}
}
}

1
Perspex/packages.config

@ -5,5 +5,6 @@
<package id="Rx-Linq" version="2.1.30214.0" targetFramework="portable-net45+wp80+win" />
<package id="Rx-Main" version="2.1.30214.0" targetFramework="portable-net45+wp80+win" />
<package id="Rx-PlatformServices" version="2.1.30214.0" targetFramework="portable-net45+wp80+win" />
<package id="Splat" version="1.1.1" targetFramework="portable-net45+win" />
<package id="StyleCop.MSBuild" version="4.7.46.0" targetFramework="portable-net45+wp80+win" />
</packages>

22
TestApplication/Program.cs

@ -11,14 +11,32 @@ using Perspex.Media;
using Perspex.Windows;
using Perspex.Windows.Media;
using Perspex.Windows.Threading;
using Splat;
namespace TestApplication
{
class TestLogger : ILogger
{
public LogLevel Level
{
get;
set;
}
public void Write(string message, LogLevel logLevel)
{
if ((int)logLevel < (int)Level) return;
System.Diagnostics.Debug.WriteLine(message);
}
}
class Program
{
static void Main(string[] args)
{
ServiceLocator.Register<ITextService>(() => new TextService(new SharpDX.DirectWrite.Factory()));
Locator.CurrentMutable.Register(() => new TestLogger(), typeof(ILogger));
Application application = new Application
{
@ -30,7 +48,7 @@ namespace TestApplication
{
new Setter(Button.BackgroundProperty, new SolidColorBrush(0xffdddddd)),
new Setter(Button.BorderBrushProperty, new SolidColorBrush(0xff707070)),
new Setter(Button.BorderThicknessProperty, 1),
new Setter(Button.BorderThicknessProperty, 2.0),
new Setter(Button.ForegroundProperty, new SolidColorBrush(0xff000000)),
},
},
@ -52,8 +70,6 @@ namespace TestApplication
Content = "Hello World",
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
BorderThickness = 2,
BorderBrush = new SolidColorBrush(0xff000000),
},
};

3
TestApplication/TestApplication.csproj

@ -44,6 +44,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\SharpDX.DXGI.2.5.0\lib\net40\SharpDX.DXGI.dll</HintPath>
</Reference>
<Reference Include="Splat">
<HintPath>..\packages\Splat.1.1.1\lib\Net45\Splat.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />

1
TestApplication/packages.config

@ -8,4 +8,5 @@
<package id="SharpDX" version="2.5.0" targetFramework="net45" />
<package id="SharpDX.Direct2D1" version="2.5.0" targetFramework="net45" />
<package id="SharpDX.DXGI" version="2.5.0" targetFramework="net45" />
<package id="Splat" version="1.1.1" targetFramework="net45" />
</packages>

BIN
packages/Splat.1.1.1/Splat.1.1.1.nupkg

Binary file not shown.

20
packages/Splat.1.1.1/Splat.1.1.1.nuspec

@ -0,0 +1,20 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Splat</id>
<version>1.1.1</version>
<title>Splat</title>
<authors>Paul Betts</authors>
<owners>Paul Betts</owners>
<licenseUrl>https://github.com/xpaulbettsx/splat/blob/master/COPYING</licenseUrl>
<projectUrl>https://github.com/xpaulbettsx/splat</projectUrl>
<iconUrl>http://f.cl.ly/items/1307401C3x2g3F2p2Z36/Logo.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A library to make things cross-platform that should be</description>
<summary>A library to make things cross-platform that should be</summary>
<releaseNotes />
<copyright />
<language />
<tags>portable</tags>
</metadata>
</package>

BIN
packages/Splat.1.1.1/lib/MonoMac/Splat.dll

Binary file not shown.

BIN
packages/Splat.1.1.1/lib/MonoMac/Splat.dll.mdb

Binary file not shown.

BIN
packages/Splat.1.1.1/lib/Net45/Splat.dll

Binary file not shown.

BIN
packages/Splat.1.1.1/lib/NetCore45/Splat.dll

Binary file not shown.

BIN
packages/Splat.1.1.1/lib/NetCore45/Splat.pri

Binary file not shown.

BIN
packages/Splat.1.1.1/lib/Portable-Net45+WinRT45+WP8/Splat.dll

Binary file not shown.

BIN
packages/Splat.1.1.1/lib/Portable-Net45+WinRT45+WP8/Splat.dll.mdb

Binary file not shown.

BIN
packages/Splat.1.1.1/lib/monoandroid/Splat.dll

Binary file not shown.

BIN
packages/Splat.1.1.1/lib/monoandroid/Splat.dll.mdb

Binary file not shown.

BIN
packages/Splat.1.1.1/lib/monotouch/Splat.dll

Binary file not shown.

BIN
packages/Splat.1.1.1/lib/monotouch/Splat.dll.mdb

Binary file not shown.

BIN
packages/Splat.1.1.1/lib/wp8/Splat.dll

Binary file not shown.
Loading…
Cancel
Save