Browse Source

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.
pull/1831/head
William David Cossey 8 years ago
parent
commit
a161f6a095
  1. 8
      samples/ControlCatalog/Pages/ScreenPage.cs
  2. 40
      src/Avalonia.Controls/TreeViewItem.cs
  3. 6
      src/Avalonia.Themes.Default/Accents/BaseLight.xaml
  4. 27
      src/Avalonia.Themes.Default/DatePicker.xaml
  5. 154
      src/Avalonia.Themes.Default/TreeViewItem.xaml
  6. 5
      src/Skia/Avalonia.Skia/FormattedTextImpl.cs

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

40
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
/// </summary>
public static readonly DirectProperty<TreeViewItem, bool> IsExpandedProperty =
AvaloniaProperty.RegisterDirect<TreeViewItem, bool>(
"IsExpanded",
nameof(IsExpanded),
o => o.IsExpanded,
(o, v) => o.IsExpanded = v);
@ -31,11 +32,20 @@ namespace Avalonia.Controls
public static readonly StyledProperty<bool> IsSelectedProperty =
ListBoxItem.IsSelectedProperty.AddOwner<TreeViewItem>();
/// <summary>
/// Defines the <see cref="Depth"/> property.
/// </summary>
public static readonly DirectProperty<TreeViewItem, int> DepthProperty =
AvaloniaProperty.RegisterDirect<TreeViewItem, int>(
nameof(Depth),
o => o.Depth);
private static readonly ITemplate<IPanel> DefaultPanel =
new FuncTemplate<IPanel>(() => new StackPanel());
private TreeView _treeView;
private bool _isExpanded;
private int _depth;
/// <summary>
/// Initializes static members of the <see cref="TreeViewItem"/> class.
@ -65,6 +75,34 @@ namespace Avalonia.Controls
set { SetValue(IsSelectedProperty, value); }
}
/// <summary>
/// Gets or sets the depth of the item.
/// </summary>
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;
}
/// <summary>
/// Gets the <see cref="ITreeItemContainerGenerator"/> for the tree view.
/// </summary>

6
src/Avalonia.Themes.Default/Accents/BaseLight.xaml

@ -25,6 +25,8 @@
<Color x:Key="ErrorColor">#FFFF0000</Color>
<Color x:Key="ErrorLightColor">#10FF0000</Color>
<Color x:Key="InvisibleSelectionColor">#01000000</Color>
<SolidColorBrush x:Key="ThemeBackgroundBrush" Color="{DynamicResource ThemeBackgroundColor}"></SolidColorBrush>
<SolidColorBrush x:Key="ThemeBorderLightBrush" Color="{DynamicResource ThemeBorderLightColor}"></SolidColorBrush>
<SolidColorBrush x:Key="ThemeBorderMidBrush" Color="{DynamicResource ThemeBorderMidColor}"></SolidColorBrush>
@ -45,7 +47,9 @@
<SolidColorBrush x:Key="ThemeAccentBrush4" Color="{DynamicResource ThemeAccentColor4}"></SolidColorBrush>
<SolidColorBrush x:Key="ErrorBrush" Color="{DynamicResource ErrorColor}"></SolidColorBrush>
<SolidColorBrush x:Key="ErrorLightBrush" Color="{DynamicResource ErrorLightColor}"></SolidColorBrush>
<SolidColorBrush x:Key="InvisibleSelectionBrush" Color="{DynamicResource InvisibleSelectionColor}"></SolidColorBrush>
<Thickness x:Key="ThemeBorderThickness">2</Thickness>
<sys:Double x:Key="ThemeDisabledOpacity">0.5</sys:Double>

27
src/Avalonia.Themes.Default/DatePicker.xaml

