Browse Source

Moved template into theme.

pull/4/head
grokys 12 years ago
parent
commit
60c8302033
  1. 3
      Perspex.Windows/Window.cs
  2. 25
      Perspex/ControlTemplate.cs
  3. 13
      Perspex/Controls/Button.cs
  4. 15
      Perspex/Controls/TemplatedControl.cs
  5. 1
      Perspex/Perspex.csproj
  6. 14
      Perspex/Themes/Default/ButtonStyle.cs

3
Perspex.Windows/Window.cs

@ -39,6 +39,7 @@ namespace Perspex.Windows
Size clientSize = this.ClientSize;
this.LayoutManager = new LayoutManager();
this.renderer = new Renderer(this.Handle, (int)clientSize.Width, (int)clientSize.Height);
this.Template = ControlTemplate.Create<Window>(this.DefaultTemplate);
this.LayoutManager.LayoutNeeded.Subscribe(x =>
{
@ -79,7 +80,7 @@ namespace Perspex.Windows
UnmanagedMethods.ShowWindow(this.Handle, 4);
}
protected override Visual DefaultTemplate()
private Visual DefaultTemplate(Window c)
{
Border border = new Border();
border.Background = new Perspex.Media.SolidColorBrush(0xffffffff);

25
Perspex/ControlTemplate.cs

@ -0,0 +1,25 @@
namespace Perspex
{
using System;
using Perspex.Controls;
public class ControlTemplate
{
public ControlTemplate(Func<TemplatedControl, Visual> build)
{
this.Build = build;
}
public Func<TemplatedControl, Visual> Build
{
get;
private set;
}
public static ControlTemplate Create<TControl>(Func<TControl, Visual> build)
where TControl : TemplatedControl
{
return new ControlTemplate(c => build((TControl)c));
}
}
}

13
Perspex/Controls/Button.cs

@ -22,18 +22,5 @@ namespace Perspex.Controls
this.Classes.Remove(":pressed");
});
}
protected override Visual DefaultTemplate()
{
Border border = new Border();
border.SetValue(Border.BackgroundProperty, this.GetObservable(Button.BackgroundProperty));
border.SetValue(Border.BorderBrushProperty, this.GetObservable(Button.BorderBrushProperty));
border.SetValue(Border.BorderThicknessProperty, this.GetObservable(Button.BorderThicknessProperty));
border.Padding = new Thickness(3);
ContentPresenter contentPresenter = new ContentPresenter();
contentPresenter.SetValue(ContentPresenter.ContentProperty, this.GetObservable(Button.ContentProperty));
border.Content = contentPresenter;
return border;
}
}
}

15
Perspex/Controls/TemplatedControl.cs

@ -13,17 +13,12 @@ namespace Perspex.Controls
public abstract class TemplatedControl : Control
{
public static readonly PerspexProperty<Func<TemplatedControl, Visual>> TemplateProperty =
PerspexProperty.Register<TemplatedControl, Func<TemplatedControl, Visual>>("Template");
public static readonly PerspexProperty<ControlTemplate> TemplateProperty =
PerspexProperty.Register<TemplatedControl, ControlTemplate>("Template");
private Visual visualChild;
public TemplatedControl()
{
this.Template = owner => this.DefaultTemplate();
}
public Func<TemplatedControl, Visual> Template
public ControlTemplate Template
{
get { return this.GetValue(TemplateProperty); }
set { this.SetValue(TemplateProperty, value); }
@ -37,7 +32,7 @@ namespace Perspex.Controls
if (this.visualChild == null && template != null)
{
this.visualChild = template(this);
this.visualChild = template.Build(this);
this.visualChild.VisualParent = this;
}
@ -48,7 +43,5 @@ namespace Perspex.Controls
public sealed override void Render(IDrawingContext context)
{
}
protected abstract Visual DefaultTemplate();
}
}

1
Perspex/Perspex.csproj

@ -76,6 +76,7 @@
<Compile Include="Controls\ContentControl.cs" />
<Compile Include="Controls\Control.cs" />
<Compile Include="Controls\TextBlock.cs" />
<Compile Include="ControlTemplate.cs" />
<Compile Include="Input\MouseEventArgs.cs" />
<Compile Include="Interactive.cs" />
<Compile Include="IStyle.cs" />

14
Perspex/Themes/Default/ButtonStyle.cs

@ -22,6 +22,7 @@ namespace Perspex.Themes.Default
new Setter(Button.BorderBrushProperty, new SolidColorBrush(0xff707070)),
new Setter(Button.BorderThicknessProperty, 2.0),
new Setter(Button.ForegroundProperty, new SolidColorBrush(0xff000000)),
new Setter(Button.TemplateProperty, ControlTemplate.Create<Button>(this.Template)),
},
},
new Style(x => x.Select<Button>().Class(":mouseover"))
@ -42,5 +43,18 @@ namespace Perspex.Themes.Default
},
});
}
private Visual Template(Button control)
{
Border border = new Border();
border.SetValue(Border.BackgroundProperty, control.GetObservable(Button.BackgroundProperty));
border.SetValue(Border.BorderBrushProperty, control.GetObservable(Button.BorderBrushProperty));
border.SetValue(Border.BorderThicknessProperty, control.GetObservable(Button.BorderThicknessProperty));
border.Padding = new Thickness(3);
ContentPresenter contentPresenter = new ContentPresenter();
contentPresenter.SetValue(ContentPresenter.ContentProperty, control.GetObservable(Button.ContentProperty));
border.Content = contentPresenter;
return border;
}
}
}

Loading…
Cancel
Save