feat: update AnchorItem Padding Converter.

This commit is contained in:
Zhang Dian
2025-07-10 19:55:34 +08:00
parent b304d585bd
commit 3ae76efd45
4 changed files with 67 additions and 22 deletions

View File

@@ -4,7 +4,7 @@
xmlns:converters="clr-namespace:Ursa.Themes.Semi.Converters"
xmlns:iri="https://irihi.tech/shared"
xmlns:u="https://irihi.tech/ursa">
<converters:TreeLevelToMarginConverter x:Key="LevelToMarginConverter" />
<converters:TreeLevelToPaddingConverter x:Key="LevelToPaddingConverter" />
<ControlTheme x:Key="{x:Type u:Anchor}" TargetType="{x:Type u:Anchor}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="VerticalAlignment" Value="Top" />
@@ -12,7 +12,7 @@
<ControlTemplate>
<Panel>
<Rectangle
Width="1"
Width="{DynamicResource AnchorPipeWidth}"
Name="PART_Pipe"
HorizontalAlignment="Left"
VerticalAlignment="Stretch"
@@ -24,7 +24,7 @@
</Panel>
</ControlTemplate>
</Setter>
<Style Selector="^.Mute /template/ Rectangle#PART_Pipe">
<Style Selector="^.Muted /template/ Rectangle#PART_Pipe">
<Setter Property="Fill" Value="Transparent" />
</Style>
</ControlTheme>
@@ -39,23 +39,23 @@
<Panel Background="{TemplateBinding Background}">
<Border
Name="PART_Pipe"
Width="2"
CornerRadius="1"
Width="{DynamicResource AnchorPipeWidth}"
CornerRadius="{DynamicResource AnchorPipeCornerRadius}"
HorizontalAlignment="Left"
VerticalAlignment="Stretch" />
<Panel Margin="8,0,0,0">
<Panel>
<ContentPresenter
Name="{x:Static iri:PartNames.PART_HeaderPresenter}"
VerticalAlignment="Center"
Foreground="{DynamicResource AnchorForeground}"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}">
<ContentPresenter.Margin>
<MultiBinding Converter="{StaticResource LevelToMarginConverter}">
<ContentPresenter.Padding>
<MultiBinding Converter="{StaticResource LevelToPaddingConverter}">
<Binding Path="Level" RelativeSource="{RelativeSource AncestorType={x:Type u:AnchorItem}}" />
<DynamicResource ResourceKey="AnchorIndent" />
</MultiBinding>
</ContentPresenter.Margin>
</ContentPresenter.Padding>
</ContentPresenter>
</Panel>
</Panel>
@@ -83,7 +83,7 @@
<Style Selector="^.Tertiary /template/ Border#PART_Pipe">
<Setter Property="Background" Value="{DynamicResource AnchorPipeSelectedTertiaryBackground}" />
</Style>
<Style Selector="^.Mute /template/ Border#PART_Pipe">
<Style Selector="^.Muted /template/ Border#PART_Pipe">
<Setter Property="Background" Value="Transparent" />
</Style>
</Style>

View File

@@ -4,14 +4,15 @@ using Avalonia.Data.Converters;
namespace Ursa.Themes.Semi.Converters;
public class TreeLevelToMarginConverter: IMultiValueConverter
public class TreeLevelToPaddingConverter : IMultiValueConverter
{
public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
{
if (values[0] is int i && values[1] is double indent)
if (values[0] is int i && values[1] is Thickness indent)
{
return new Thickness(Math.Max(i-1, 0) * indent, 0, 0, 0);
return new Thickness(Math.Max(i, 0) * indent.Left, indent.Top, indent.Right, indent.Bottom);
}
return new Thickness();
}
}

View File

@@ -1,6 +1,8 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<x:Double x:Key="AnchorIndent">12</x:Double>
<Thickness x:Key="AnchorIndent">8,4,0,4</Thickness>
<x:Double x:Key="AnchorPipeWidth">2</x:Double>
<CornerRadius x:Key="AnchorPipeCornerRadius">1</CornerRadius>
<x:Double x:Key="AnchorDefaultHeight">20</x:Double>
<x:Double x:Key="AnchorSmallHeight">16</x:Double>
<StaticResource x:Key="AnchorSmallFontSize" ResourceKey="SemiFontSizeSmall"/>
</ResourceDictionary>
<x:Double x:Key="AnchorSmallFontSize">12</x:Double>
</ResourceDictionary>