feat: update selection handling, fix initial offset calculation.

This commit is contained in:
Dong Bin
2025-07-08 13:36:11 +08:00
parent 68f95826c5
commit fb799636d9
8 changed files with 116 additions and 57 deletions

View File

@@ -1,31 +1,60 @@
<ResourceDictionary
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:u="https://irihi.tech/ursa"
xmlns:iri="https://irihi.tech/shared">
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" />
<ControlTheme x:Key="{x:Type u:Anchor}" TargetType="{x:Type u:Anchor}">
<Setter Property="Template">
<ControlTemplate>
<ItemsPresenter
Name="PART_ItemsPresenter"
Margin="{TemplateBinding Padding}"
ItemsPanel="{TemplateBinding ItemsPanel}" />
<Panel>
<Rectangle
Width="1"
HorizontalAlignment="Left"
VerticalAlignment="Stretch"
Fill="{DynamicResource SemiColorBorder}" />
<ItemsPresenter
Name="PART_ItemsPresenter"
Margin="{TemplateBinding Padding}"
ItemsPanel="{TemplateBinding ItemsPanel}" />
</Panel>
</ControlTemplate>
</Setter>
</ControlTheme>
<ControlTheme x:Key="{x:Type u:AnchorItem}" TargetType="u:AnchorItem" >
<ControlTheme x:Key="{x:Type u:AnchorItem}" TargetType="u:AnchorItem">
<Setter Property="Background" Value="Transparent" />
<Setter Property="MinHeight" Value="20" />
<Setter Property="Template">
<ControlTemplate TargetType="u:AnchorItem">
<StackPanel>
<ContentPresenter Name="{x:Static iri:PartNames.PART_HeaderPresenter}" Content="{TemplateBinding Header}" ContentTemplate="{TemplateBinding HeaderTemplate}" />
<ItemsPresenter Margin="8 0 0 0" ItemsPanel="{TemplateBinding ItemsPanel}" />
<Panel>
<Rectangle
Name="PART_Pipe"
Width="2"
HorizontalAlignment="Left"
VerticalAlignment="Stretch" />
<Panel Margin="8,0,0,0">
<ContentPresenter
Name="{x:Static iri:PartNames.PART_HeaderPresenter}"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}">
<ContentPresenter.Margin>
<MultiBinding Converter="{StaticResource LevelToMarginConverter}">
<Binding Path="Level" RelativeSource="{RelativeSource AncestorType={x:Type u:AnchorItem}}" />
<DynamicResource ResourceKey="AnchorIndent" />
</MultiBinding>
</ContentPresenter.Margin>
</ContentPresenter>
</Panel>
</Panel>
<ItemsPresenter ItemsPanel="{TemplateBinding ItemsPanel}" />
</StackPanel>
</ControlTemplate>
</Setter>
<Style Selector="^:selected /template/ ContentPresenter#PART_HeaderPresenter">
<Setter Property="Foreground" Value="{DynamicResource SemiBlue5}" />
<Style Selector="^:selected /template/ Rectangle#PART_Pipe">
<Setter Property="Fill" Value="{DynamicResource SemiBlue5}" />
</Style>
</ControlTheme>
</ResourceDictionary>

View File

@@ -1,23 +0,0 @@
using System.Globalization;
using Avalonia;
using Avalonia.Data.Converters;
namespace Ursa.Themes.Semi.Converters;
public class NavigationMenuItemLevelToMarginConverter: IMultiValueConverter
{
public int Indent { get; set; }
public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
{
if (values[0] is int i && values[1] is bool b)
{
if (b)
{
return new Thickness();
}
return new Thickness((i-1) * Indent, 0, 0, 0);
}
return new Thickness();
}
}

View File

@@ -0,0 +1,17 @@
using System.Globalization;
using Avalonia;
using Avalonia.Data.Converters;
namespace Ursa.Themes.Semi.Converters;
public class TreeLevelToMarginConverter: IMultiValueConverter
{
public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
{
if (values[0] is int i && values[1] is double indent)
{
return new Thickness((i-1) * indent, 0, 0, 0);
}
return new Thickness();
}
}

View File

@@ -0,0 +1,4 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<x:Double x:Key="AnchorIndent">12</x:Double>
</ResourceDictionary>

View File

@@ -1,6 +1,7 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source="Avatar.axaml" />
<ResourceInclude Source="Anchor.axaml" />
<ResourceInclude Source="Badge.axaml" />
<ResourceInclude Source="Banner.axaml" />
<ResourceInclude Source="ButtonGroup.axaml" />