Merge pull request #122 from irihitech/fix

Use PureRectangle in shared library.
This commit is contained in:
Dong Bin
2024-02-26 14:29:12 +08:00
committed by GitHub
11 changed files with 22 additions and 111 deletions

View File

@@ -1,14 +1,14 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" <ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:u="https://irihi.tech/ursa" xmlns:u="https://irihi.tech/ursa"
xmlns:shapes="clr-namespace:Ursa.Controls.Shapes;assembly=Ursa"> xmlns:iri="https://irihi.tech/shared">
<!-- Add Resources Here --> <!-- Add Resources Here -->
<ControlTheme TargetType="u:DisableContainer" x:Key="{x:Type u:DisableContainer}"> <ControlTheme TargetType="u:DisableContainer" x:Key="{x:Type u:DisableContainer}">
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate TargetType="u:DisableContainer"> <ControlTemplate TargetType="u:DisableContainer">
<Panel> <Panel>
<ContentPresenter Content="{TemplateBinding Content}"></ContentPresenter> <ContentPresenter Content="{TemplateBinding Content}"></ContentPresenter>
<shapes:PureRectangle Background="Transparent" IsVisible="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content.IsEnabled, Converter={x:Static BoolConverters.Not}}" Cursor="No" ToolTip.Tip="{TemplateBinding DisabledTip}"/> <iri:PureRectangle Background="Transparent" IsVisible="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content.IsEnabled, Converter={x:Static BoolConverters.Not}}" Cursor="No" ToolTip.Tip="{TemplateBinding DisabledTip}"/>
</Panel> </Panel>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>

View File

@@ -3,7 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:Ursa.Themes.Semi.Converters" xmlns:converters="clr-namespace:Ursa.Themes.Semi.Converters"
xmlns:u="clr-namespace:Ursa.Controls;assembly=Ursa" xmlns:u="clr-namespace:Ursa.Controls;assembly=Ursa"
xmlns:shapes="clr-namespace:Ursa.Controls.Shapes;assembly=Ursa"> xmlns:iri="https://irihi.tech/shared">
<!-- Add Resources Here --> <!-- Add Resources Here -->
<converters:BrushToColorConverter x:Key="BrushToColorConverter" /> <converters:BrushToColorConverter x:Key="BrushToColorConverter" />
<ControlTheme x:Key="{x:Type u:LoadingIcon}" TargetType="u:LoadingIcon"> <ControlTheme x:Key="{x:Type u:LoadingIcon}" TargetType="u:LoadingIcon">
@@ -68,9 +68,10 @@
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate TargetType="u:Loading"> <ControlTemplate TargetType="u:Loading">
<Panel IsVisible="{TemplateBinding IsLoading}"> <Panel IsVisible="{TemplateBinding IsLoading}">
<shapes:PureRectangle <iri:PureRectangle
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" VerticalAlignment="Stretch"
IsHitTestVisible="True"
Background="{TemplateBinding Background}" /> Background="{TemplateBinding Background}" />
<Grid <Grid
HorizontalAlignment="Center" HorizontalAlignment="Center"

View File

@@ -1,7 +1,8 @@
<ResourceDictionary <ResourceDictionary
xmlns="https://github.com/avaloniaui" xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:u="https://irihi.tech/ursa"> xmlns:u="https://irihi.tech/ursa"
xmlns:iri="https://irihi.tech/shared">
<Design.PreviewWith> <Design.PreviewWith>
<Border Padding="20"> <Border Padding="20">
<!-- Add Controls for Previewer Here --> <!-- Add Controls for Previewer Here -->
@@ -24,19 +25,19 @@
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}" Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" /> ContentTemplate="{TemplateBinding ContentTemplate}" />
<Border <iri:PureRectangle
x:Name="PART_LoadingBorder" x:Name="PART_LoadingBorder"
Classes.Active="{Binding Path= IsActive, RelativeSource={RelativeSource TemplatedParent}}" Classes.Active="{Binding Path= IsActive, RelativeSource={RelativeSource TemplatedParent}}"
IsHitTestVisible="{TemplateBinding IsLoading}" IsHitTestVisible="{TemplateBinding IsLoading}"
Background="{DynamicResource SkeletonDefaultBackground}" Background="{DynamicResource SkeletonDefaultBackground}"
IsVisible="{TemplateBinding IsLoading}"> IsVisible="{TemplateBinding IsLoading}">
</Border> </iri:PureRectangle>
<Border <iri:PureRectangle
x:Name="PART_ActiveBorder" x:Name="PART_ActiveBorder"
IsHitTestVisible="{TemplateBinding IsLoading}" IsHitTestVisible="{TemplateBinding IsLoading}"
IsVisible="{TemplateBinding IsLoading}" IsVisible="{TemplateBinding IsLoading}"
> >
</Border> </iri:PureRectangle>
</Panel> </Panel>
</Border> </Border>
</ControlTemplate> </ControlTemplate>

View File