@ -6,7 +6,8 @@
-->
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<Style Selector="DatePicker">
<Setter Property="Background" Value="{DynamicResource ThemeBackgroundBrush}"/>
@ -54,17 +55,19 @@
Stroke="{DynamicResource ThemeBorderDarkBrush}"
Fill="{DynamicResource ThemeAccentBrush}">
</Rectangle>
<Path HorizontalAlignment="Center"
Margin="4,3,4,3"
VerticalAlignment="Center"
RenderTransformOrigin="0.5,0.5"
Grid.Column="0"
Grid.Row="1"
Grid.ColumnSpan="4"
Grid.RowSpan="3"
Fill="{DynamicResource ThemeBorderDarkBrush}"
Stretch="Fill"
Data="M11.426758,8.4305077 L11.749023,8.4305077 L11.749023,16.331387 L10.674805,16.331387 L10.674805,10.299648 L9.0742188,11.298672 L9.0742188,10.294277 C9.4788408,10.090176 9.9094238,9.8090878 10.365967,9.4510155 C10.82251,9.0929432 11.176106,8.7527733 11.426758,8.4305077 z M14.65086,8.4305077 L18.566387,8.4305077 L18.566387,9.3435936 L15.671368,9.3435936 L15.671368,11.255703 C15.936341,11.058764 16.27293,10.960293 16.681133,10.960293 C17.411602,10.960293 17.969301,11.178717 18.354229,11.615566 C18.739157,12.052416 18.931622,12.673672 18.931622,13.479336 C18.931622,15.452317 18.052553,16.438808 16.294415,16.438808 C15.560365,16.438808 14.951641,16.234707 14.468243,15.826504 L14.881817,14.929531 C15.368796,15.326992 15.837872,15.525723 16.289043,15.525723 C17.298809,15.525723 17.803692,14.895514 17.803692,13.635098 C17.803692,12.460618 17.305971,11.873379 16.310528,11.873379 C15.83071,11.873379 15.399232,12.079271 15.016094,12.491055 L14.65086,12.238613 z" />
<TextBlock Margin="0,-1,0,0"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Grid.Column="0"
Grid.Row="1"
Grid.ColumnSpan="4"
Grid.RowSpan="3"
FontSize="{DynamicResource FontSizeSmall}"
Foreground="{DynamicResource ThemeBorderDarkBrush}">
<TextBlock.Text>
<Binding Source="{x:Static sys:DateTime.Today}" Path="Day"/>
</TextBlock.Text>
</TextBlock>
<Ellipse HorizontalAlignment="Center" VerticalAlignment="Center" Fill="{DynamicResource ThemeControlLightBrush}" StrokeThickness="0" Grid.ColumnSpan="4" Width="3" Height="3"/>
</Grid>

154
src/Avalonia.Themes.Default/TreeViewItem.xaml

