diff --git a/Perspex.Controls/Control.cs b/Perspex.Controls/Control.cs index 1dcf316abf..75f68f838a 100644 --- a/Perspex.Controls/Control.cs +++ b/Perspex.Controls/Control.cs @@ -27,12 +27,6 @@ namespace Perspex.Controls public static readonly PerspexProperty BorderThicknessProperty = PerspexProperty.Register("BorderThickness"); - public static readonly PerspexProperty FontSizeProperty = - PerspexProperty.Register( - "FontSize", - defaultValue: 12.0, - inherits: true); - public static readonly PerspexProperty ForegroundProperty = PerspexProperty.Register("Foreground", new SolidColorBrush(0xff000000), true); @@ -115,12 +109,6 @@ namespace Perspex.Controls } } - public double FontSize - { - get { return this.GetValue(FontSizeProperty); } - set { this.SetValue(FontSizeProperty, value); } - } - public Brush Foreground { get { return this.GetValue(ForegroundProperty); } diff --git a/Perspex.Controls/TextBlock.cs b/Perspex.Controls/TextBlock.cs index 84b3ac0dcd..e77cf21816 100644 --- a/Perspex.Controls/TextBlock.cs +++ b/Perspex.Controls/TextBlock.cs @@ -13,6 +13,15 @@ namespace Perspex.Controls public class TextBlock : Control { + public static readonly PerspexProperty FontSizeProperty = + PerspexProperty.Register( + "FontSize", + defaultValue: 12.0, + inherits: true); + + public static readonly PerspexProperty FontStyleProperty = + PerspexProperty.Register("FontStyle", inherits: true); + public static readonly PerspexProperty TextProperty = PerspexProperty.Register("Text"); @@ -27,6 +36,18 @@ namespace Perspex.Controls set { this.SetValue(TextProperty, value); } } + public double FontSize + { + get { return this.GetValue(FontSizeProperty); } + set { this.SetValue(FontSizeProperty, value); } + } + + public FontStyle FontStyle + { + get { return this.GetValue(FontStyleProperty); } + set { this.SetValue(FontStyleProperty, value); } + } + private FormattedText FormattedText { get @@ -35,6 +56,7 @@ namespace Perspex.Controls { FontFamilyName = "Segoe UI", FontSize = this.FontSize, + FontStyle = this.FontStyle, Text = this.Text, }; } diff --git a/Perspex.Controls/TextBoxView.cs b/Perspex.Controls/TextBoxView.cs index 0f02f94838..2a3a443939 100644 --- a/Perspex.Controls/TextBoxView.cs +++ b/Perspex.Controls/TextBoxView.cs @@ -111,7 +111,8 @@ namespace Perspex.Controls return new FormattedText { FontFamilyName = "Segoe UI", - FontSize = this.FontSize, + FontSize = this.GetValue(TextBlock.FontSizeProperty), + FontStyle = this.GetValue(TextBlock.FontStyleProperty), Text = this.parent.Text, }; } diff --git a/Perspex.Diagnostics/DevTools.cs b/Perspex.Diagnostics/DevTools.cs index c93d98d718..dcdb030ef6 100644 --- a/Perspex.Diagnostics/DevTools.cs +++ b/Perspex.Diagnostics/DevTools.cs @@ -29,9 +29,7 @@ namespace Perspex.Diagnostics { DataTemplates = new DataTemplates { - new TreeDataTemplate( - x => new TextBlock {Text = x.GetType().Name }, - x => x.VisualChildren), + new TreeDataTemplate(GetHeader, x => x.VisualChildren), }, [!TreeView.ItemsProperty] = this[!DevTools.RootProperty].Select(x => new[] { x }), } @@ -44,5 +42,19 @@ namespace Perspex.Diagnostics get { return this.GetValue(RootProperty); } set { this.SetValue(RootProperty, value); } } + + private static Control GetHeader(IVisual visual) + { + Control control = visual as Control; + TextBlock result = new TextBlock(); + result.Text = visual.GetType().Name; + + if (control != null && control.TemplatedParent != null) + { + result.FontStyle = Media.FontStyle.Italic; + } + + return result; + } } } diff --git a/Perspex.Direct2D1/TextService.cs b/Perspex.Direct2D1/TextService.cs index ce6a22075d..054c48f04a 100644 --- a/Perspex.Direct2D1/TextService.cs +++ b/Perspex.Direct2D1/TextService.cs @@ -26,6 +26,8 @@ namespace Perspex.Direct2D1 return new TextFormat( factory, text.FontFamilyName, + FontWeight.Normal, + (SharpDX.DirectWrite.FontStyle)text.FontStyle, (float)text.FontSize); } diff --git a/Perspex.SceneGraph/Media/FormattedText.cs b/Perspex.SceneGraph/Media/FormattedText.cs index 556d2a9f9f..b7a9dbf34b 100644 --- a/Perspex.SceneGraph/Media/FormattedText.cs +++ b/Perspex.SceneGraph/Media/FormattedText.cs @@ -6,12 +6,21 @@ namespace Perspex.Media { + public enum FontStyle + { + Normal, + Oblique, + Italic, + } + public class FormattedText { public string FontFamilyName { get; set; } public double FontSize { get; set; } + public FontStyle FontStyle { get; set; } + public string Text { get; set; } } } diff --git a/Perspex.Themes.Default/TabItemStyle.cs b/Perspex.Themes.Default/TabItemStyle.cs index b9929af95d..fd20c4cf8b 100644 --- a/Perspex.Themes.Default/TabItemStyle.cs +++ b/Perspex.Themes.Default/TabItemStyle.cs @@ -21,7 +21,7 @@ namespace Perspex.Themes.Default { Setters = new[] { - new Setter(TextBox.FontSizeProperty, 28.7), + new Setter(TextBlock.FontSizeProperty, 28.7), new Setter(Control.ForegroundProperty, Brushes.Gray), new Setter(TabItem.TemplateProperty, ControlTemplate.Create(this.Template)), }, diff --git a/TestApplication/Program.cs b/TestApplication/Program.cs index 2447fda627..9dfc45901b 100644 --- a/TestApplication/Program.cs +++ b/TestApplication/Program.cs @@ -147,6 +147,11 @@ namespace TestApplication { Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin venenatis dui quis libero suscipit tincidunt.", }, + new TextBlock + { + Text = "Italic text.", + FontStyle = FontStyle.Italic, + }, new TextBox { Text = "Text Box",