@@ -1,6 +1,7 @@
<Styles xmlns="https://github.com/avaloniaui" <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:u="https://irihi.tech/ursa"> xmlns:u="https://irihi.tech/ursa"
xmlns:iri="https://irihi.tech/shared">
<Design.PreviewWith> <Design.PreviewWith>
<Border Padding="20"> <Border Padding="20">
<!-- Add Controls for Previewer Here --> <!-- Add Controls for Previewer Here -->
@@ -8,7 +9,7 @@
</Design.PreviewWith> </Design.PreviewWith>
<!-- Add Styles Here --> <!-- Add Styles Here -->
<Style Selector="u|Skeleton[IsActive=True][IsLoading=True] /template/ Border#PART_ActiveBorder"> <Style Selector="u|Skeleton[IsActive=True][IsLoading=True] /template/ iri|PureRectangle#PART_ActiveBorder">
<Style.Animations> <Style.Animations>
<Animation <Animation
FillMode="None" FillMode="None"
@@ -17,10 +18,10 @@
PlaybackDirection="Alternate" PlaybackDirection="Alternate"
Duration="0:0:1.4"> Duration="0:0:1.4">
<KeyFrame Cue="0%"> <KeyFrame Cue="0%">
<Setter Property="Border.Background" Value="{DynamicResource SkeletonStartAnimationBackground}" /> <Setter Property="Background" Value="{DynamicResource SkeletonStartAnimationBackground}" />
</KeyFrame> </KeyFrame>
<KeyFrame Cue="100%"> <KeyFrame Cue="100%">
<Setter Property="Border.Background" Value="{DynamicResource SkeletonEndAnimationBackground}" /> <Setter Property="Background" Value="{DynamicResource SkeletonEndAnimationBackground}" />
</KeyFrame> </KeyFrame>
</Animation> </Animation>
</Style.Animations> </Style.Animations>

View File

@@ -1,12 +1,10 @@
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.Primitives; using Avalonia.Controls.Primitives;
using Avalonia.Data;
using Avalonia.Data.Converters;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Layout; using Avalonia.Layout;
using Avalonia.Media; using Avalonia.Media;
using Ursa.Controls.Shapes; using Irihi.Avalonia.Shared.Shapes;
namespace Ursa.Controls; namespace Ursa.Controls;
@@ -33,7 +31,7 @@ public class DisabledAdorner
{ {
if (arg2.NewValue.Value) if (arg2.NewValue.Value)
{ {
var pureRectangle = new Border() var pureRectangle = new PureRectangle()
{ {
Background = Brushes.Transparent, Background = Brushes.Transparent,
IsHitTestVisible = true, IsHitTestVisible = true,

View File

@@ -1,17 +1,8 @@
using Avalonia; using Avalonia;
using Avalonia.Animation;
using Avalonia.Animation.Easings;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Layout;
using Avalonia.Media;
using Avalonia.Styling;
using Avalonia.Utilities; using Avalonia.Utilities;
using Irihi.Avalonia.Shared.Shapes;
using Ursa.Controls.OverlayShared; using Ursa.Controls.OverlayShared;
using Ursa.Controls.Shapes;
using Ursa.EventArgs;
namespace Ursa.Controls; namespace Ursa.Controls;

View File

@@ -3,9 +3,9 @@ using Avalonia.Animation;
using Avalonia.Animation.Easings; using Avalonia.Animation.Easings;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Styling; using Avalonia.Styling;
using Irihi.Avalonia.Shared.Shapes;
using Ursa.Common; using Ursa.Common;
using Ursa.Controls.OverlayShared; using Ursa.Controls.OverlayShared;
using Ursa.Controls.Shapes;
using Ursa.EventArgs; using Ursa.EventArgs;
namespace Ursa.Controls; namespace Ursa.Controls;

View File

@@ -1,15 +1,12 @@
using Avalonia; using Avalonia;
using Avalonia.Animation; using Avalonia.Animation;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.Shapes;
using Avalonia.Controls.Templates; using Avalonia.Controls.Templates;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Media; using Avalonia.Media;
using Ursa.Controls.OverlayShared; using Ursa.Controls.OverlayShared;
using Avalonia.Layout;
using Avalonia.Media.Immutable;
using Avalonia.Styling; using Avalonia.Styling;
using Ursa.Controls.Shapes; using Irihi.Avalonia.Shared.Shapes;
namespace Ursa.Controls; namespace Ursa.Controls;

View File

@@ -1,45 +0,0 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Media;
namespace Ursa.Controls.Shapes;
public class PureCircle: Control
{
public static readonly StyledProperty<IBrush?> BackgroundProperty =
TemplatedControl.BackgroundProperty.AddOwner<PureCircle>();
public IBrush? Background
{
get => GetValue(BackgroundProperty);
set => SetValue(BackgroundProperty, value);
}
public static readonly StyledProperty<double> DiameterProperty = AvaloniaProperty.Register<PureCircle, double>(
nameof(Diameter));
public double Diameter
{
get => GetValue(DiameterProperty);
set => SetValue(DiameterProperty, value);
}
static PureCircle()
{
FocusableProperty.OverrideDefaultValue<PureCircle>(false);
AffectsMeasure<PureCircle>(DiameterProperty);
AffectsRender<PureCircle>(DiameterProperty, BackgroundProperty);
}
protected override Size MeasureOverride(Size availableSize)
{
return new Size(Diameter, Diameter);
}
public override void Render(DrawingContext context)
{
double value = Diameter / 2;
context.DrawEllipse(Background, null, new(value, value), value, value);
}
}

View File

@@ -1,33 +0,0 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
using Avalonia.Markup.Xaml.Templates;
using Avalonia.Media;
namespace Ursa.Controls.Shapes;
/// <summary>
/// A rectangle, with no corner radius.
/// </summary>
public class PureRectangle: Control
{
public static readonly StyledProperty<IBrush?> BackgroundProperty =
TemplatedControl.BackgroundProperty.AddOwner<PureRectangle>();
public IBrush? Background
{
get => GetValue(BackgroundProperty);
set => SetValue(BackgroundProperty, value);
}
static PureRectangle()
{
FocusableProperty.OverrideDefaultValue<PureRectangle>(false);
AffectsRender<PureRectangle>(BackgroundProperty);
}
public override void Render(DrawingContext context)
{
context.DrawRectangle(Background, null, new Rect(Bounds.Size));
}
}

View File

@@ -14,7 +14,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" /> <PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Irihi.Avalonia.Shared" Version="0.1.4" /> <PackageReference Include="Irihi.Avalonia.Shared" Version="0.1.5" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>