Browse Source

Added Application class.

And some more work on styling.
pull/4/head
grokys 12 years ago
parent
commit
27d5d35316
  1. 42
      Perspex/Application.cs
  2. 72
      Perspex/Controls/Control.cs
  3. 12
      Perspex/Controls/TextBlock.cs
  4. 1
      Perspex/Perspex.csproj
  5. 10
      Perspex/Setter.cs
  6. 8
      Perspex/Style.cs
  7. 19
      Perspex/Styles.cs
  8. 31
      TestApplication/Program.cs

42
Perspex/Application.cs

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Perspex
{
public class Application
{
private Styles styles;
public Application()
{
Current = this;
}
public static Application Current
{
get;
private set;
}
public Styles Styles
{
get
{
if (this.styles == null)
{
this.styles = new Styles();
}
return this.styles;
}
set
{
this.styles = value;
}
}
}
}

72
Perspex/Controls/Control.cs

@ -36,7 +36,7 @@ namespace Perspex.Controls
new ReadOnlyPerspexProperty<Control>(ParentPropertyRW);
public static readonly PerspexProperty<Brush> BackgroundProperty =
PerspexProperty.Register<Control, Brush>("Background");
PerspexProperty.Register<Control, Brush>("Background", inherits: true);
public static readonly PerspexProperty<Brush> BorderBrushProperty =
PerspexProperty.Register<Control, Brush>("BorderBrush");
@ -44,18 +44,21 @@ namespace Perspex.Controls
public static readonly PerspexProperty<double> BorderThicknessProperty =
PerspexProperty.Register<Control, double>("BorderThickness");
public static readonly PerspexProperty<Brush> ForegroundProperty =
PerspexProperty.Register<Control, Brush>("Foreground", new SolidColorBrush(0xff000000), true);
public static readonly PerspexProperty<bool> IsMouseOverProperty =
PerspexProperty.Register<Visual, bool>("IsMouseOver");
public static readonly PerspexProperty<HorizontalAlignment> HorizontalAlignmentProperty =
PerspexProperty.Register<Control, HorizontalAlignment>("HorizontalAlignment");
public static readonly PerspexProperty<VerticalAlignment> VerticalAlignmentProperty =
PerspexProperty.Register<Control, VerticalAlignment>("VerticalAlignment");
public static readonly PerspexProperty<Thickness> MarginProperty =
PerspexProperty.Register<Control, Thickness>("Margin");
public static readonly PerspexProperty<VerticalAlignment> VerticalAlignmentProperty =
PerspexProperty.Register<Control, VerticalAlignment>("VerticalAlignment");
internal static readonly PerspexProperty<Control> ParentPropertyRW =
PerspexProperty.Register<Control, Control>("Parent");
@ -106,22 +109,10 @@ namespace Perspex.Controls
private set;
}
public Styles Styles
public Brush Foreground
{
get
{
if (this.styles == null)
{
this.styles = new Styles();
}
return this.styles;
}
set
{
this.styles = value;
}
get { return this.GetValue(ForegroundProperty); }
set { this.SetValue(ForegroundProperty, value); }
}
public Size? DesiredSize
@ -142,12 +133,6 @@ namespace Perspex.Controls
set { this.SetValue(HorizontalAlignmentProperty, value); }
}
public VerticalAlignment VerticalAlignment
{
get { return this.GetValue(VerticalAlignmentProperty); }
set { this.SetValue(VerticalAlignmentProperty, value); }
}
public Thickness Margin
{
get { return this.GetValue(MarginProperty); }
@ -160,6 +145,30 @@ namespace Perspex.Controls
internal set { this.SetValue(ParentPropertyRW, value); }
}
public Styles Styles
{
get
{
if (this.styles == null)
{
this.styles = new Styles();
}
return this.styles;
}
set
{
this.styles = value;
}
}
public VerticalAlignment VerticalAlignment
{
get { return this.GetValue(VerticalAlignmentProperty); }
set { this.SetValue(VerticalAlignmentProperty, value); }
}
public ILayoutRoot GetLayoutRoot()
{
Control c = this;
@ -214,18 +223,15 @@ namespace Perspex.Controls
private void AttachStyles(Control control)
{
Contract.Requires<ArgumentNullException>(control != null);
Control parent = control.Parent;
if (parent != null)
if (control != null)
{
Control parent = control.Parent;
this.AttachStyles(parent);
control.Styles.Attach(this);
}
foreach (Style style in control.Styles)
else
{
style.Attach(this);
Application.Current.Styles.Attach(this);
}
}

12
Perspex/Controls/TextBlock.cs

@ -15,12 +15,6 @@ namespace Perspex.Controls
"FontSize",
inherits: true);
public static readonly PerspexProperty<Brush> ForegroundProperty =
PerspexProperty.Register<TextBlock, Brush>(
"Foreground",
defaultValue: new SolidColorBrush(0xff000000),
inherits: true);
public static readonly PerspexProperty<string> TextProperty =
PerspexProperty.Register<Border, string>("Text");
@ -30,12 +24,6 @@ namespace Perspex.Controls
set { this.SetValue(FontSizeProperty, value); }
}
public Brush Foreground
{
get { return this.GetValue(ForegroundProperty); }
set { this.SetValue(ForegroundProperty, value); }
}
public string Text
{
get { return this.GetValue(TextProperty); }

1
Perspex/Perspex.csproj

@ -68,6 +68,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="Application.cs" />
<Compile Include="Controls\Border.cs" />
<Compile Include="Controls\Button.cs" />
<Compile Include="Controls\ContentPresenter.cs" />

10
Perspex/Setter.cs

@ -16,6 +16,16 @@ namespace Perspex
{
private object oldValue;
public Setter()
{
}
public Setter(PerspexProperty property, object value)
{
this.Property = property;
this.Value = value;
}
public PerspexProperty Property
{
get;

8
Perspex/Style.cs

@ -15,13 +15,17 @@ namespace Perspex
public class Style
{
private bool applied;
public Style()
{
this.Setters = new List<Setter>();
}
public Style(Func<Control, Match> selector)
: this()
{
this.Selector = selector;
}
public Func<Control, Match> Selector
{
get;

19
Perspex/Styles.cs

@ -1,12 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// -----------------------------------------------------------------------
// <copyright file="Styles.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex
{
using Perspex.Controls;
public class Styles : PerspexList<Style>
{
public void Attach(Control control)
{
foreach (Style style in this)
{
style.Attach(control);
}
}
}
}

31
TestApplication/Program.cs

@ -20,29 +20,38 @@ namespace TestApplication
{
ServiceLocator.Register<ITextService>(() => new TextService(new SharpDX.DirectWrite.Factory()));
Window window = new Window
Application application = new Application
{
Styles = new Styles
Styles = new Styles
{
new Style
new Style(x => x.Select<Button>())
{
Setters = new[]
{
new Setter(Button.BackgroundProperty, new SolidColorBrush(0xffdddddd)),
new Setter(Button.BorderBrushProperty, new SolidColorBrush(0xff707070)),
new Setter(Button.BorderThicknessProperty, 1),
new Setter(Button.ForegroundProperty, new SolidColorBrush(0xff000000)),
},
},
new Style(x => x.Select<Button>().Class(":mouseover"))
{
Selector = x => x.Select<Button>().Class(":mouseover"),
Setters = new[]
{
new Setter
{
Property = Button.BackgroundProperty,
Value = new SolidColorBrush(0xffff8080),
}
new Setter (Button.BackgroundProperty, new SolidColorBrush(0xffbee6fd)),
new Setter (Button.BorderBrushProperty, new SolidColorBrush(0xff3c7fb1)),
},
}
},
}
};
Window window = new Window
{
Content = new Button
{
Content = "Hello World",
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Background = new SolidColorBrush(0xff808080),
BorderThickness = 2,
BorderBrush = new SolidColorBrush(0xff000000),
},

Loading…
Cancel
Save