@ -1,69 +1,91 @@
<Styles xmlns="https://github.com/avaloniaui">
<Style Selector="TreeViewItem">
<Setter Property="Padding" Value="2"/>
<Setter Property="Template">
<ControlTemplate>
<StackPanel>
<Grid ColumnDefinitions="16, Auto">
<ToggleButton Name="expander"
Focusable="False"
IsChecked="{TemplateBinding IsExpanded, Mode=TwoWay}"/>
<ContentPresenter Name="PART_HeaderPresenter"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Content="{TemplateBinding Header}"
Padding="{TemplateBinding Padding}"
TemplatedControl.IsTemplateFocusTarget="True"
Grid.Column="1"/>
</Grid>
<ItemsPresenter Name="PART_ItemsPresenter"
IsVisible="{TemplateBinding IsExpanded}"
Items="{TemplateBinding Items}"
ItemsPanel="{TemplateBinding ItemsPanel}"
Margin="24,0,0,0"
MemberSelector="{TemplateBinding MemberSelector}"/>
</StackPanel>
</ControlTemplate>
</Setter>
</Style>
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Avalonia.Controls.Converters;assembly=Avalonia.Controls">
<Style Selector="TreeViewItem">
<Style.Resources>
<local:MarginMultiplierConverter Indent="16" Left="True" x:Key="leftMarginConverter" />
</Style.Resources>
<Setter Property="Padding" Value="2"/>
<Setter Property="Background" Value="{DynamicResource InvisibleSelectionBrush}"/>
<Setter Property="Template">
<ControlTemplate>
<StackPanel>
<Border Name="SelectionBorder"
Focusable="True"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
TemplatedControl.IsTemplateFocusTarget="True">
<Grid ColumnDefinitions="16, *" Margin="{TemplateBinding Depth, Converter={StaticResource leftMarginConverter}}" >
<ToggleButton Name="expander"
Focusable="False"
IsChecked="{TemplateBinding IsExpanded, Mode=TwoWay}"/>
<ContentPresenter Name="PART_HeaderPresenter"
Focusable="False"
Content="{TemplateBinding Header}"
HorizontalContentAlignment="{TemplateBinding HorizontalAlignment}"
Padding="{TemplateBinding Padding}"
Grid.Column="1"/>
</Grid>
</Border>
<ItemsPresenter Name="PART_ItemsPresenter"
IsVisible="{TemplateBinding IsExpanded}"
Items="{TemplateBinding Items}"
ItemsPanel="{TemplateBinding ItemsPanel}"
MemberSelector="{TemplateBinding MemberSelector}"/>
</StackPanel>
</ControlTemplate>
</Setter>
</Style>
<Style Selector="TreeViewItem /template/ ToggleButton#expander">
<Setter Property="Template">
<ControlTemplate>
<Border Background="Transparent"
Width="14"
Height="12"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Path Fill="{DynamicResource ThemeForegroundBrush}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="M 0 2 L 4 6 L 0 10 Z"/>
</Border>
</ControlTemplate>
</Setter>
</Style>
<Style Selector="TreeViewItem /template/ ToggleButton#expander">
<Setter Property="Template">
<ControlTemplate>
<Border Background="Transparent"
Width="14"
Height="12"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Path Fill="{DynamicResource ThemeForegroundBrush}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="M 0 2 L 4 6 L 0 10 Z"/>
</Border>
</ControlTemplate>
</Setter>
</Style>
<Style Selector="TreeViewItem /template/ ContentPresenter#PART_HeaderPresenter">
<Setter Property="Padding" Value="2"/>
</Style>
<Style Selector="TreeViewItem:selected /template/ ContentPresenter#PART_HeaderPresenter">
<Setter Property="Background" Value="#fff0f0f0"/>
</Style>
<Style Selector="TreeViewItem:selected:focus /template/ ContentPresenter#PART_HeaderPresenter">
<Setter Property="Background" Value="#ffd0d0d0"/>
</Style>
<Style Selector="TreeViewItem /template/ ToggleButton#expander:checked">
<Setter Property="RenderTransform">
<RotateTransform Angle="45"/>
</Setter>
</Style>
<Style Selector="TreeViewItem /template/ ContentPresenter#PART_HeaderPresenter">
<Setter Property="Padding" Value="2"/>
</Style>
<Style Selector="TreeViewItem[IsSelected=false] /template/ Border#SelectionBorder[IsPointerOver=true]">
<Setter Property="Background" Value="{DynamicResource ThemeControlHighlightMidBrush}"/>
</Style>
<Style Selector="TreeViewItem:empty /template/ ToggleButton#expander">
<Setter Property="IsVisible" Value="False"/>
</Style>
</Styles>
<Style Selector="TreeViewItem[IsSelected=true] /template/ Border#SelectionBorder">
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush4}"/>
</Style>
<Style Selector="TreeViewItem[IsSelected=true] /template/ Border#SelectionBorder[IsPointerOver=false][IsFocused=true]">
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush3}"/>
</Style>
<Style Selector="TreeViewItem[IsSelected=true] /template/ Border#SelectionBorder[IsPointerOver=true][IsFocused=false]">
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush3}"/>
</Style>
<Style Selector="TreeViewItem[IsSelected=true] /template/ Border#SelectionBorder[IsPointerOver=true][IsFocused=true]">
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush2}"/>
</Style>
<Style Selector="TreeViewItem /template/ ToggleButton#expander:checked">
<Setter Property="RenderTransform">
<RotateTransform Angle="45"/>
</Setter>
</Style>
<Style Selector="TreeViewItem:empty /template/ ToggleButton#expander">
<Setter Property="IsVisible" Value="False"/>
</Style>
</Styles>

5
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);

Loading…
Cancel
Save