Browse Source

Display template controls in italic.

pull/4/head
Steven Kirk 12 years ago
parent
commit
007dbd2656
  1. 12
      Perspex.Controls/Control.cs
  2. 22
      Perspex.Controls/TextBlock.cs
  3. 3
      Perspex.Controls/TextBoxView.cs
  4. 18
      Perspex.Diagnostics/DevTools.cs
  5. 2
      Perspex.Direct2D1/TextService.cs
  6. 9
      Perspex.SceneGraph/Media/FormattedText.cs
  7. 2
      Perspex.Themes.Default/TabItemStyle.cs
  8. 5
      TestApplication/Program.cs

12
Perspex.Controls/Control.cs

@ -27,12 +27,6 @@ namespace Perspex.Controls
public static readonly PerspexProperty<double> BorderThicknessProperty =
PerspexProperty.Register<Control, double>("BorderThickness");
public static readonly PerspexProperty<double> FontSizeProperty =
PerspexProperty.Register<Control, double>(
"FontSize",
defaultValue: 12.0,
inherits: true);
public static readonly PerspexProperty<Brush> ForegroundProperty =
PerspexProperty.Register<Control, Brush>("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); }

22
Perspex.Controls/TextBlock.cs

@ -13,6 +13,15 @@ namespace Perspex.Controls
public class TextBlock : Control
{
public static readonly PerspexProperty<double> FontSizeProperty =
PerspexProperty.Register<Control, double>(
"FontSize",
defaultValue: 12.0,
inherits: true);
public static readonly PerspexProperty<FontStyle> FontStyleProperty =
PerspexProperty.Register<Control, FontStyle>("FontStyle", inherits: true);
public static readonly PerspexProperty<string> TextProperty =
PerspexProperty.Register<TextBlock, string>("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,
};
}

3
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,
};
}

18
Perspex.Diagnostics/DevTools.cs

@ -29,9 +29,7 @@ namespace Perspex.Diagnostics
{
DataTemplates = new DataTemplates
{
new TreeDataTemplate<IVisual>(
x => new TextBlock {Text = x.GetType().Name },
x => x.VisualChildren),
new TreeDataTemplate<IVisual>(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;
}
}
}

2
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);
}

9
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; }
}
}

2
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<TabItem>(this.Template)),
},

5
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",

Loading…
Cancel
Save