From 3cdda17ef64bc6f67370d79359c65ac18fa537f7 Mon Sep 17 00:00:00 2001 From: grokys Date: Wed, 11 Dec 2013 23:51:24 +0100 Subject: [PATCH] Added FontSize/VisualParent. --- Perspex.Windows/Window.cs | 8 ++++++++ Perspex/Controls/ContentPresenter.cs | 5 +++++ Perspex/Controls/Decorator.cs | 12 ++++++++++++ Perspex/Controls/TemplatedControl.cs | 1 + Perspex/Controls/TextBlock.cs | 13 ++++++++++++- Perspex/Visual.cs | 19 +++++++++++++++++++ 6 files changed, 57 insertions(+), 1 deletion(-) diff --git a/Perspex.Windows/Window.cs b/Perspex.Windows/Window.cs index cc9f27160c..52001ec063 100644 --- a/Perspex.Windows/Window.cs +++ b/Perspex.Windows/Window.cs @@ -10,12 +10,20 @@ public class Window : ContentControl, ILayoutRoot { + public static PerspexProperty FontSizeProperty = + TextBlock.FontSizeProperty.AddOwner(); + private UnmanagedMethods.WndProc wndProcDelegate; private string className; private Renderer renderer; + static Window() + { + FontSizeProperty.OverrideDefaultValue(typeof(Window), 18.0); + } + public Window() { this.CreateWindow(); diff --git a/Perspex/Controls/ContentPresenter.cs b/Perspex/Controls/ContentPresenter.cs index 72671bfb72..95b38e7222 100644 --- a/Perspex/Controls/ContentPresenter.cs +++ b/Perspex/Controls/ContentPresenter.cs @@ -50,6 +50,11 @@ Text = content.ToString(), }; } + + if (this.visualChild != null) + { + this.visualChild.VisualParent = this; + } } return Enumerable.Repeat(this.visualChild, this.visualChild != null ? 1 : 0); diff --git a/Perspex/Controls/Decorator.cs b/Perspex/Controls/Decorator.cs index 9f1a8d64b3..4d28c8b5e0 100644 --- a/Perspex/Controls/Decorator.cs +++ b/Perspex/Controls/Decorator.cs @@ -9,6 +9,18 @@ public static readonly PerspexProperty ContentProperty = PerspexProperty.Register("Content"); + public Decorator() + { + // TODO: Unset old content's visual parent. + this.GetObservable(ContentProperty).Subscribe(x => + { + if (x != null) + { + x.VisualParent = this; + } + }); + } + public Control Content { get { return this.GetValue(ContentProperty); } diff --git a/Perspex/Controls/TemplatedControl.cs b/Perspex/Controls/TemplatedControl.cs index 884e658b69..1d96b47c43 100644 --- a/Perspex/Controls/TemplatedControl.cs +++ b/Perspex/Controls/TemplatedControl.cs @@ -32,6 +32,7 @@ if (this.visualChild == null && template != null) { this.visualChild = template(this); + this.visualChild.VisualParent = this; } return Enumerable.Repeat(this.visualChild, this.visualChild != null ? 1 : 0); diff --git a/Perspex/Controls/TextBlock.cs b/Perspex/Controls/TextBlock.cs index d67cd5d067..9850710b0d 100644 --- a/Perspex/Controls/TextBlock.cs +++ b/Perspex/Controls/TextBlock.cs @@ -7,6 +7,11 @@ public static readonly PerspexProperty BackgroundProperty = Border.BackgroundProperty.AddOwner(); + public static readonly PerspexProperty FontSizeProperty = + PerspexProperty.Register( + "FontSize", + inherits: true); + public static readonly PerspexProperty ForegroundProperty = PerspexProperty.Register( "Foreground", @@ -22,6 +27,12 @@ set { this.SetValue(BackgroundProperty, value); } } + public double FontSize + { + get { return this.GetValue(FontSizeProperty); } + set { this.SetValue(FontSizeProperty, value); } + } + public Brush Foreground { get { return this.GetValue(ForegroundProperty); } @@ -41,7 +52,7 @@ return new FormattedText { FontFamilyName = "Segoe UI", - FontSize = 18, + FontSize = this.FontSize, Text = this.Text, }; } diff --git a/Perspex/Visual.cs b/Perspex/Visual.cs index dd5ea900e2..4b3446de73 100644 --- a/Perspex/Visual.cs +++ b/Perspex/Visual.cs @@ -14,6 +14,8 @@ private static readonly PerspexProperty BoundsPropertyW = PerspexProperty.Register("Bounds", new Rect()); + private Visual visualParent; + public Rect Bounds { get { return this.GetValue(BoundsPropertyW); } @@ -25,6 +27,23 @@ get { return Enumerable.Empty(); } } + public Visual VisualParent + { + get + { + return this.visualParent; + } + + set + { + if (this.visualParent != value) + { + this.visualParent = value; + this.InheritanceParent = value; + } + } + } + public virtual void Render(IDrawingContext context) { Contract.Requires(context != null);