From a161f6a095eb990b48d9b7173326b6fcd7fceac4 Mon Sep 17 00:00:00 2001 From: William David Cossey Date: Tue, 28 Aug 2018 22:31:46 +0100 Subject: [PATCH] ScreenPage.cs - Bug fix. TreeViewItem - Added Depth property. BaseLight.xaml - Added InvisibleSelectionColor/Brush. DatePicker.xaml - Improvments. TreeViewItem.xaml - Reworked styling. FormattedTextImpl.cs - Reverted previous changes. --- samples/ControlCatalog/Pages/ScreenPage.cs | 8 +- src/Avalonia.Controls/TreeViewItem.cs | 40 ++++- .../Accents/BaseLight.xaml | 6 +- src/Avalonia.Themes.Default/DatePicker.xaml | 27 +-- src/Avalonia.Themes.Default/TreeViewItem.xaml | 154 ++++++++++-------- src/Skia/Avalonia.Skia/FormattedTextImpl.cs | 5 - 6 files changed, 153 insertions(+), 87 deletions(-) diff --git a/samples/ControlCatalog/Pages/ScreenPage.cs b/samples/ControlCatalog/Pages/ScreenPage.cs index 34aa85b8aa..fd66185832 100644 --- a/samples/ControlCatalog/Pages/ScreenPage.cs +++ b/samples/ControlCatalog/Pages/ScreenPage.cs @@ -42,7 +42,11 @@ namespace ControlCatalog.Pages context.DrawRectangle(p, boundsRect); context.DrawRectangle(p, workingAreaRect); - FormattedText text = new FormattedText(); + FormattedText text = new FormattedText() + { + Typeface = Typeface.Default + }; + text.Text = $"Bounds: {screen.Bounds.Width}:{screen.Bounds.Height}"; context.DrawText(Brushes.Black, boundsRect.Position.WithY(boundsRect.Size.Height), text); @@ -59,4 +63,4 @@ namespace ControlCatalog.Pages context.DrawRectangle(p, new Rect(w.Position.X / 10f + Math.Abs(_leftMost), w.Position.Y / 10, w.Bounds.Width / 10, w.Bounds.Height / 10)); } } -} \ No newline at end of file +} diff --git a/src/Avalonia.Controls/TreeViewItem.cs b/src/Avalonia.Controls/TreeViewItem.cs index 0886c05038..33b0e54868 100644 --- a/src/Avalonia.Controls/TreeViewItem.cs +++ b/src/Avalonia.Controls/TreeViewItem.cs @@ -6,6 +6,7 @@ using Avalonia.Controls.Generators; using Avalonia.Controls.Mixins; using Avalonia.Controls.Primitives; using Avalonia.Controls.Templates; +using Avalonia.Data; using Avalonia.Input; using Avalonia.LogicalTree; @@ -21,7 +22,7 @@ namespace Avalonia.Controls /// public static readonly DirectProperty IsExpandedProperty = AvaloniaProperty.RegisterDirect( - "IsExpanded", + nameof(IsExpanded), o => o.IsExpanded, (o, v) => o.IsExpanded = v); @@ -31,11 +32,20 @@ namespace Avalonia.Controls public static readonly StyledProperty IsSelectedProperty = ListBoxItem.IsSelectedProperty.AddOwner(); + /// + /// Defines the property. + /// + public static readonly DirectProperty DepthProperty = + AvaloniaProperty.RegisterDirect( + nameof(Depth), + o => o.Depth); + private static readonly ITemplate DefaultPanel = new FuncTemplate(() => new StackPanel()); private TreeView _treeView; private bool _isExpanded; + private int _depth; /// /// Initializes static members of the class. @@ -65,6 +75,34 @@ namespace Avalonia.Controls set { SetValue(IsSelectedProperty, value); } } + /// + /// Gets or sets the depth of the item. + /// + public int Depth + { + get { return this.GetDepth(this); } + } + + private int GetDepth(TreeViewItem item) + { + TreeViewItem parent; + while ((parent = GetParent(item)) != null) + { + return GetDepth(parent) + 1; + } + return 0; + } + + private static TreeViewItem GetParent(TreeViewItem item) + { + var parent = item.InheritanceParent; + while (!(parent == null || parent is TreeViewItem || parent is TreeView)) + { + parent = item.Parent; + } + return parent as TreeViewItem; + } + /// /// Gets the for the tree view. /// diff --git a/src/Avalonia.Themes.Default/Accents/BaseLight.xaml b/src/Avalonia.Themes.Default/Accents/BaseLight.xaml index afac69c9b3..5aac023708 100644 --- a/src/Avalonia.Themes.Default/Accents/BaseLight.xaml +++ b/src/Avalonia.Themes.Default/Accents/BaseLight.xaml @@ -25,6 +25,8 @@ #FFFF0000 #10FF0000 + #01000000 + @@ -45,7 +47,9 @@ - + + + 2 0.5 diff --git a/src/Avalonia.Themes.Default/DatePicker.xaml b/src/Avalonia.Themes.Default/DatePicker.xaml index 8e0bb5f0b0..93bafdb56f 100644 --- a/src/Avalonia.Themes.Default/DatePicker.xaml +++ b/src/Avalonia.Themes.Default/DatePicker.xaml @@ -6,7 +6,8 @@ --> + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:sys="clr-namespace:System;assembly=mscorlib"> + + - + - - - - - - - + + + - - \ No newline at end of file + + + + + + + + + + + + diff --git a/src/Skia/Avalonia.Skia/FormattedTextImpl.cs b/src/Skia/Avalonia.Skia/FormattedTextImpl.cs index 8ad88da7f4..c8d051ed74 100644 --- a/src/Skia/Avalonia.Skia/FormattedTextImpl.cs +++ b/src/Skia/Avalonia.Skia/FormattedTextImpl.cs @@ -30,11 +30,6 @@ namespace Avalonia.Skia SKTypeface skiaTypeface = TypefaceCache.Default; - if (typeface == null) - { - typeface = Typeface.Default; - } - if (typeface.FontFamily.Key != null) { var typefaces = SKTypefaceCollectionCache.GetOrAddTypefaceCollection(typeface.FontFamily);