Browse Source

Slightly change the selector syntax.

pull/4/head
Steven Kirk 12 years ago
parent
commit
ab5480f59c
  1. 10
      Perspex.UnitTests/StyleTests.cs
  2. 3
      Perspex/PerspexObject.cs
  3. 4
      Perspex/Styling/Style.cs
  4. 14
      Perspex/Themes/Default/ButtonStyle.cs
  5. 1
      TestApplication/Program.cs

10
Perspex.UnitTests/StyleTests.cs

@ -18,7 +18,7 @@ namespace Perspex.UnitTests
[TestMethod] [TestMethod]
public void Style_With_Only_Type_Selector_Should_Update_Value() public void Style_With_Only_Type_Selector_Should_Update_Value()
{ {
Style style = new Style(new Selector().OfType<Class1>()) Style style = new Style(x => x.OfType<Class1>())
{ {
Setters = new[] Setters = new[]
{ {
@ -36,7 +36,7 @@ namespace Perspex.UnitTests
[TestMethod] [TestMethod]
public void Style_With_Class_Selector_Should_Update_And_Restore_Value() public void Style_With_Class_Selector_Should_Update_And_Restore_Value()
{ {
Style style = new Style(new Selector().OfType<Class1>().Class("foo")) Style style = new Style(x => x.OfType<Class1>().Class("foo"))
{ {
Setters = new[] Setters = new[]
{ {
@ -57,7 +57,7 @@ namespace Perspex.UnitTests
[TestMethod] [TestMethod]
public void LocalValue_Should_Override_Style() public void LocalValue_Should_Override_Style()
{ {
Style style = new Style(new Selector().OfType<Class1>()) Style style = new Style(x => x.OfType<Class1>())
{ {
Setters = new[] Setters = new[]
{ {
@ -79,7 +79,7 @@ namespace Perspex.UnitTests
{ {
Styles styles = new Styles Styles styles = new Styles
{ {
new Style(new Selector().OfType<Class1>().Class("foo")) new Style(x => x.OfType<Class1>().Class("foo"))
{ {
Setters = new[] Setters = new[]
{ {
@ -87,7 +87,7 @@ namespace Perspex.UnitTests
}, },
}, },
new Style(new Selector().OfType<Class1>().Class("foo")) new Style(x => x.OfType<Class1>().Class("foo"))
{ {
Setters = new[] Setters = new[]
{ {

3
Perspex/PerspexObject.cs

@ -9,9 +9,6 @@ namespace Perspex
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Expressions;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq; using System.Reactive.Linq;
using System.Reflection; using System.Reflection;
using Splat; using Splat;

4
Perspex/Styling/Style.cs

@ -20,10 +20,10 @@ namespace Perspex.Styling
this.Setters = new List<Setter>(); this.Setters = new List<Setter>();
} }
public Style(Selector selector) public Style(Func<Selector, Selector> selector)
: this() : this()
{ {
this.Selector = selector; this.Selector = selector(new Selector());
} }
public Selector Selector public Selector Selector

14
Perspex/Themes/Default/ButtonStyle.cs

@ -15,14 +15,14 @@ namespace Perspex.Themes.Default
{ {
this.AddRange(new[] this.AddRange(new[]
{ {
new Style(new Selector().OfType<Button>()) new Style(x => x.OfType<Button>())
{ {
Setters = new[] Setters = new[]
{ {
new Setter(Button.TemplateProperty, ControlTemplate.Create<Button>(this.Template)), new Setter(Button.TemplateProperty, ControlTemplate.Create<Button>(this.Template)),
}, },
}, },
new Style(new Selector().OfType<Button>().Template().Id("border")) new Style(x => x.OfType<Button>().Template().Id("border"))
{ {
Setters = new[] Setters = new[]
{ {
@ -32,7 +32,7 @@ namespace Perspex.Themes.Default
new Setter(Button.ForegroundProperty, new SolidColorBrush(0xff000000)), new Setter(Button.ForegroundProperty, new SolidColorBrush(0xff000000)),
}, },
}, },
new Style(new Selector().OfType<Button>().Class(":mouseover").Template().Id("border")) new Style(x => x.OfType<Button>().Class(":mouseover").Template().Id("border"))
{ {
Setters = new[] Setters = new[]
{ {
@ -40,7 +40,7 @@ namespace Perspex.Themes.Default
new Setter (Button.BorderBrushProperty, new SolidColorBrush(0xff3c7fb1)), new Setter (Button.BorderBrushProperty, new SolidColorBrush(0xff3c7fb1)),
}, },
}, },
new Style(new Selector().OfType<Button>().Class(":pressed").Template().Id("border")) new Style(x => x.OfType<Button>().Class(":pressed").Template().Id("border"))
{ {
Setters = new[] Setters = new[]
{ {
@ -56,11 +56,17 @@ namespace Perspex.Themes.Default
Border border = new Border(); Border border = new Border();
border.Id = "border"; border.Id = "border";
border.Padding = new Thickness(3); border.Padding = new Thickness(3);
border.Bind(
Border.BackgroundProperty,
control.GetObservable(Button.BackgroundProperty),
BindingPriority.Template);
ContentPresenter contentPresenter = new ContentPresenter(); ContentPresenter contentPresenter = new ContentPresenter();
contentPresenter.Bind( contentPresenter.Bind(
ContentPresenter.ContentProperty, ContentPresenter.ContentProperty,
control.GetObservable(Button.ContentProperty), control.GetObservable(Button.ContentProperty),
BindingPriority.Template); BindingPriority.Template);
border.Content = contentPresenter; border.Content = contentPresenter;
return border; return border;
} }

1
TestApplication/Program.cs

@ -52,6 +52,7 @@ namespace TestApplication
{ {
Content = new Button Content = new Button
{ {
Background = new SolidColorBrush(0xff0000ff),
Content = "Hello World", Content = "Hello World",
HorizontalAlignment = HorizontalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center, VerticalAlignment = VerticalAlignment.Center,

Loading…
Cancel
Save