Merge pull request #323 from irihitech/cleanup

Clean up warnings
This commit is contained in:
Dong Bin
2024-07-31 00:57:22 +08:00
committed by GitHub
171 changed files with 515 additions and 869 deletions

View File

@@ -1,5 +1,4 @@
using Avalonia.Controls;
using Ursa.Controls;
using Ursa.Controls;
namespace Ursa.PrismExtension;

View File

@@ -70,7 +70,7 @@
</Setter>
<Style Selector="^[Dot=True]">
<Setter Property="u:Badge.Template">
<Setter Property="Template">
<ControlTemplate TargetType="{x:Type u:Badge}">
<Grid
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"

View File

@@ -69,54 +69,54 @@
</Setter>
<Style Selector="^[Type=Information]">
<Style Selector="^.Bordered /template/ Border#PART_Container">
<Setter Property="Border.CornerRadius" Value="{DynamicResource BannerCornerRadius}" />
<Setter Property="CornerRadius" Value="{DynamicResource BannerCornerRadius}" />
<Setter Property="BorderBrush" Value="{DynamicResource BannerInformationBorderBrush}" />
</Style>
<Style Selector="^ /template/ Border#PART_Container">
<Setter Property="Background" Value="{DynamicResource BannerInformationBackground}" />
</Style>
<Style Selector="^ /template/ PathIcon#PART_BuildInIcon">
<Setter Property="PathIcon.Data" Value="{DynamicResource BannerInformationIconGeometry}" />
<Setter Property="PathIcon.Foreground" Value="{DynamicResource BannerInformationBorderBrush}" />
<Setter Property="Data" Value="{DynamicResource BannerInformationIconGeometry}" />
<Setter Property="Foreground" Value="{DynamicResource BannerInformationBorderBrush}" />
</Style>
</Style>
<Style Selector="^[Type=Success]">
<Style Selector="^.Bordered /template/ Border#PART_Container">
<Setter Property="Border.CornerRadius" Value="{DynamicResource BannerCornerRadius}" />
<Setter Property="CornerRadius" Value="{DynamicResource BannerCornerRadius}" />
<Setter Property="BorderBrush" Value="{DynamicResource BannerSuccessBorderBrush}" />
</Style>
<Style Selector="^ /template/ Border#PART_Container">
<Setter Property="Background" Value="{DynamicResource BannerSuccessBackground}" />
</Style>
<Style Selector="^ /template/ PathIcon#PART_BuildInIcon">
<Setter Property="PathIcon.Data" Value="{DynamicResource BannerSuccessIconGeometry}" />
<Setter Property="PathIcon.Foreground" Value="{DynamicResource BannerSuccessBorderBrush}" />
<Setter Property="Data" Value="{DynamicResource BannerSuccessIconGeometry}" />
<Setter Property="Foreground" Value="{DynamicResource BannerSuccessBorderBrush}" />
</Style>
</Style>
<Style Selector="^[Type=Warning]">
<Style Selector="^.Bordered /template/ Border#PART_Container">
<Setter Property="Border.CornerRadius" Value="{DynamicResource BannerCornerRadius}" />
<Setter Property="CornerRadius" Value="{DynamicResource BannerCornerRadius}" />
<Setter Property="BorderBrush" Value="{DynamicResource BannerWarningBorderBrush}" />
</Style>
<Style Selector="^ /template/ Border#PART_Container">
<Setter Property="Background" Value="{DynamicResource BannerWarningBackground}" />
</Style>
<Style Selector="^ /template/ PathIcon#PART_BuildInIcon">
<Setter Property="PathIcon.Data" Value="{DynamicResource BannerWarningIconGeometry}" />
<Setter Property="PathIcon.Foreground" Value="{DynamicResource BannerWarningBorderBrush}" />
<Setter Property="Data" Value="{DynamicResource BannerWarningIconGeometry}" />
<Setter Property="Foreground" Value="{DynamicResource BannerWarningBorderBrush}" />
</Style>
</Style>
<Style Selector="^[Type=Error]">
<Style Selector="^.Bordered /template/ Border#PART_Container">
<Setter Property="Border.CornerRadius" Value="{DynamicResource BannerCornerRadius}" />
<Setter Property="CornerRadius" Value="{DynamicResource BannerCornerRadius}" />
<Setter Property="BorderBrush" Value="{DynamicResource BannerErrorBorderBrush}" />
</Style>
<Style Selector="^ /template/ Border#PART_Container">
<Setter Property="Background" Value="{DynamicResource BannerErrorBackground}" />
</Style>
<Style Selector="^ /template/ PathIcon#PART_BuildInIcon">
<Setter Property="PathIcon.Data" Value="{DynamicResource BannerErrorIconGeometry}" />
<Setter Property="PathIcon.Foreground" Value="{DynamicResource BannerErrorBorderBrush}" />
<Setter Property="Data" Value="{DynamicResource BannerErrorIconGeometry}" />
<Setter Property="Foreground" Value="{DynamicResource BannerErrorBorderBrush}" />
</Style>
</Style>
</ControlTheme>

View File

@@ -1,7 +1,6 @@
<ResourceDictionary
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:contracts="https://irihi.tech/shared"
xmlns:u="https://irihi.tech/ursa">
<!-- Add Resources Here -->
<ControlTheme x:Key="{x:Type u:DatePicker}" TargetType="u:DatePicker">

View File

@@ -165,7 +165,6 @@
<ScrollViewer Grid.Row="1">
<ContentPresenter
Name="PART_ContentPresenter"
Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="24,8"

View File

@@ -85,7 +85,6 @@
<ScrollViewer Grid.Row="1">
<ContentPresenter
Name="PART_ContentPresenter"
Grid.Row="1"
Margin="24,8"
Content="{TemplateBinding Content}" />
</ScrollViewer>

View File

@@ -113,10 +113,10 @@
</ControlTemplate>
</Setter>
<Style Selector="^:pointerover /template/ Border#PART_Border">
<Setter Property="Border.Background" Value="{DynamicResource IPv4BoxPointeroverBackground}" />
<Setter Property="Background" Value="{DynamicResource IPv4BoxPointeroverBackground}" />
</Style>
<Style Selector="^:pressed /template/ Border#PART_Border">
<Setter Property="Border.Background" Value="{DynamicResource IPv4BoxPressedBackground}" />
<Setter Property="Background" Value="{DynamicResource IPv4BoxPressedBackground}" />
</Style>
<Style Selector="^:focus-within">
<Setter Property="Border.BorderBrush" Value="{DynamicResource IPv4BoxFocusBorderBrush}" />

View File

@@ -59,7 +59,7 @@
</Panel>
<ContentPresenter
Name="PART_ContentPresenter"
Grid.Column="1"
Grid.Row="0" Grid.Column="1"
Margin="8 0 0 0"
HorizontalAlignment="Center"
VerticalAlignment="Center"

View File

@@ -47,14 +47,14 @@
</ControlTemplate>
</Setter>
<Style Selector="^.Small /template/ Arc#PART_Arc">
<Setter Property="Arc.Width" Value="14" />
<Setter Property="Arc.Height" Value="14" />
<Setter Property="Arc.StrokeThickness" Value="2" />
<Setter Property="Width" Value="14" />
<Setter Property="Height" Value="14" />
<Setter Property="StrokeThickness" Value="2" />
</Style>
<Style Selector="^.Large /template/ Arc#PART_Arc">
<Setter Property="Arc.Width" Value="32" />
<Setter Property="Arc.Height" Value="32" />
<Setter Property="Arc.StrokeThickness" Value="5" />
<Setter Property="Width" Value="32" />
<Setter Property="Height" Value="32" />
<Setter Property="StrokeThickness" Value="5" />
</Style>
</ControlTheme>

View File

@@ -1,7 +1,6 @@
<ResourceDictionary
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:Ursa.Converters;assembly=Ursa"
xmlns:u="https://irihi.tech/ursa">
<!-- Add Resources Here -->
<ControlTheme x:Key="{x:Type u:NumberDisplayerBase}" TargetType="u:NumberDisplayerBase">

View File

@@ -74,13 +74,13 @@
</ControlTemplate>
</Setter>
<Style Selector="^:pointerover">
<Setter Property="u:PaginationButton.Background" Value="{DynamicResource PaginationButtonPointeroverBackground}" />
<Setter Property="Background" Value="{DynamicResource PaginationButtonPointeroverBackground}" />
</Style>
<Style Selector="^:pressed">
<Setter Property="u:PaginationButton.Background" Value="{DynamicResource PaginationButtonPressedBackground}" />
<Setter Property="Background" Value="{DynamicResource PaginationButtonPressedBackground}" />
</Style>
<Style Selector="^:left">
<Setter Property="u:PaginationButton.Content">
<Setter Property="Content">
<Template>
<PathIcon
Width="12"
@@ -90,7 +90,7 @@
</Template>
</Setter>
<Style Selector="^:pointerover">
<Setter Property="u:PaginationButton.Content">
<Setter Property="Content">
<Template>
<PathIcon
Width="12"
@@ -102,7 +102,7 @@
</Style>
</Style>
<Style Selector="^:right">
<Setter Property="u:PaginationButton.Content">
<Setter Property="Content">
<Template>
<PathIcon
Width="12"
@@ -112,7 +112,7 @@
</Template>
</Setter>
<Style Selector="^:pointerover">
<Setter Property="u:PaginationButton.Content">
<Setter Property="Content">
<Template>
<PathIcon
Width="12"

View File

@@ -52,10 +52,10 @@
<Setter Property="IsVisible" Value="True"></Setter>
</Style>
<Style Selector="^:pointerover /template/ Border#PART_BackgroundBorder">
<Setter Property="Border.Background" Value="{DynamicResource TextBoxPointeroverBackground}" />
<Setter Property="Background" Value="{DynamicResource TextBoxPointeroverBackground}" />
</Style>
<Style Selector="^:focus-within /template/ Border#PART_BackgroundBorder">
<Setter Property="Border.BorderBrush" Value="{DynamicResource TextBoxFocusBorderBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource TextBoxFocusBorderBrush}" />
</Style>
</ControlTheme>

View File

@@ -1,7 +1,6 @@
<ResourceDictionary
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:Ursa.Converters;assembly=Ursa"
xmlns:iri="https://irihi.tech/shared"
xmlns:u="https://irihi.tech/ursa">
<!-- Add Resources Here -->

View File

@@ -110,7 +110,7 @@
</ControlTemplate>
</Setter>
<Style Selector="^:last /template/ Rectangle.end">
<Setter Property="Rectangle.Fill" Value="Transparent" />
<Setter Property="Fill" Value="Transparent" />
</Style>
<Style Selector="^:empty-icon /template/ Ellipse#PART_DefaultIcon">
<Setter Property="IsVisible" Value="True"/>

View File

@@ -5,7 +5,7 @@ namespace Ursa.Themes.Semi.Converters;
public class BooleansToOpacityConverter: IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is bool b)
{
@@ -14,7 +14,7 @@ public class BooleansToOpacityConverter: IValueConverter
return 1;
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}

View File

@@ -1,5 +1,4 @@
using System.Globalization;
using Avalonia;
using Avalonia.Data.Converters;
using Avalonia.Media;
@@ -7,7 +6,7 @@ namespace Ursa.Themes.Semi.Converters;
public class BrushToColorConverter: IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is ISolidColorBrush b)
{
@@ -16,7 +15,7 @@ public class BrushToColorConverter: IValueConverter
return Colors.Transparent;
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}

View File

@@ -8,8 +8,6 @@ public class ClockHandLengthConverter(double ratio) : IValueConverter
public static ClockHandLengthConverter Hour { get; } = new(1-0.618);
public static ClockHandLengthConverter Minute { get; } = new(0.618);
public static ClockHandLengthConverter Second { get; } = new(1);
private double _ratio = ratio;
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
@@ -20,7 +18,7 @@ public class ClockHandLengthConverter(double ratio) : IValueConverter
return 0.0;
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}

View File

@@ -1,6 +1,5 @@
using System.Globalization;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Data.Converters;
using Avalonia.Media;
using Ursa.Controls;
@@ -55,7 +54,7 @@ public class TimelineItemTypeToIconForegroundConverter: AvaloniaObject, IMultiVa
}
public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
public object Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
{
if (values[0] is TimelineItemType type)
{

View File

@@ -20,10 +20,10 @@ public class SemiTheme: Styles
private static readonly ResourceDictionary _defaultResource = new zh_cn();
private readonly IServiceProvider? sp;
private readonly IServiceProvider? _sp;
public SemiTheme(IServiceProvider? provider = null)
{
sp = provider;
_sp = provider;
AvaloniaXamlLoader.Load(provider, this);
}

View File

@@ -61,7 +61,7 @@ public class Badge: HeaderedContentControl
static Badge()
{
HeaderProperty.Changed.AddClassHandler<Badge>((badge, args) => badge.UpdateBadgePosition());
HeaderProperty.Changed.AddClassHandler<Badge>((badge, _) => badge.UpdateBadgePosition());
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
@@ -86,7 +86,7 @@ public class Badge: HeaderedContentControl
{
var vertical = CornerPosition is CornerPosition.BottomLeft or CornerPosition.BottomRight ? 1 : -1;
var horizontal = CornerPosition is CornerPosition.TopRight or CornerPosition.BottomRight ? 1 : -1;
if (_badgeContainer is not null && base.Presenter?.Child is not null)
if (_badgeContainer is not null && Presenter?.Child is not null)
{
_badgeContainer.RenderTransform = new TransformGroup()
{

View File

@@ -3,9 +3,7 @@ using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Notifications;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Interactivity;
using Avalonia.Metadata;
using Irihi.Avalonia.Shared.Helpers;
namespace Ursa.Controls;
@@ -63,7 +61,7 @@ public class Banner: HeaderedContentControl
Button.ClickEvent.AddHandler(OnCloseClick, _closeButton);
}
private void OnCloseClick(object sender, RoutedEventArgs args)
private void OnCloseClick(object? sender, RoutedEventArgs args)
{
IsVisible = false;
}

View File

@@ -4,7 +4,6 @@ using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Templates;
using Avalonia.Input;
using Avalonia.LogicalTree;
namespace Ursa.Controls;

View File

@@ -1,10 +1,6 @@
using System.Net.Http.Headers;
using Avalonia;
using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Data;
using Avalonia.Media;
using Avalonia.Metadata;
using Irihi.Avalonia.Shared.Helpers;

View File

@@ -3,7 +3,6 @@ using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Layout;
using Ursa.Common;
namespace Ursa.Controls;

View File

@@ -156,7 +156,7 @@ public class Clock : TemplatedControl
private CancellationTokenSource _cts = new CancellationTokenSource();
private async void OnTimeChanged(AvaloniaPropertyChangedEventArgs<DateTime> args)
private void OnTimeChanged(AvaloniaPropertyChangedEventArgs<DateTime> args)
{
var oldSeconds = args.OldValue.Value.Second;
var time = args.NewValue.Value;
@@ -179,8 +179,14 @@ public class Clock : TemplatedControl
_cts.Cancel();
_cts.Dispose();
_cts = new CancellationTokenSource();
(_secondsAnimation.Children[0].Setters[0] as Setter).Value = oldSecondAngle;
(_secondsAnimation.Children[1].Setters[0] as Setter).Value = secondAngle;
if (_secondsAnimation.Children[0].Setters[0] is Setter start)
{
start.Value = oldSecondAngle;
}
if (_secondsAnimation.Children[1].Setters[0] is Setter end)
{
end.Value = secondAngle;
}
_secondsAnimation.RunAsync(this, _cts.Token);
}
}

View File

@@ -6,10 +6,8 @@ using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Data.Converters;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Irihi.Avalonia.Shared.Helpers;
using Irihi.Avalonia.Shared.Contracts;
@@ -145,7 +143,7 @@ public class MultiComboBox: SelectingItemsControl, IInnerContentControl
PseudoClasses.Set(PC_Empty, SelectedItems?.Count == 0);
}
private void OnBackgroundPointerPressed(object sender, PointerPressedEventArgs e)
private void OnBackgroundPointerPressed(object? sender, PointerPressedEventArgs e)
{
SetCurrentValue(IsDropDownOpenProperty, !IsDropDownOpen);
}

View File

@@ -1,5 +1,4 @@
using System.Windows.Input;
using Avalonia;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Mixins;
using Avalonia.Input;

View File

@@ -6,8 +6,6 @@ using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Media.TextFormatting;
using Irihi.Avalonia.Shared.Common;
using Irihi.Avalonia.Shared.Helpers;
@@ -16,7 +14,6 @@ namespace Ursa.Controls;
[TemplatePart(PartNames.PART_Header, typeof(Control))]
public class TreeComboBoxItem: HeaderedItemsControl, ISelectable
{
private Control? _header;
private TreeComboBox? _treeComboBox;
public TreeComboBox? Owner => _treeComboBox;
@@ -58,7 +55,7 @@ public class TreeComboBoxItem: HeaderedItemsControl, ISelectable
{
base.OnApplyTemplate(e);
DoubleTappedEvent.RemoveHandler(OnDoubleTapped, this);
_header = e.NameScope.Find<Control>(PartNames.PART_Header);
e.NameScope.Find<Control>(PartNames.PART_Header);
DoubleTappedEvent.AddHandler(OnDoubleTapped, RoutingStrategies.Tunnel, true, this);
}
@@ -77,7 +74,7 @@ public class TreeComboBoxItem: HeaderedItemsControl, ISelectable
}
}
private void OnDoubleTapped(object sender, TappedEventArgs e)
private void OnDoubleTapped(object? sender, TappedEventArgs e)
{
if (this.ItemCount <= 0) return;
this.SetCurrentValue(IsExpandedProperty, !IsExpanded);
@@ -86,8 +83,6 @@ public class TreeComboBoxItem: HeaderedItemsControl, ISelectable
protected override bool NeedsContainerOverride(object? item, int index, out object? recycleKey)
{
TreeViewItem t = new TreeViewItem();
ComboBox c = new ComboBox();
return EnsureParent().NeedsContainerInternal(item, index, out recycleKey);
}

View File

@@ -1,7 +1,6 @@
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using Avalonia;
using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
@@ -9,9 +8,9 @@ namespace Ursa.Controls;
public class ControlClassesInput: TemplatedControl
{
LinkedList<List<string>> _history = new();
LinkedList<List<string>> _undoHistory = new();
private bool _disableHistory = false;
private readonly LinkedList<List<string>> _history = [];
private readonly LinkedList<List<string>> _undoHistory = [];
private bool _disableHistory;
public int CountOfHistoricalRecord { get; set; } = 10;
@@ -34,12 +33,12 @@ public class ControlClassesInput: TemplatedControl
}
private ObservableCollection<string> _targetClasses;
private ObservableCollection<string>? _targetClasses;
internal static readonly DirectProperty<ControlClassesInput, ObservableCollection<string>> TargetClassesProperty = AvaloniaProperty.RegisterDirect<ControlClassesInput, ObservableCollection<string>>(
internal static readonly DirectProperty<ControlClassesInput, ObservableCollection<string>?> TargetClassesProperty = AvaloniaProperty.RegisterDirect<ControlClassesInput, ObservableCollection<string>?>(
nameof(TargetClasses), o => o.TargetClasses, (o, v) => o.TargetClasses = v);
public ObservableCollection<string> TargetClasses
public ObservableCollection<string>? TargetClasses
{
get => _targetClasses;
set => SetAndRaise(TargetClassesProperty, ref _targetClasses, value);
@@ -53,14 +52,13 @@ public class ControlClassesInput: TemplatedControl
static ControlClassesInput()
{
TargetClassesProperty.Changed.AddClassHandler<ControlClassesInput, ObservableCollection<string>>((o,e)=>o.OnClassesChanged(e));
TargetClassesProperty.Changed.AddClassHandler<ControlClassesInput, ObservableCollection<string>?>((o,e)=>o.OnClassesChanged(e));
SourceProperty.Changed.AddClassHandler<StyledElement, ControlClassesInput?>(HandleSourceChange);
}
public ControlClassesInput()
{
TargetClasses = new ObservableCollection<string>();
//TargetClasses.CollectionChanged += InccOnCollectionChanged;
}
private List<StyledElement> _targets = new();
@@ -83,7 +81,6 @@ public class ControlClassesInput: TemplatedControl
if (newValue is null)
{
SaveHistory(new List<string>(), true);
return;
}
else
{
@@ -93,11 +90,10 @@ public class ControlClassesInput: TemplatedControl
{
incc.CollectionChanged+=InccOnCollectionChanged;
}
return;
}
}
private void InccOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
private void InccOnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
if(_disableHistory) return;
SaveHistory(TargetClasses?.ToList() ?? new List<string>(), true);
@@ -123,7 +119,7 @@ public class ControlClassesInput: TemplatedControl
}
else
{
strings = _history.Last.Value;
strings = _history.Last?.Value ?? [];
}
if (!fromInput)
@@ -143,13 +139,14 @@ public class ControlClassesInput: TemplatedControl
public void UnDo()
{
var node = _history.Last;
if (node is null) return;
_history.RemoveLast();
_undoHistory.AddFirst(node);
_undoHistory.AddFirst(node.Value);
_disableHistory = true;
TargetClasses.Clear();
foreach (var value in _history.Last.Value)
TargetClasses?.Clear();
foreach (var value in node.Value)
{
TargetClasses.Add(value);
TargetClasses?.Add(value);
}
_disableHistory = false;
SetClassesToTarget(false);
@@ -158,13 +155,14 @@ public class ControlClassesInput: TemplatedControl
public void Redo()
{
var node = _undoHistory.First;
if (node is null) return;
_undoHistory.RemoveFirst();
_history.AddLast(node);
_disableHistory = true;
TargetClasses.Clear();
foreach (var value in _history.Last.Value)
TargetClasses?.Clear();
foreach (var value in node.Value)
{
TargetClasses.Add(value);
TargetClasses?.Add(value);
}
_disableHistory = false;
SetClassesToTarget(false);
@@ -172,6 +170,6 @@ public class ControlClassesInput: TemplatedControl
public void Clear()
{
SaveHistory(new List<string>(), false);
SaveHistory([], false);
}
}

View File

@@ -1,7 +1,6 @@
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Mixins;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Irihi.Avalonia.Shared.Common;

View File

@@ -1,6 +1,5 @@
using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
@@ -167,7 +166,7 @@ public class CalendarView : TemplatedControl
UpdateYearButtons();
}
private void OnFastNext(object sender, RoutedEventArgs e)
private void OnFastNext(object? sender, RoutedEventArgs e)
{
if (Mode == CalendarViewMode.Month)
{
@@ -176,7 +175,7 @@ public class CalendarView : TemplatedControl
}
}
private void OnNext(object sender, RoutedEventArgs e)
private void OnNext(object? sender, RoutedEventArgs e)
{
if (Mode == CalendarViewMode.Month)
{
@@ -200,7 +199,7 @@ public class CalendarView : TemplatedControl
}
}
private void OnPrevious(object sender, RoutedEventArgs e)
private void OnPrevious(object? sender, RoutedEventArgs e)
{
if (Mode == CalendarViewMode.Month)
{
@@ -224,7 +223,7 @@ public class CalendarView : TemplatedControl
}
}
private void OnFastPrevious(object sender, RoutedEventArgs e)
private void OnFastPrevious(object? sender, RoutedEventArgs e)
{
if (Mode == CalendarViewMode.Month)
{
@@ -238,7 +237,7 @@ public class CalendarView : TemplatedControl
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnHeaderButtonClick(object sender, RoutedEventArgs e)
private void OnHeaderButtonClick(object? sender, RoutedEventArgs e)
{
// Header button should be hidden in Month mode.
if (Mode == CalendarViewMode.Month) return;
@@ -261,10 +260,7 @@ public class CalendarView : TemplatedControl
ContextDate = ContextDate.With(startYear: range.start, endYear: range.end);
_dateContextSyncing = false;
UpdateYearButtons();
return;
}
if (Mode == CalendarViewMode.Century) return;
}
/// <summary>
@@ -319,7 +315,7 @@ public class CalendarView : TemplatedControl
if (_monthGrid is null || Mode != CalendarViewMode.Month) return;
var children = _monthGrid.Children;
var info = DateTimeHelper.GetCurrentDateTimeFormatInfo();
var date = new DateTime(ContextDate.Year ?? ContextDate.StartYear.Value, ContextDate.Month.Value, 1);
var date = new DateTime(ContextDate.Year ?? ContextDate.StartYear!.Value, ContextDate.Month!.Value, 1);
var dayBefore = PreviousMonthDays(date);
var dateToSet = date.GetFirstDayOfMonth().AddDays(-dayBefore);
for (var i = 7; i < children.Count; i++)
@@ -412,12 +408,12 @@ public class CalendarView : TemplatedControl
return i == 0 ? DateTimeHelper.NumberOfDaysPerWeek : i;
}
private void OnCellDatePreviewed(object sender, CalendarDayButtonEventArgs e)
private void OnCellDatePreviewed(object? sender, CalendarDayButtonEventArgs e)
{
DatePreviewed?.Invoke(this, e);
}
private void OnCellDateSelected(object sender, CalendarDayButtonEventArgs e)
private void OnCellDateSelected(object? sender, CalendarDayButtonEventArgs e)
{
if (e.Date.HasValue && e.Date.Value.Month != ContextDate.Month)
{
@@ -432,7 +428,7 @@ public class CalendarView : TemplatedControl
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnHeaderMonthButtonClick(object sender, RoutedEventArgs e)
private void OnHeaderMonthButtonClick(object? sender, RoutedEventArgs e)
{
SetCurrentValue(ModeProperty, CalendarViewMode.Year);
UpdateYearButtons();
@@ -443,7 +439,7 @@ public class CalendarView : TemplatedControl
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnHeaderYearButtonClick(object sender, RoutedEventArgs e)
private void OnHeaderYearButtonClick(object? sender, RoutedEventArgs e)
{
if (_yearGrid is null) return;
SetCurrentValue(ModeProperty, CalendarViewMode.Decade);
@@ -464,10 +460,9 @@ public class CalendarView : TemplatedControl
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnYearItemSelected(object sender, CalendarYearButtonEventArgs e)
private void OnYearItemSelected(object? sender, CalendarYearButtonEventArgs e)
{
if (_yearGrid is null) return;
var buttons = _yearGrid.Children.OfType<CalendarYearButton>().ToList();
if (Mode == CalendarViewMode.Century)
{
Mode = CalendarViewMode.Decade;
@@ -481,7 +476,7 @@ public class CalendarView : TemplatedControl
else if (Mode == CalendarViewMode.Year)
{
Mode = CalendarViewMode.Month;
ContextDate = ContextDate.With(null, e.Context.Month, null, null);
ContextDate = ContextDate.With(null, e.Context.Month);
UpdateDayButtons();
}
else if (Mode == CalendarViewMode.Month)
@@ -600,7 +595,7 @@ public class CalendarView : TemplatedControl
DatePreviewed?.Invoke(this, new CalendarDayButtonEventArgs(null));
}
private bool _dateContextSyncing = false;
private bool _dateContextSyncing;
/// <summary>
/// Used for syncing the context date for DateRangePicker. mark a flag to avoid infinitely loop.
/// </summary>

View File

@@ -1,4 +1,3 @@
using System.Diagnostics;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Mixins;

View File

@@ -23,7 +23,6 @@ public class DatePicker: DatePickerBase, IClearControl
public const string PART_TextBox = "PART_TextBox";
public const string PART_Calendar = "PART_Calendar";
private Button? _button;
private Popup? _popup;
private TextBox? _textBox;
private CalendarView? _calendar;
@@ -79,7 +78,7 @@ public class DatePicker: DatePickerBase, IClearControl
}
_button = e.NameScope.Find<Button>(PART_Button);
_popup = e.NameScope.Find<Popup>(PART_Popup);
e.NameScope.Find<Popup>(PART_Popup);
_textBox = e.NameScope.Find<TextBox>(PART_TextBox);
_calendar = e.NameScope.Find<CalendarView>(PART_Calendar);
@@ -94,19 +93,19 @@ public class DatePicker: DatePickerBase, IClearControl
}
}
private void OnDateSelected(object sender, CalendarDayButtonEventArgs e)
private void OnDateSelected(object? sender, CalendarDayButtonEventArgs e)
{
SetCurrentValue(SelectedDateProperty, e.Date);
SetCurrentValue(IsDropdownOpenProperty, false);
}
private void OnButtonClick(object sender, RoutedEventArgs e)
private void OnButtonClick(object? sender, RoutedEventArgs e)
{
Focus(NavigationMethod.Pointer);
SetCurrentValue(IsDropdownOpenProperty, !IsDropdownOpen);
}
private void OnTextBoxPointerPressed(object sender, PointerPressedEventArgs e)
private void OnTextBoxPointerPressed(object? sender, PointerPressedEventArgs e)
{
if (_calendar is not null)
{
@@ -118,7 +117,7 @@ public class DatePicker: DatePickerBase, IClearControl
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void OnTextChanged(object sender, TextChangedEventArgs e)
private void OnTextChanged(object? sender, TextChangedEventArgs e)
{
SetSelectedDate(true);
}
@@ -146,7 +145,6 @@ public class DatePicker: DatePickerBase, IClearControl
SetCurrentValue(SelectedDateProperty, date);
if (_calendar is not null)
{
var d = SelectedDate ?? DateTime.Today;
_calendar.ContextDate = _calendar.ContextDate.With(year: date.Year, month: date.Month);
_calendar.UpdateDayButtons();
}
@@ -164,7 +162,7 @@ public class DatePicker: DatePickerBase, IClearControl
}
}
private void OnTextBoxGetFocus(object sender, GotFocusEventArgs e)
private void OnTextBoxGetFocus(object? sender, GotFocusEventArgs e)
{
if (_calendar is not null)
{

View File

@@ -43,7 +43,6 @@ public class DateRangePicker : DatePickerBase, IClearControl
private Button? _button;
private CalendarView? _endCalendar;
private TextBox? _endTextBox;
private Popup? _popup;
private DateTime? _previewEnd;
private DateTime? _previewStart;
@@ -140,7 +139,7 @@ public class DateRangePicker : DatePickerBase, IClearControl
}
_button = e.NameScope.Find<Button>(PART_Button);
_popup = e.NameScope.Find<Popup>(PART_Popup);
e.NameScope.Find<Popup>(PART_Popup);
_startCalendar = e.NameScope.Find<CalendarView>(PART_StartCalendar);
_endCalendar = e.NameScope.Find<CalendarView>(PART_EndCalendar);
_startTextBox = e.NameScope.Find<TextBox>(PART_StartTextBox);
@@ -168,28 +167,28 @@ public class DateRangePicker : DatePickerBase, IClearControl
}
}
private void OnTextBoxLostFocus(object sender, RoutedEventArgs e)
private void OnTextBoxLostFocus(object? sender, RoutedEventArgs e)
{
if (sender == _startTextBox)
if (Equals(sender, _startTextBox))
OnTextChangedInternal(_startTextBox, SelectedStartDateProperty);
else if (sender == _endTextBox) OnTextChangedInternal(_endTextBox, SelectedEndDateProperty);
else if (Equals(sender, _endTextBox)) OnTextChangedInternal(_endTextBox, SelectedEndDateProperty);
}
private void OnContextDateChanged(object sender, CalendarContext e)
private void OnContextDateChanged(object? sender, CalendarContext e)
{
if (sender == _startCalendar && _startCalendar?.Mode == CalendarViewMode.Month)
if (Equals(sender, _startCalendar) && _startCalendar?.Mode == CalendarViewMode.Month)
{
var needsUpdate = EnableMonthSync || _startCalendar?.ContextDate.CompareTo(_endCalendar?.ContextDate) >= 0;
if (needsUpdate) _endCalendar?.SyncContextDate(_startCalendar?.ContextDate.NextMonth());
}
else if (sender == _endCalendar && _endCalendar?.Mode == CalendarViewMode.Month)
else if (Equals(sender, _endCalendar) && _endCalendar?.Mode == CalendarViewMode.Month)
{
var needsUpdate = EnableMonthSync || _endCalendar?.ContextDate.CompareTo(_startCalendar?.ContextDate) <= 0;
if (needsUpdate) _startCalendar?.SyncContextDate(_endCalendar?.ContextDate.PreviousMonth());
}
}
private void OnDatePreviewed(object sender, CalendarDayButtonEventArgs e)
private void OnDatePreviewed(object? sender, CalendarDayButtonEventArgs e)
{
if (_start == true)
{
@@ -205,7 +204,7 @@ public class DateRangePicker : DatePickerBase, IClearControl
}
}
private void OnDateSelected(object sender, CalendarDayButtonEventArgs e)
private void OnDateSelected(object? sender, CalendarDayButtonEventArgs e)
{
if (_start == true)
{
@@ -241,16 +240,16 @@ public class DateRangePicker : DatePickerBase, IClearControl
}
}
private void OnButtonClick(object sender, RoutedEventArgs e)
private void OnButtonClick(object? sender, RoutedEventArgs e)
{
Focus(NavigationMethod.Pointer);
SetCurrentValue(IsDropdownOpenProperty, !IsDropdownOpen);
_start = true;
}
private void OnTextBoxPointerPressed(object sender, PointerPressedEventArgs e)
private void OnTextBoxPointerPressed(object? sender, PointerPressedEventArgs e)
{
if (sender == _startTextBox)
if (Equals(sender, _startTextBox))
{
_start = true;
if (_startCalendar is not null)
@@ -270,11 +269,11 @@ public class DateRangePicker : DatePickerBase, IClearControl
date2 = date2.Value.AddMonths(1);
}
_endCalendar.ContextDate = new CalendarContext(date2?.Year, date2?.Month);
_endCalendar.ContextDate = new CalendarContext(date2.Value.Year, date2.Value.Month);
_endCalendar.UpdateDayButtons();
}
}
else if (sender == _endTextBox)
else if (Equals(sender, _endTextBox))
{
_start = false;
if (_endCalendar is not null)
@@ -294,7 +293,7 @@ public class DateRangePicker : DatePickerBase, IClearControl
date2 = date2.Value.AddMonths(-1);
}
_startCalendar.ContextDate = new CalendarContext(date2?.Year, date2?.Month);
_startCalendar.ContextDate = new CalendarContext(date2.Value.Year, date2.Value.Month);
_startCalendar.UpdateDayButtons();
}
}
@@ -302,24 +301,24 @@ public class DateRangePicker : DatePickerBase, IClearControl
SetCurrentValue(IsDropdownOpenProperty, true);
}
private void OnTextChanged(object sender, TextChangedEventArgs e)
private void OnTextChanged(object? sender, TextChangedEventArgs e)
{
if (sender == _startTextBox)
if (Equals(sender, _startTextBox))
OnTextChangedInternal(_startTextBox, SelectedStartDateProperty, true);
else if (sender == _endTextBox) OnTextChangedInternal(_endTextBox, SelectedEndDateProperty, true);
else if (Equals(sender, _endTextBox)) OnTextChangedInternal(_endTextBox, SelectedEndDateProperty, true);
}
private void OnTextChangedInternal(TextBox? textBox, AvaloniaProperty property, bool fromText = false)
{
if (string.IsNullOrEmpty(textBox?.Text))
if (textBox?.Text is null || string.IsNullOrEmpty(textBox.Text))
{
SetCurrentValue(property, null);
_startCalendar?.ClearSelection(true);
_startCalendar?.ClearSelection();
_endCalendar?.ClearSelection(end: true);
}
else if (DisplayFormat is null || DisplayFormat.Length == 0)
{
if (DateTime.TryParse(textBox?.Text, out var defaultTime))
if (DateTime.TryParse(textBox.Text, out var defaultTime))
{
SetCurrentValue(property, defaultTime);
_startCalendar?.MarkDates(defaultTime, defaultTime);
@@ -328,7 +327,7 @@ public class DateRangePicker : DatePickerBase, IClearControl
}
else
{
if (DateTime.TryParseExact(textBox?.Text, DisplayFormat, CultureInfo.CurrentUICulture, DateTimeStyles.None,
if (DateTime.TryParseExact(textBox.Text, DisplayFormat, CultureInfo.CurrentUICulture, DateTimeStyles.None,
out var date))
{
SetCurrentValue(property, date);
@@ -356,19 +355,18 @@ public class DateRangePicker : DatePickerBase, IClearControl
if (!fromText)
{
SetCurrentValue(property, null);
textBox?.SetValue(TextBox.TextProperty, null);
_startCalendar?.ClearSelection(true);
textBox.SetValue(TextBox.TextProperty, null);
_startCalendar?.ClearSelection();
_endCalendar?.ClearSelection(end: true);
}
}
}
}
private void OnTextBoxGetFocus(object sender, GotFocusEventArgs e)
private void OnTextBoxGetFocus(object? sender, GotFocusEventArgs e)
{
if (_startCalendar is not null && _startCalendar?.Mode == CalendarViewMode.Month)
{
var date = SelectedStartDate ?? DateTime.Today;
//_startCalendar.ContextDate = new CalendarContext(date.Year, date.Month);
//_startCalendar.UpdateDayButtons();
}

View File

@@ -10,7 +10,7 @@ internal static class DateTimeHelper
public static DateTimeFormatInfo GetCurrentDateTimeFormatInfo()
{
if (CultureInfo.CurrentCulture.Calendar is GregorianCalendar) return CultureInfo.CurrentCulture.DateTimeFormat;
System.Globalization.Calendar? calendar =
Calendar? calendar =
CultureInfo.CurrentCulture.OptionalCalendars.OfType<GregorianCalendar>().FirstOrDefault();
string cultureName = calendar is null ? CultureInfo.InvariantCulture.Name : CultureInfo.CurrentCulture.Name;
var dt = new CultureInfo(cultureName).DateTimeFormat;

View File

@@ -30,7 +30,6 @@ public class TimePicker : TimePickerBase, IClearControl
nameof(Watermark));
private Button? _button;
private Popup? _popup;
private TimePickerPresenter? _presenter;
private TextBox? _textBox;
@@ -42,10 +41,11 @@ public class TimePicker : TimePickerBase, IClearControl
DisplayFormatProperty.Changed.AddClassHandler<TimePicker, string?>((picker, args) => picker.OnDisplayFormatChanged(args));
}
private void OnDisplayFormatChanged(AvaloniaPropertyChangedEventArgs<string?> args)
private void OnDisplayFormatChanged(AvaloniaPropertyChangedEventArgs<string?> _)
{
if (_textBox is null) return;
var time = SelectedTime;
if (time is null) return;
var date = new DateTime( 1, 1, 1, time.Value.Hours, time.Value.Minutes, time.Value.Seconds);
var text = date.ToString(DisplayFormat);
_textBox.Text = text;
@@ -79,7 +79,7 @@ public class TimePicker : TimePickerBase, IClearControl
Button.ClickEvent.RemoveHandler(OnButtonClick, _button);
_textBox = e.NameScope.Find<TextBox>(PART_TextBox);
_popup = e.NameScope.Find<Popup>(PartNames.PART_Popup);
e.NameScope.Find<Popup>(PartNames.PART_Popup);
_presenter = e.NameScope.Find<TimePickerPresenter>(PART_Presenter);
_button = e.NameScope.Find<Button>(PART_Button);

View File

@@ -69,7 +69,7 @@ public class TimePickerPresenter : TemplatedControl
private DateTimePickerPanel? _secondSelector;
private Control? _secondSeparator;
private Control? _thirdSeparator;
internal TimeSpan _timeHolder;
internal TimeSpan TimeHolder;
private bool _updateFromTimeChange;
private bool _use12Clock;
@@ -172,7 +172,7 @@ public class TimePickerPresenter : TemplatedControl
}
catch
{
// ignored
}
}
@@ -224,11 +224,11 @@ public class TimePickerPresenter : TemplatedControl
UpdatePanelsFromSelectedTime(Time);
}
private void OnPanelSelectionChanged(object sender, System.EventArgs e)
private void OnPanelSelectionChanged(object? sender, System.EventArgs e)
{
if (_updateFromTimeChange) return;
if (!_use12Clock && sender == _ampmSelector) return;
var time = NeedsConfirmation ? _timeHolder : Time ?? DateTime.Now.TimeOfDay;
if (!_use12Clock && Equals(sender, _ampmSelector)) return;
var time = NeedsConfirmation ? TimeHolder : Time ?? DateTime.Now.TimeOfDay;
var hour = _hourSelector?.SelectedValue ?? time.Hours;
var minute = _minuteSelector?.SelectedValue ?? time.Minutes;
var second = _secondSelector?.SelectedValue ?? time.Seconds;
@@ -251,7 +251,7 @@ public class TimePickerPresenter : TemplatedControl
}
var newTime = new TimeSpan(hour, minute, second);
if (NeedsConfirmation)
_timeHolder = newTime;
TimeHolder = newTime;
else
SetCurrentValue(TimeProperty, newTime);
}
@@ -314,7 +314,7 @@ public class TimePickerPresenter : TemplatedControl
public void Confirm()
{
if (NeedsConfirmation) SetCurrentValue(TimeProperty, _timeHolder);
if (NeedsConfirmation) SetCurrentValue(TimeProperty, TimeHolder);
}
private void SetIfChanged(DateTimePickerPanel? panel, int index)

View File

@@ -45,7 +45,6 @@ public class TimeRangePicker : TimePickerBase, IClearControl
private Button? _button;
private TimePickerPresenter? _endPresenter;
private TextBox? _endTextBox;
private Popup? _popup;
private TimePickerPresenter? _startPresenter;
private TextBox? _startTextBox;
@@ -114,7 +113,7 @@ public class TimeRangePicker : TimePickerBase, IClearControl
PointerPressedEvent.RemoveHandler(OnTextBoxPointerPressed, _startTextBox, _endTextBox);
Button.ClickEvent.RemoveHandler(OnButtonClick, _button);
_popup = e.NameScope.Find<Popup>(PartNames.PART_Popup);
e.NameScope.Find<Popup>(PartNames.PART_Popup);
_startTextBox = e.NameScope.Find<TextBox>(PART_StartTextBox);
_endTextBox = e.NameScope.Find<TextBox>(PART_EndTextBox);
_startPresenter = e.NameScope.Find<TimePickerPresenter>(PART_StartPresenter);
@@ -127,18 +126,18 @@ public class TimeRangePicker : TimePickerBase, IClearControl
Button.ClickEvent.AddHandler(OnButtonClick, _button);
}
private void OnButtonClick(object sender, RoutedEventArgs e)
private void OnButtonClick(object? sender, RoutedEventArgs e)
{
Focus(NavigationMethod.Pointer);
SetCurrentValue(IsDropdownOpenProperty, !IsDropdownOpen);
}
private void OnTextBoxPointerPressed(object sender, PointerPressedEventArgs e)
private void OnTextBoxPointerPressed(object? sender, PointerPressedEventArgs e)
{
SetCurrentValue(IsDropdownOpenProperty, true);
}
private void OnTextBoxGetFocus(object sender, GotFocusEventArgs e)
private void OnTextBoxGetFocus(object? sender, GotFocusEventArgs e)
{
SetCurrentValue(IsDropdownOpenProperty, true);
}
@@ -161,7 +160,7 @@ public class TimeRangePicker : TimePickerBase, IClearControl
if (e.Key == Key.Tab)
{
if (e.Source == _endTextBox) SetCurrentValue(IsDropdownOpenProperty, false);
if (Equals(e.Source, _endTextBox)) SetCurrentValue(IsDropdownOpenProperty, false);
return;
}

View File

@@ -1,11 +1,5 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Layout;
using Avalonia.VisualTree;
namespace Ursa.Controls;

View File

@@ -1,15 +1,5 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Input.GestureRecognizers;
using Avalonia.Interactivity;
using Avalonia.Threading;
using Avalonia.Controls.Primitives;
using Irihi.Avalonia.Shared.Contracts;
using Ursa.Common;
using Ursa.Controls.OverlayShared;
using Ursa.EventArgs;
namespace Ursa.Controls;

View File

@@ -2,12 +2,9 @@ using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Irihi.Avalonia.Shared.Contracts;
using Irihi.Avalonia.Shared.Helpers;
using Ursa.Common;
using Ursa.EventArgs;
namespace Ursa.Controls;
@@ -95,7 +92,7 @@ public class DefaultDialogControl: DialogControlBase
}
}
private void DefaultButtonsClose(object sender, RoutedEventArgs args)
private void DefaultButtonsClose(object? sender, RoutedEventArgs args)
{
if (sender is Button button)
{

View File

@@ -5,7 +5,6 @@ using Avalonia.Controls.Primitives;
using Avalonia.Interactivity;
using Irihi.Avalonia.Shared.Contracts;
using Irihi.Avalonia.Shared.Helpers;
using Ursa.Common;
namespace Ursa.Controls;
@@ -57,27 +56,26 @@ public class DefaultDialogWindow: DialogWindow
SetButtonVisibility();
}
private void OnDefaultClose(object sender, RoutedEventArgs e)
private void OnDefaultClose(object? sender, RoutedEventArgs e)
{
if (sender == _yesButton)
if (Equals(sender, _yesButton))
{
Close(DialogResult.Yes);
return;
}
if(sender == _noButton)
if(Equals(sender, _noButton))
{
Close(DialogResult.No);
return;
}
if(sender == _okButton)
if(Equals(sender, _okButton))
{
Close(DialogResult.OK);
return;
}
if(sender == _cancelButton)
if(Equals(sender, _cancelButton))
{
Close(DialogResult.Cancel);
return;
}
}
@@ -125,7 +123,7 @@ public class DefaultDialogWindow: DialogWindow
if (button is not null) button.IsVisible = visible;
}
protected internal override void OnCloseButtonClicked(object sender, RoutedEventArgs args)
protected override void OnCloseButtonClicked(object? sender, RoutedEventArgs args)
{
if (DataContext is IDialogContext context)
{

View File

@@ -6,9 +6,7 @@ using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Irihi.Avalonia.Shared.Helpers;
using Ursa.Common;
using Ursa.Controls.OverlayShared;
using Ursa.EventArgs;
namespace Ursa.Controls;
@@ -190,7 +188,7 @@ public abstract class DialogControlBase : OverlayFeedbackElement
e.Source = this;
}
private void OnCloseButtonClick(object sender, RoutedEventArgs args) => Close();
private void OnCloseButtonClick(object? sender, RoutedEventArgs args) => Close();
internal void SetAsModal(bool modal)
{

View File

@@ -6,7 +6,6 @@ using Avalonia.Input;
using Avalonia.Interactivity;
using Irihi.Avalonia.Shared.Contracts;
using Irihi.Avalonia.Shared.Helpers;
using Ursa.Common;
namespace Ursa.Controls;
@@ -59,7 +58,7 @@ public class DialogWindow: Window
Close(args);
}
protected internal virtual void OnCloseButtonClicked(object sender, RoutedEventArgs args)
protected virtual void OnCloseButtonClicked(object? sender, RoutedEventArgs args)
{
if (DataContext is IDialogContext context)
{
@@ -71,7 +70,7 @@ public class DialogWindow: Window
}
}
private void OnTitlePointerPressed(object sender, PointerPressedEventArgs e)
private void OnTitlePointerPressed(object? sender, PointerPressedEventArgs e)
{
this.BeginMoveDrag(e);
}

View File

@@ -1,7 +1,6 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Layout;
using Ursa.Common;
namespace Ursa.Controls;

View File

@@ -1,5 +1,4 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Metadata;

View File

@@ -5,7 +5,6 @@ using Avalonia.Controls.Primitives;
using Avalonia.Interactivity;
using Irihi.Avalonia.Shared.Contracts;
using Irihi.Avalonia.Shared.Helpers;
using Ursa.Common;
using Ursa.EventArgs;
namespace Ursa.Controls;

View File

@@ -3,7 +3,6 @@ using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Interactivity;
using Avalonia.Threading;
using Irihi.Avalonia.Shared.Contracts;
using Irihi.Avalonia.Shared.Helpers;
using Ursa.Common;
@@ -75,12 +74,12 @@ public abstract class DrawerControlBase: OverlayFeedbackElement
}
}
private void OnContextRequestClose(object sender, object? e)
private void OnContextRequestClose(object? sender, object? e)
{
RaiseEvent(new ResultEventArgs(ClosedEvent, e));
}
private void OnCloseButtonClick(object sender, RoutedEventArgs e) => Close();
private void OnCloseButtonClick(object? sender, RoutedEventArgs e) => Close();
public override void Close()
{

View File

@@ -66,9 +66,9 @@ public class DualBadge : HeaderedContentControl
static DualBadge()
{
IconProperty.Changed.AddClassHandler<DualBadge>((o, args) => o.OnIconChanged());
HeaderProperty.Changed.AddClassHandler<DualBadge>((o, args) => o.OnHeaderChanged());
ContentProperty.Changed.AddClassHandler<DualBadge>((o, args) => o.OnContentChanged());
IconProperty.Changed.AddClassHandler<DualBadge>((o, _) => o.OnIconChanged());
HeaderProperty.Changed.AddClassHandler<DualBadge>((o, _) => o.OnHeaderChanged());
ContentProperty.Changed.AddClassHandler<DualBadge>((o, _) => o.OnContentChanged());
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)

View File

@@ -2,6 +2,7 @@
using Avalonia.Controls;
using Avalonia.Layout;
using Avalonia.Utilities;
using Irihi.Avalonia.Shared.Helpers;
using static System.Math;
namespace Ursa.Controls;
@@ -132,7 +133,7 @@ public class ElasticWrapPanel : WrapPanel
sz.V = itemSetSize.V;
}
if (MathUtilities.GreaterThan(curLineSize.U + sz.U, uvConstraint.U))
if (MathHelpers.GreaterThan(curLineSize.U + sz.U, uvConstraint.U))
{
panelSize.U = Max(curLineSize.U, panelSize.U);
panelSize.V += curLineSize.V;
@@ -158,13 +159,13 @@ public class ElasticWrapPanel : WrapPanel
itemWidthSet ? itemWidth : child.DesiredSize.Width,
itemHeightSet ? itemHeight : child.DesiredSize.Height);
if (MathUtilities.GreaterThan(curLineSize.U + sz.U, uvConstraint.U)) // Need to switch to another line
if (MathHelpers.GreaterThan(curLineSize.U + sz.U, uvConstraint.U)) // Need to switch to another line
{
panelSize.U = Max(curLineSize.U, panelSize.U);
panelSize.V += curLineSize.V;
curLineSize = sz;
if (MathUtilities.GreaterThan(sz.U, uvConstraint.U)) // The element is wider than the constraint - give it a separate line
if (MathHelpers.GreaterThan(sz.U, uvConstraint.U)) // The element is wider than the constraint - give it a separate line
{
panelSize.U = Max(sz.U, panelSize.U);
panelSize.V += sz.V;
@@ -236,7 +237,7 @@ public class ElasticWrapPanel : WrapPanel
sz.V = itemSetSize.V;
}
if (MathUtilities.GreaterThan(curLineUIs.TotalU + sz.U, uvFinalSize.U))
if (MathHelpers.GreaterThan(curLineUIs.TotalU + sz.U, uvFinalSize.U))
{
if (curLineUIs.Count > 0)
{
@@ -260,7 +261,7 @@ public class ElasticWrapPanel : WrapPanel
itemWidthSet ? ItemWidth : child.DesiredSize.Width,
itemHeightSet ? ItemHeight : child.DesiredSize.Height);
if (MathUtilities.GreaterThan(curLineUIs.TotalU + sz.U, uvFinalSize.U)) // Need to switch to another line
if (MathHelpers.GreaterThan(curLineUIs.TotalU + sz.U, uvFinalSize.U)) // Need to switch to another line
{
if (curLineUIs.Count > 0)
{
@@ -269,7 +270,7 @@ public class ElasticWrapPanel : WrapPanel
curLineUIs = new UVCollection(Orientation, itemSetSize);
curLineUIs.Add(child, sz);
if (MathUtilities.GreaterThan(sz.U, uvFinalSize.U))
if (MathHelpers.GreaterThan(sz.U, uvFinalSize.U))
{
lineUVCollection.Add(curLineUIs);
curLineUIs = new UVCollection(Orientation, itemSetSize);

View File

@@ -1,6 +1,5 @@
using System.ComponentModel;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Data;
@@ -136,12 +135,12 @@ public class EnumSelector: TemplatedControl
if (EnumType is null) return new List<EnumItemTuple>();
var values = Enum.GetValues(EnumType);
List<EnumItemTuple> list = new();
var fields = EnumType.GetFields();
foreach (var value in values)
{
if (value.GetType() == EnumType)
{
var displayName = value.ToString();
if(displayName is null) continue;
var field = EnumType.GetField(displayName);
var description = field?.GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault();
if (description is not null)

View File

@@ -1,5 +1,4 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
namespace Ursa.Controls;

View File

@@ -1,7 +1,6 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Layout;
using Avalonia.Reactive;
using Avalonia.VisualTree;

View File

@@ -1,4 +1,3 @@
using System.Diagnostics;
using System.Net;
using Avalonia;
using Avalonia.Controls;
@@ -133,11 +132,7 @@ public class IPv4Box: TemplatedControl
protected override void OnKeyDown(KeyEventArgs e)
{
if (_currentActivePresenter is null)
{
_currentActivePresenter = _presenters[0];
}
_currentActivePresenter ??= _presenters[0];
var keymap = TopLevel.GetTopLevel(this)?.PlatformSettings?.HotkeyConfiguration;
bool Match(List<KeyGesture> gestures) => gestures.Any(g => g.Matches(e));
if (e.Key is Key.Enter or Key.Return)
@@ -150,8 +145,11 @@ public class IPv4Box: TemplatedControl
}
if (keymap is not null && Match(keymap.SelectAll))
{
_currentActivePresenter.SelectionStart = 0;
_currentActivePresenter.SelectionEnd = _currentActivePresenter.Text?.Length ?? 0;
if (_currentActivePresenter is not null)
{
_currentActivePresenter.SelectionStart = 0;
_currentActivePresenter.SelectionEnd = _currentActivePresenter.Text?.Length ?? 0;
}
e.Handled = true;
return;
}
@@ -217,8 +215,8 @@ public class IPv4Box: TemplatedControl
protected override void OnTextInput(TextInputEventArgs e)
{
if (e.Handled) return;
string? s = e.Text;
if (string.IsNullOrEmpty(s)) return;
var s = e.Text;
if (s is null || string.IsNullOrEmpty(s)) return;
if (s == ".")
{
_currentActivePresenter?.HideCaret();
@@ -231,10 +229,10 @@ public class IPv4Box: TemplatedControl
e.Handled = false;
return;
}
if (!char.IsNumber(s![0])) return;
if (!char.IsNumber(s[0])) return;
if (_currentActivePresenter != null)
{
int index = Math.Min(_currentActivePresenter.CaretIndex, _currentActivePresenter.Text.Length);
int index = Math.Min(_currentActivePresenter.CaretIndex, _currentActivePresenter.Text?.Length ?? 0);
string? oldText = _currentActivePresenter.Text;
if (oldText is null)
{
@@ -245,11 +243,11 @@ public class IPv4Box: TemplatedControl
{
_currentActivePresenter.DeleteSelection();
_currentActivePresenter.ClearSelection();
oldText = _currentActivePresenter.Text;
oldText = _currentActivePresenter.Text??string.Empty;
string newText = string.IsNullOrEmpty(oldText)
var newText = string.IsNullOrEmpty(oldText)
? s
: oldText?.Substring(0, index) + s + oldText?.Substring(Math.Min(index, oldText.Length));
: oldText.Substring(0, index) + s + oldText.Substring(Math.Min(index, oldText.Length));
if (newText.Length > 3)
{
newText = newText.Substring(0, 3);
@@ -444,7 +442,7 @@ public class IPv4Box: TemplatedControl
private void DeleteImplementation(TextPresenter? presenter)
{
if(presenter is null) return;
var oldText = presenter.Text;
var oldText = presenter.Text ?? string.Empty;
if (presenter.SelectionStart != presenter.SelectionEnd)
{
presenter.DeleteSelection();
@@ -463,7 +461,7 @@ public class IPv4Box: TemplatedControl
else
{
int index = presenter.CaretIndex;
string newText = oldText?.Substring(0, index - 1) + oldText?.Substring(Math.Min(index, oldText.Length));
string newText = oldText.Substring(0, index - 1) + oldText.Substring(Math.Min(index, oldText.Length));
presenter.MoveCaretHorizontal(LogicalDirection.Backward);
presenter.Text = newText;
}
@@ -529,7 +527,8 @@ public class IPv4Box: TemplatedControl
{
string s = string.Join(".", _firstText?.Text, _secondText?.Text, _thirdText?.Text, _fourthText?.Text);
IClipboard? clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
clipboard?.SetTextAsync(s);
if (clipboard is null) return;
await clipboard.SetTextAsync(s);
}
public static KeyGesture? CopyKeyGesture { get; } = Application.Current?.PlatformSettings?.HotkeyConfiguration.Copy.FirstOrDefault();
@@ -540,8 +539,8 @@ public class IPv4Box: TemplatedControl
{
IClipboard? clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
if (clipboard is null) return;
string s = await clipboard.GetTextAsync();
if (IPAddress.TryParse(s, out var address))
var s = await clipboard.GetTextAsync();
if (s is not null && IPAddress.TryParse(s, out var address))
{
IPAddress = address;
}

View File

@@ -1,5 +1,4 @@
using System.ComponentModel;
using Avalonia;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;

View File

@@ -5,7 +5,6 @@ using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.Media.Imaging;
namespace Ursa.Controls;
@@ -18,8 +17,7 @@ public class ImageViewer: TemplatedControl
public const string PART_Layer = "PART_Layer";
public const string PC_Moving = ":moving";
private Image? _image = null!;
private VisualLayerManager? _layer;
private Image? _image;
private Point? _lastClickPoint;
private Point? _lastLocation;
private bool _moving;
@@ -128,28 +126,14 @@ public class ImageViewer: TemplatedControl
{
if (_moving) return;
var newValue = args.GetNewValue<double>();
if (_lastLocation is not null)
{
_lastLocation = _lastLocation.Value.WithY(newValue);
}
else
{
_lastLocation = new Point(0, newValue);
}
_lastLocation = _lastLocation?.WithY(newValue) ?? new Point(0, newValue);
}
private void OnTranslateXChanged(AvaloniaPropertyChangedEventArgs args)
{
if (_moving) return;
var newValue = args.GetNewValue<double>();
if (_lastLocation is not null)
{
_lastLocation = _lastLocation.Value.WithX(newValue);
}
else
{
_lastLocation = new Point(newValue, 0);
}
_lastLocation = _lastLocation?.WithX(newValue) ?? new Point(newValue, 0);
}
private void OnOverlayerChanged(AvaloniaPropertyChangedEventArgs args)
@@ -181,26 +165,12 @@ public class ImageViewer: TemplatedControl
{
var stretch = args.GetNewValue<Stretch>();
Scale = GetScaleRatio(Width / _image!.Width, Height / _image!.Height, stretch);
if(_image is { })
{
_sourceMinScale = Math.Min(Width * MinScale / _image.Width, Height * MinScale / _image.Height);
}
else
{
_sourceMinScale = MinScale;
}
_sourceMinScale = _image is not null ? Math.Min(Width * MinScale / _image.Width, Height * MinScale / _image.Height) : MinScale;
}
private void OnMinScaleChanged(AvaloniaPropertyChangedEventArgs args)
private void OnMinScaleChanged(AvaloniaPropertyChangedEventArgs _)
{
if (_image is { })
{
_sourceMinScale = Math.Min(Width * MinScale / _image.Width, Height * MinScale / _image.Height);
}
else
{
_sourceMinScale = MinScale;
}
_sourceMinScale = _image is not null ? Math.Min(Width * MinScale / _image.Width, Height * MinScale / _image.Height) : MinScale;
if (_sourceMinScale > Scale)
{
@@ -224,7 +194,7 @@ public class ImageViewer: TemplatedControl
{
base.OnApplyTemplate(e);
_image = e.NameScope.Get<Image>(PART_Image);
_layer = e.NameScope.Get<VisualLayerManager>(PART_Layer);
e.NameScope.Get<VisualLayerManager>(PART_Layer);
if (Overlayer is { } c)
{
AdornerLayer.SetAdorner(this, c);
@@ -271,7 +241,7 @@ public class ImageViewer: TemplatedControl
protected override void OnPointerMoved(PointerEventArgs e)
{
base.OnPointerMoved(e);
if (e.Pointer.Captured == this && _lastClickPoint != null)
if (Equals(e.Pointer.Captured, this) && _lastClickPoint != null)
{
PseudoClasses.Set(PC_Moving, true);
Point p = e.GetPosition(this);

View File

@@ -1,6 +1,5 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Converters;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Input;

View File

@@ -2,12 +2,8 @@ using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.Styling;
using Irihi.Avalonia.Shared.Helpers;
using Ursa.Common;
namespace Ursa.Controls;
@@ -41,7 +37,7 @@ public class MessageBoxControl: DialogControlBase
}
public static readonly StyledProperty<MessageBoxButton> ButtonsProperty = AvaloniaProperty.Register<MessageBoxControl, MessageBoxButton>(
nameof(Buttons), MessageBoxButton.OK);
nameof(Buttons));
public MessageBoxButton Buttons
{
@@ -60,7 +56,7 @@ public class MessageBoxControl: DialogControlBase
static MessageBoxControl()
{
ButtonsProperty.Changed.AddClassHandler<MessageBoxControl>((o, e) => { o.SetButtonVisibility(); });
ButtonsProperty.Changed.AddClassHandler<MessageBoxControl>((o, _) => { o.SetButtonVisibility(); });
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
@@ -75,7 +71,7 @@ public class MessageBoxControl: DialogControlBase
SetButtonVisibility();
}
private void DefaultButtonsClose(object sender, RoutedEventArgs e)
private void DefaultButtonsClose(object? sender, RoutedEventArgs e)
{
if (sender is Button button)
{

View File

@@ -4,9 +4,7 @@ using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Platform;
using Irihi.Avalonia.Shared.Helpers;
using Ursa.Common;
namespace Ursa.Controls;
@@ -15,7 +13,7 @@ namespace Ursa.Controls;
[TemplatePart(PART_OKButton, typeof(Button))]
[TemplatePart(PART_CancelButton, typeof(Button))]
[TemplatePart(PART_YesButton, typeof(Button))]
public class MessageBoxWindow : Window
public class MessageBoxWindow(MessageBoxButton buttons) : Window
{
public const string PART_CloseButton = "PART_CloseButton";
public const string PART_YesButton = "PART_YesButton";
@@ -23,8 +21,6 @@ public class MessageBoxWindow : Window
public const string PART_OKButton = "PART_OKButton";
public const string PART_CancelButton = "PART_CancelButton";
private MessageBoxButton _buttonConfigs;
private Button? _closeButton;
private Button? _yesButton;
private Button? _noButton;
@@ -43,14 +39,8 @@ public class MessageBoxWindow : Window
set => SetValue(MessageIconProperty, value);
}
public MessageBoxWindow()
public MessageBoxWindow() : this(MessageBoxButton.OK)
{
_buttonConfigs = MessageBoxButton.OK;
}
public MessageBoxWindow(MessageBoxButton buttons)
{
_buttonConfigs = buttons;
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
@@ -70,7 +60,7 @@ public class MessageBoxWindow : Window
private void SetButtonVisibility()
{
switch (_buttonConfigs)
switch (buttons)
{
case MessageBoxButton.OK:
Button.IsVisibleProperty.SetValue(true, _okButton);
@@ -91,9 +81,9 @@ public class MessageBoxWindow : Window
}
}
private void OnCloseButtonClick(object sender, RoutedEventArgs e)
private void OnCloseButtonClick(object? sender, RoutedEventArgs e)
{
if (_buttonConfigs == MessageBoxButton.OK)
if (buttons == MessageBoxButton.OK)
{
Close(MessageBoxResult.OK);
}
@@ -101,21 +91,21 @@ public class MessageBoxWindow : Window
Close(MessageBoxResult.Cancel);
}
private void OnDefaultButtonClick(object sender, RoutedEventArgs e)
private void OnDefaultButtonClick(object? sender, RoutedEventArgs e)
{
if (sender == _okButton)
if (Equals(sender, _okButton))
{
Close(MessageBoxResult.OK);
}
else if (sender == _cancelButton)
else if (Equals(sender, _cancelButton))
{
Close(MessageBoxResult.Cancel);
}
else if (sender == _yesButton)
else if (Equals(sender, _yesButton))
{
Close(MessageBoxResult.Yes);
}
else if (sender == _noButton)
else if (Equals(sender, _noButton))
{
Close(MessageBoxResult.No);
}
@@ -124,7 +114,7 @@ public class MessageBoxWindow : Window
protected override void OnKeyUp(KeyEventArgs e)
{
base.OnKeyUp(e);
if (e.Key == Key.Escape && _buttonConfigs == MessageBoxButton.OK)
if (e.Key == Key.Escape && buttons == MessageBoxButton.OK)
{
Close(MessageBoxResult.OK);
}

View File

@@ -1,6 +1,4 @@
using System.Diagnostics;
using System.Reflection;
using Avalonia;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
@@ -245,7 +243,7 @@ public class NavMenu: ItemsControl
_updateFromUI = true;
foreach (var child in LogicalChildren)
{
if (child == parent)
if (Equals(child, parent))
{
continue;
}

View File

@@ -28,12 +28,11 @@ public class NavMenuItem: HeaderedItemsControl
public const string PC_Selector = ":selector";
private NavMenu? _rootMenu;
private Panel? _popupPanel;
private Popup? _popup;
private Panel? _overflowPanel;
private static readonly Point s_invalidPoint = new (double.NaN, double.NaN);
private Point _pointerDownPoint = s_invalidPoint;
private static readonly Point InvalidPoint = new (double.NaN, double.NaN);
private Point _pointerDownPoint = InvalidPoint;
public static readonly StyledProperty<object?> IconProperty = AvaloniaProperty.Register<NavMenuItem, object?>(
nameof(Icon));

View File

@@ -1,9 +1,6 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Irihi.Avalonia.Shared.Helpers;
namespace Ursa.Controls;
@@ -51,7 +48,7 @@ public class NumPad: TemplatedControl
}
}
private static void OnTargetGotFocus(object sender, GotFocusEventArgs e)
private static void OnTargetGotFocus(object? sender, GotFocusEventArgs e)
{
if (sender is not InputElement) return;
var existing = OverlayDialog.Recall<NumPad>(null);
@@ -87,7 +84,7 @@ public class NumPad: TemplatedControl
{
if (Target is null || o is not NumPadButton b) return;
var key = (b.NumMode ? b.NumKey : b.FunctionKey)?? Key.None;
if (KeyInputMapping.TryGetValue(key, out string s))
if (KeyInputMapping.TryGetValue(key, out var s))
{
Target.RaiseEvent(new TextInputEventArgs()
{

View File

@@ -8,11 +8,11 @@ namespace Ursa.Controls;
public abstract class NumberDisplayerBase : TemplatedControl
{
public static readonly DirectProperty<NumberDisplayerBase, string> InternalTextProperty = AvaloniaProperty.RegisterDirect<NumberDisplayerBase, string>(
public static readonly DirectProperty<NumberDisplayerBase, string?> InternalTextProperty = AvaloniaProperty.RegisterDirect<NumberDisplayerBase, string?>(
nameof(InternalText), o => o.InternalText, (o, v) => o.InternalText = v);
private string _internalText;
private string? _internalText;
public string InternalText
public string? InternalText
{
get => _internalText;
set => SetAndRaise(InternalTextProperty, ref _internalText, value);
@@ -51,7 +51,9 @@ public abstract class NumberDisplayer<T>: NumberDisplayerBase
private Animation? _animation;
private CancellationTokenSource _cts = new ();
#pragma warning disable AVP1002
public static readonly StyledProperty<T?> ValueProperty = AvaloniaProperty.Register<NumberDisplayer<T>, T?>(
#pragma warning restore AVP1002
nameof(Value), defaultBindingMode:BindingMode.TwoWay);
public T? Value
@@ -60,7 +62,9 @@ public abstract class NumberDisplayer<T>: NumberDisplayerBase
set => SetValue(ValueProperty, value);
}
#pragma warning disable AVP1002
private static readonly StyledProperty<T?> InternalValueProperty = AvaloniaProperty.Register<NumberDisplayer<T>, T?>(
#pragma warning restore AVP1002
nameof(InternalValue), defaultBindingMode:BindingMode.TwoWay);
private T? InternalValue

View File

@@ -1,8 +1,4 @@
using System.Globalization;
using Avalonia.Controls;
using Avalonia.Utilities;
namespace Ursa.Controls;
namespace Ursa.Controls;
public class NumericIntUpDown : NumericUpDownBase<int>
{

View File

@@ -1,6 +1,4 @@
using System.Diagnostics;
using System.Globalization;
using System.Net.Mime;
using System.Globalization;
using System.Windows.Input;
using Avalonia;
using Avalonia.Controls;
@@ -25,8 +23,8 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl
public const string PART_TextBox = "PART_TextBox";
public const string PART_DragPanel = "PART_DragPanel";
protected internal ButtonSpinner? _spinner;
protected internal TextBox? _textBox;
protected ButtonSpinner? _spinner;
protected TextBox? _textBox;
protected internal Panel? _dragPanel;
private Point? _point;
@@ -154,7 +152,7 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl
private void OnIsReadOnlyChanged(AvaloniaPropertyChangedEventArgs<bool> args)
{
ChangeToSetSpinDirection(args, false);
ChangeToSetSpinDirection(args);
TextBox.IsReadOnlyProperty.SetValue(args.NewValue.Value, _textBox);
}
@@ -229,7 +227,7 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl
}
}
private void OnDragPanelPointerPressed(object sender, PointerPressedEventArgs e)
private void OnDragPanelPointerPressed(object? sender, PointerPressedEventArgs e)
{
_point = e.GetPosition(this);
if (e.ClickCount == 2 && _dragPanel is not null && AllowDrag)
@@ -251,12 +249,12 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl
_textBox?.RaiseEvent(e);
}
private void OnDragPanelPointerReleased(object sender, PointerReleasedEventArgs e)
private void OnDragPanelPointerReleased(object? sender, PointerReleasedEventArgs e)
{
_point = null;
}
private void OnDragPanelPointerMoved(object sender, PointerEventArgs e)
private void OnDragPanelPointerMoved(object? sender, PointerEventArgs e)
{
if (!AllowDrag || IsReadOnly) return;
if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;
@@ -292,7 +290,7 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl
};
}
private void OnSpin(object sender, SpinEventArgs e)
private void OnSpin(object? sender, SpinEventArgs e)
{
if (AllowSpin && !IsReadOnly)
{
@@ -379,7 +377,9 @@ public abstract class NumericUpDownBase<T> : NumericUpDown where T : struct, ICo
return text;
}
#pragma warning disable AVP1002
public static readonly StyledProperty<T?> ValueProperty = AvaloniaProperty.Register<NumericUpDownBase<T>, T?>(
nameof(Value), defaultBindingMode: BindingMode.TwoWay, enableDataValidation: true);
public T? Value
@@ -484,7 +484,7 @@ public abstract class NumericUpDownBase<T> : NumericUpDown where T : struct, ICo
get => this.GetValue(CommandParameterProperty);
set => this.SetValue(CommandParameterProperty, value);
}
#pragma warning restore AVP1002
protected override void UpdateDataValidation(AvaloniaProperty property, BindingValueType state, Exception? error)
{
if (property == ValueProperty)
@@ -525,7 +525,7 @@ public abstract class NumericUpDownBase<T> : NumericUpDown where T : struct, ICo
ValueProperty.Changed.AddClassHandler<NumericUpDownBase<T>>((o, e) => o.OnValueChanged(e));
}
private void OnConstraintChanged(AvaloniaPropertyChangedEventArgs avaloniaPropertyChangedEventArgs)
private void OnConstraintChanged(AvaloniaPropertyChangedEventArgs _)
{
if (IsInitialized)
{
@@ -755,6 +755,6 @@ public abstract class NumericUpDownBase<T> : NumericUpDown where T : struct, ICo
public override void Clear()
{
SetCurrentValue(ValueProperty, EmptyInputValue);
SyncTextAndValue(false, forceTextUpdate: true);
SyncTextAndValue(forceTextUpdate: true);
}
}

View File

@@ -1,6 +1,6 @@
using Avalonia;
using Avalonia.Input;
using Avalonia.Utilities;
using Irihi.Avalonia.Shared.Helpers;
using Irihi.Avalonia.Shared.Shapes;
using Ursa.Controls.OverlayShared;
@@ -57,8 +57,8 @@ public partial class OverlayDialogHost
var p = e.GetPosition(this);
var left = p.X - _lastPoint.X;
var top = p.Y - _lastPoint.Y;
left = MathUtilities.Clamp(left, 0, Bounds.Width - item.Bounds.Width);
top = MathUtilities.Clamp(top, 0, Bounds.Height - item.Bounds.Height);
left = MathHelpers.SafeClamp(left, 0, Bounds.Width - item.Bounds.Width);
top = MathHelpers.SafeClamp(top, 0, Bounds.Height - item.Bounds.Height);
SetLeft(item, left);
SetTop(item, top);
}
@@ -109,7 +109,7 @@ public partial class OverlayDialogHost
ResetZIndices();
}
private async void OnDialogControlClosing(object sender, object? e)
private async void OnDialogControlClosing(object? sender, object? e)
{
if (sender is DialogControlBase control)
{
@@ -175,7 +175,7 @@ public partial class OverlayDialogHost
}
// Handle dialog layer change event
private void OnDialogLayerChanged(object sender, DialogLayerChangeEventArgs e)
private void OnDialogLayerChanged(object? sender, DialogLayerChangeEventArgs e)
{
if (sender is not DialogControlBase control)
return;
@@ -187,10 +187,10 @@ public partial class OverlayDialogHost
switch (e.ChangeType)
{
case DialogLayerChangeType.BringForward:
newIndex = MathUtilities.Clamp(index + 1, 0, _layers.Count);
newIndex = MathHelpers.SafeClamp(index + 1, 0, _layers.Count);
break;
case DialogLayerChangeType.SendBackward:
newIndex = MathUtilities.Clamp(index - 1, 0, _layers.Count);
newIndex = MathHelpers.SafeClamp(index - 1, 0, _layers.Count);
break;
case DialogLayerChangeType.BringToFront:
newIndex = _layers.Count;
@@ -257,19 +257,17 @@ public partial class OverlayDialogHost
private double GetLeftPosition(DialogControlBase control)
{
double left = 0;
double left;
double offset = Math.Max(0, control.HorizontalOffset ?? 0);
left = this.Bounds.Width - control.Bounds.Width;
if (control.HorizontalAnchor == HorizontalPosition.Center)
{
left *= 0.5;
(double min, double max) = MathUtilities.GetMinMax(0, Bounds.Width * 0.5);
left = MathUtilities.Clamp(left, min, max);
left = MathHelpers.SafeClamp(left, 0, Bounds.Width * 0.5);
}
else if (control.HorizontalAnchor == HorizontalPosition.Left)
{
(double min, double max) = MathUtilities.GetMinMax(0, offset);
left = MathUtilities.Clamp(left, min, max);
left = MathHelpers.SafeClamp(left, 0, offset);
}
else if (control.HorizontalAnchor == HorizontalPosition.Right)
{
@@ -277,7 +275,7 @@ public partial class OverlayDialogHost
leftOffset = Math.Max(0, leftOffset);
if(control.HorizontalOffset.HasValue)
{
left = MathUtilities.Clamp(left, 0, leftOffset);
left = MathHelpers.SafeClamp(left, 0, leftOffset);
}
}
return left;
@@ -285,23 +283,21 @@ public partial class OverlayDialogHost
private double GetTopPosition(DialogControlBase control)
{
double top = 0;
double offset = Math.Max(0, control.VerticalOffset ?? 0);
top = this.Bounds.Height - control.Bounds.Height;
var top = this.Bounds.Height - control.Bounds.Height;
if (control.VerticalAnchor == VerticalPosition.Center)
{
top *= 0.5;
(double min, double max) = MathUtilities.GetMinMax(0, Bounds.Height * 0.5);
top = MathUtilities.Clamp(top, min, max);
top = MathHelpers.SafeClamp(top, 0, Bounds.Height * 0.5);
}
else if (control.VerticalAnchor == VerticalPosition.Top)
{
top = MathUtilities.Clamp(top, 0, offset);
top = MathHelpers.SafeClamp(top, 0, offset);
}
else if (control.VerticalAnchor == VerticalPosition.Bottom)
{
var topOffset = Math.Max(0, Bounds.Height - control.Bounds.Height - offset);
top = MathUtilities.Clamp(top, 0, topOffset);
top = MathHelpers.SafeClamp(top, 0, topOffset);
}
return top;
}

View File

@@ -27,7 +27,7 @@ public partial class OverlayDialogHost
control.Arrange(new Rect(control.DesiredSize));
SetDrawerPosition(control);
control.AddHandler(OverlayFeedbackElement.ClosedEvent, OnDrawerControlClosing);
var animation = CreateAnimation(control.Bounds.Size, control.Position, true);
var animation = CreateAnimation(control.Bounds.Size, control.Position);
if (IsAnimationDisabled)
{
ResetDrawerPosition(control, this.Bounds.Size);
@@ -47,7 +47,7 @@ public partial class OverlayDialogHost
internal async void AddModalDrawer(DrawerControlBase control)
{
PureRectangle? mask = CreateOverlayMask(true, control.CanLightDismiss);
PureRectangle mask = CreateOverlayMask(true, control.CanLightDismiss);
_layers.Add(new DialogPair(mask, control));
this.Children.Add(mask);
this.Children.Add(control);
@@ -135,9 +135,11 @@ public partial class OverlayDialogHost
}
var targetProperty = position==Position.Left || position==Position.Right ? Canvas.LeftProperty : Canvas.TopProperty;
var animation = new Animation();
animation.Easing = new CubicEaseOut();
animation.FillMode = FillMode.Forward;
var animation = new Animation
{
Easing = new CubicEaseOut(),
FillMode = FillMode.Forward
};
var keyFrame1 = new KeyFrame(){ Cue = new Cue(0.0) };
keyFrame1.Setters.Add(new Setter()
{ Property = targetProperty, Value = source });
@@ -150,7 +152,7 @@ public partial class OverlayDialogHost
return animation;
}
private async void OnDrawerControlClosing(object sender, ResultEventArgs e)
private async void OnDrawerControlClosing(object? sender, ResultEventArgs e)
{
if (sender is DrawerControlBase control)
{

View File

@@ -19,21 +19,14 @@ public partial class OverlayDialogHost: Canvas
private readonly List<DialogPair> _layers = new List<DialogPair>(10);
private class DialogPair
private class DialogPair(PureRectangle? mask, OverlayFeedbackElement element, bool modal = true)
{
internal PureRectangle? Mask;
internal OverlayFeedbackElement Element;
internal bool Modal;
public DialogPair(PureRectangle? mask, OverlayFeedbackElement element, bool modal = true)
{
Mask = mask;
Element = element;
Modal = modal;
}
internal readonly PureRectangle? Mask = mask;
internal readonly OverlayFeedbackElement Element = element;
internal readonly bool Modal = modal;
}
private int _modalCount = 0;
private int _modalCount;
public static readonly AttachedProperty<bool> IsModalStatusScopeProperty =
AvaloniaProperty.RegisterAttached<OverlayDialogHost, Control, bool>("IsModalStatusScope");
@@ -73,8 +66,10 @@ public partial class OverlayDialogHost: Canvas
private static Animation CreateOpacityAnimation(bool appear)
{
var animation = new Animation();
animation.FillMode = FillMode.Forward;
var animation = new Animation
{
FillMode = FillMode.Forward
};
var keyFrame1 = new KeyFrame{ Cue = new Cue(0.0) };
keyFrame1.Setters.Add(new Setter() { Property = OpacityProperty, Value = appear ? 0.0 : 1.0 });
var keyFrame2 = new KeyFrame{ Cue = new Cue(1.0) };
@@ -122,7 +117,7 @@ public partial class OverlayDialogHost: Canvas
return rec;
}
private void ClickMaskToCloseDialog(object sender, PointerReleasedEventArgs e)
private void ClickMaskToCloseDialog(object? sender, PointerReleasedEventArgs e)
{
if (sender is PureRectangle border)
{
@@ -209,9 +204,8 @@ public partial class OverlayDialogHost: Canvas
internal IDataTemplate? GetDataTemplate(object? o)
{
if (o is null) return null;
IDataTemplate? result = null;
var templates = this.DialogDataTemplates;
result = templates.FirstOrDefault(a => a.Match(o));
var result = templates.FirstOrDefault(a => a.Match(o));
if (result != null) return result;
var keys = this.Resources.Keys;
foreach (var key in keys)

View File

@@ -24,7 +24,7 @@ public abstract class OverlayFeedbackElement: ContentControl
ClosedEvent.AddClassHandler<OverlayFeedbackElement>((o,e)=>o.OnClosed(e));
}
private void OnClosed(ResultEventArgs arg2)
private void OnClosed(ResultEventArgs _)
{
SetCurrentValue(IsClosedProperty,true);
}
@@ -50,12 +50,12 @@ public abstract class OverlayFeedbackElement: ContentControl
}
}
protected virtual void OnElementClosing(object sender, object? args)
protected virtual void OnElementClosing(object? sender, object? args)
{
RaiseEvent(new ResultEventArgs(ClosedEvent, args));
}
private void OnContextRequestClose(object sender, object? args)
private void OnContextRequestClose(object? sender, object? args)
{
RaiseEvent(new ResultEventArgs(ClosedEvent, args));
}
@@ -68,7 +68,7 @@ public abstract class OverlayFeedbackElement: ContentControl
Dispatcher.UIThread.Invoke(Close);
});
void OnCloseHandler(object sender, ResultEventArgs? args)
void OnCloseHandler(object? sender, ResultEventArgs? args)
{
if (args?.Result is T result)
{

View File

@@ -159,7 +159,7 @@ public class Pagination: TemplatedControl
pagination.UpdateButtonsByCurrentPage(args.NewValue.Value));
CurrentPageProperty.Changed.AddClassHandler<Pagination, int?>((pagination, args) =>
pagination.OnCurrentPageChanged(args));
TotalCountProperty.Changed.AddClassHandler<Pagination, int>((pagination, args) =>
TotalCountProperty.Changed.AddClassHandler<Pagination, int>((pagination, _) =>
pagination.UpdateButtonsByCurrentPage(pagination.CurrentPage));
}
@@ -199,7 +199,7 @@ public class Pagination: TemplatedControl
UpdateButtonsByCurrentPage(0);
}
private void OnQuickJumpInputKeyDown(object sender, KeyEventArgs e)
private void OnQuickJumpInputKeyDown(object? sender, KeyEventArgs e)
{
if (e.Key is Key.Enter or Key.Return)
{
@@ -207,7 +207,7 @@ public class Pagination: TemplatedControl
}
}
private void OnQuickJumpInputLostFocus(object sender, RoutedEventArgs e)
private void OnQuickJumpInputLostFocus(object? sender, RoutedEventArgs e)
{
SyncQuickJumperValue();
}
@@ -238,12 +238,12 @@ public class Pagination: TemplatedControl
{
var button = new PaginationButton() { Page = i, IsVisible = true };
_buttonPanel.Children.Add(button);
_buttons![i - 1] = button;
_buttons[i - 1] = button;
Button.ClickEvent.AddHandler(OnPageButtonClick, button);
}
}
private void OnPageButtonClick(object sender, RoutedEventArgs args)
private void OnPageButtonClick(object? sender, RoutedEventArgs args)
{
if (sender is PaginationButton pageButton)
{

View File

@@ -1,8 +1,6 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Styling;
namespace Ursa.Controls;

View File

@@ -1,4 +1,3 @@
using System.Runtime.CompilerServices;
using Avalonia;
using Avalonia.Collections;
using Avalonia.Controls;
@@ -8,7 +7,7 @@ using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Layout;
using Avalonia.Utilities;
using Irihi.Avalonia.Shared.Helpers;
namespace Ursa.Controls;
@@ -178,7 +177,7 @@ public class RangeSlider: TemplatedControl
private Thumb? _currentThumb;
private void PointerPress(object sender, PointerPressedEventArgs e)
private void PointerPress(object? sender, PointerPressedEventArgs e)
{
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
{
@@ -189,7 +188,7 @@ public class RangeSlider: TemplatedControl
}
}
private void PointerMove(object sender, PointerEventArgs args)
private void PointerMove(object? sender, PointerEventArgs args)
{
if (!IsEnabled)
{
@@ -202,7 +201,7 @@ public class RangeSlider: TemplatedControl
}
}
private void PointerRelease(object sender, PointerReleasedEventArgs e)
private void PointerRelease(object? sender, PointerReleasedEventArgs e)
{
_isDragging = false;
_currentThumb = null;
@@ -240,27 +239,27 @@ public class RangeSlider: TemplatedControl
{
foreach (var tick in ticks)
{
if (MathUtilities.AreClose(tick, value))
if (MathHelpers.AreClose(tick, value))
{
return value;
}
if (MathUtilities.LessThan(tick, value) && MathUtilities.GreaterThan(tick, previous))
if (MathHelpers.LessThan(tick, value) && MathHelpers.GreaterThan(tick, previous))
{
previous = tick;
}
else if (MathUtilities.GreaterThan(tick, value) && MathUtilities.LessThan(tick, next))
else if (MathHelpers.GreaterThan(tick, value) && MathHelpers.LessThan(tick, next))
{
next = tick;
}
}
}
else if (MathUtilities.GreaterThan(TickFrequency, 0.0))
else if (MathHelpers.GreaterThan(TickFrequency, 0.0))
{
previous = Minimum + Math.Round((value - Minimum) / TickFrequency) * TickFrequency;
next = Math.Min(Maximum, previous + TickFrequency);
}
value = MathUtilities.GreaterThanOrClose(value, (previous + next) * 0.5) ? next : previous;
value = MathHelpers.GreaterThanOrClose(value, (previous + next) * 0.5) ? next : previous;
}
return value;

View File

@@ -1,13 +1,11 @@
using System.Diagnostics;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Data;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Layout;
using Avalonia.Utilities;
using Irihi.Avalonia.Shared.Helpers;
namespace Ursa.Controls;
@@ -20,8 +18,6 @@ public class RangeTrack: Control
{
public const string PC_Horizontal = ":horizontal";
public const string PC_Vertical = ":vertical";
private double _density;
private Vector _lastDrag;
private const double Tolerance = 0.0001;
@@ -173,7 +169,7 @@ public class RangeTrack: Control
}
}
private void OnMinimumChanged(AvaloniaPropertyChangedEventArgs<double> avaloniaPropertyChangedEventArgs)
private void OnMinimumChanged(AvaloniaPropertyChangedEventArgs<double> _)
{
if (IsInitialized)
{
@@ -183,7 +179,7 @@ public class RangeTrack: Control
}
}
private void OnMaximumChanged(AvaloniaPropertyChangedEventArgs<double> avaloniaPropertyChangedEventArgs)
private void OnMaximumChanged(AvaloniaPropertyChangedEventArgs<double> _)
{
if (IsInitialized)
{
@@ -247,16 +243,16 @@ public class RangeTrack: Control
private static double CoerceLowerValue(AvaloniaObject sender, double value)
{
if (!ValidateDouble(value)) return sender.GetValue(LowerValueProperty);
value = MathUtilities.Clamp(value, sender.GetValue(MinimumProperty), sender.GetValue(MaximumProperty));
value = MathUtilities.Clamp(value, sender.GetValue(MinimumProperty), sender.GetValue(UpperValueProperty));
value = MathHelpers.SafeClamp(value, sender.GetValue(MinimumProperty), sender.GetValue(MaximumProperty));
value = MathHelpers.SafeClamp(value, sender.GetValue(MinimumProperty), sender.GetValue(UpperValueProperty));
return value;
}
private static double CoerceUpperValue(AvaloniaObject sender, double value)
{
if (!ValidateDouble(value)) return sender.GetValue(UpperValueProperty);
value = MathUtilities.Clamp(value, sender.GetValue(MinimumProperty), sender.GetValue(MaximumProperty));
value = MathUtilities.Clamp(value, sender.GetValue(LowerValueProperty), sender.GetValue(MaximumProperty));
value = MathHelpers.SafeClamp(value, sender.GetValue(MinimumProperty), sender.GetValue(MaximumProperty));
value = MathHelpers.SafeClamp(value, sender.GetValue(LowerValueProperty), sender.GetValue(MaximumProperty));
return value;
}
@@ -292,9 +288,8 @@ public class RangeTrack: Control
protected override Size ArrangeOverride(Size finalSize)
{
var vertical = Orientation == Orientation.Vertical;
double lowerButtonLength, innerButtonLength, upperButtonLength, lowerThumbLength, upperThumbLength;
ComputeSliderLengths(finalSize, vertical, out lowerButtonLength, out innerButtonLength, out upperButtonLength,
out lowerThumbLength, out upperThumbLength);
ComputeSliderLengths(finalSize, vertical, out var lowerButtonLength, out var innerButtonLength, out var upperButtonLength,
out var lowerThumbLength, out var upperThumbLength);
var offset = new Point();
var pieceSize = finalSize;
if (vertical)
@@ -433,8 +428,6 @@ public class RangeTrack: Control
lowerButtonLength = remainingLength * lowerOffset / range;
upperButtonLength = remainingLength * (range-upperOffset) / range;
innerButtonLength = remainingLength - lowerButtonLength - upperButtonLength;
_density = range / remainingLength;
}
private static void CoerceLength(ref double componentLength, double trackLength)

View File

@@ -29,7 +29,6 @@ public class ScrollTo
private static void OnButtonThemeChanged(Control arg1, AvaloniaPropertyChangedEventArgs<ControlTheme?> arg2)
{
var button = EnsureButtonInAdorner(arg1);
if (button is null) return;
button.SetCurrentValue(StyledElement.ThemeProperty, arg2.NewValue.Value);
}
@@ -37,11 +36,10 @@ public class ScrollTo
{
if (args.NewValue.Value is null) return;
var button = EnsureButtonInAdorner(control);
if (button is null) return;
button.SetCurrentValue(ScrollToButton.DirectionProperty, args.NewValue.Value);
}
private static ScrollToButton? EnsureButtonInAdorner(Control control)
private static ScrollToButton EnsureButtonInAdorner(Control control)
{
var adorner = AdornerLayer.GetAdorner(control);
if (adorner is not ScrollToButton button)

View File

@@ -1,12 +1,7 @@
using Avalonia;
using Avalonia.Animation;
using Avalonia.Animation.Easings;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Styling;
using Avalonia.VisualTree;
using Irihi.Avalonia.Shared.Helpers;
using Ursa.Common;
namespace Ursa.Controls;
@@ -64,7 +59,7 @@ public class ScrollToButton: Button
}
}
protected override async void OnClick()
protected override void OnClick()
{
if (_scroll is null) return;
var vector = Direction switch

View File

@@ -1,4 +1,3 @@
using System.Runtime.CompilerServices;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
@@ -37,7 +36,7 @@ public class SelectionList: SelectingItemsControl
SelectionModeProperty.OverrideMetadata<SelectionList>(
new StyledPropertyMetadata<SelectionMode>(
defaultValue: SelectionMode.Single,
coerce: (o, mode) => SelectionMode.Single)
coerce: (_, _) => SelectionMode.Single)
);
SelectedItemProperty.Changed.AddClassHandler<SelectionList, object?>((list, args) =>
list.OnSelectedItemChanged(args));

View File

@@ -14,9 +14,6 @@ public class SelectionListItem: ContentControl, ISelectable
PressedMixin.Attach<SelectionListItem>();
FocusableProperty.OverrideDefaultValue<SelectionListItem>(true);
}
private static readonly Point s_invalidPoint = new Point(double.NaN, double.NaN);
private Point _pointerDownPoint = s_invalidPoint;
public static readonly StyledProperty<bool> IsSelectedProperty = SelectingItemsControl.IsSelectedProperty.AddOwner<ListBoxItem>();
@@ -29,7 +26,7 @@ public class SelectionListItem: ContentControl, ISelectable
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
base.OnPointerPressed(e);
if (ItemsControl.ItemsControlFromItemContaner(this) is SelectionList list)
if (ItemsControl.ItemsControlFromItemContainer(this) is SelectionList list)
{
int index = list.IndexFromContainer(this);
list.SelectByIndex(index);

View File

@@ -1,8 +1,5 @@
using Avalonia;
using Avalonia.Controls;
using System;
using System.Collections.Generic;
using System.Text;
namespace Ursa.Controls
{

View File

@@ -91,8 +91,10 @@ public class TagInput : TemplatedControl
public TagInput()
{
_textBox = new TextBox();
_textBox[!AcceptsReturnProperty] = this.GetObservable(AcceptsReturnProperty).ToBinding();
_textBox = new TextBox
{
[!AcceptsReturnProperty] = this.GetObservable(AcceptsReturnProperty).ToBinding()
};
_textBox.AddHandler(KeyDownEvent, OnTextBoxKeyDown, RoutingStrategies.Tunnel);
_textBox.AddHandler(LostFocusEvent, OnTextBox_LostFocus, RoutingStrategies.Bubble);
Items = new AvaloniaList<object>
@@ -230,18 +232,20 @@ public class TagInput : TemplatedControl
}
if (newTags != null)
for (var i = 0; i < newTags.Count; i++)
Items.Insert(Items.Count - 1, newTags[i]);
foreach (var newTag in newTags)
Items.Insert(Items.Count - 1, newTag);
if (oldTags is INotifyCollectionChanged inccold) inccold.CollectionChanged -= OnCollectionChanged;
if (Tags is INotifyCollectionChanged incc) incc.CollectionChanged += OnCollectionChanged;
}
private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
private void OnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
var items = e.NewItems;
if (items is null) return;
var index = e.NewStartingIndex;
foreach (var item in items)
if (item is string s)
@@ -253,6 +257,7 @@ public class TagInput : TemplatedControl
else if (e.Action == NotifyCollectionChangedAction.Remove)
{
var items = e.OldItems;
if (items is null) return;
var index = e.OldStartingIndex;
foreach (var item in items)
if (item is string)
@@ -295,21 +300,21 @@ public class TagInput : TemplatedControl
{
if (!(text?.Length > 0)) return;
if (Tags.Count >= MaxCount) return;
string[] values;
string[] values = [];
if (!string.IsNullOrEmpty(Separator))
values = text.Split(new[] { Separator },
StringSplitOptions.RemoveEmptyEntries);
else
else if(_textBox.Text is not null)
values = new[] { _textBox.Text };
if (!AllowDuplicates)
values = values.Distinct().Except(Tags).ToArray();
for (var i = 0; i < values.Length; i++)
foreach (var value in values)
{
var index = Items.Count - 1;
// Items.Insert(index, values[i]);
Tags?.Insert(index, values[i]);
Tags?.Insert(index, value);
}
_textBox.Clear();

View File

@@ -1,6 +1,6 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Utilities;
using Irihi.Avalonia.Shared.Helpers;
namespace Ursa.Controls;
@@ -23,7 +23,7 @@ public class TagInputPanel: Panel
child.Measure(availableSize);
double deltaX = availableSize.Width - currentLineX;
// Width is enough to place next child
if (MathUtilities.GreaterThan(deltaX, child.DesiredSize.Width))
if (MathHelpers.GreaterThan(deltaX, child.DesiredSize.Width))
{
currentLineX+=child.DesiredSize.Width;
currentLineHeight = Math.Max(currentLineHeight, child.DesiredSize.Height);
@@ -69,7 +69,7 @@ public class TagInputPanel: Panel
var child = children[i];
double deltaX = finalSize.Width - currentLineX;
// Width is enough to place next child
if (MathUtilities.GreaterThan(deltaX, child.DesiredSize.Width))
if (MathHelpers.GreaterThan(deltaX, child.DesiredSize.Width))
{
child.Arrange(new Rect(currentLineX, totalHeight, child.DesiredSize.Width, Math.Max(child.DesiredSize.Height, currentLineHeight)));
currentLineX += child.DesiredSize.Width;

View File

@@ -3,8 +3,6 @@ using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.LogicalTree;
using Avalonia.Styling;
using Ursa.Common;
using System;
namespace Ursa.Controls;
@@ -61,7 +59,7 @@ public abstract class ThemeSelectorBase: TemplatedControl
}
}
private void OnScopeThemeChanged(object sender, System.EventArgs e)
private void OnScopeThemeChanged(object? sender, System.EventArgs e)
{
_syncFromScope = true;
if (this.TargetScope is { } target)
@@ -149,7 +147,6 @@ public abstract class ThemeSelectorBase: TemplatedControl
if (_application is not null)
{
_application.RequestedThemeVariant = newTheme;
return;
}
}
}

View File

@@ -5,7 +5,6 @@ using Avalonia.Controls.Primitives;
using Avalonia.Interactivity;
using Avalonia.Styling;
using Irihi.Avalonia.Shared.Helpers;
using Ursa.Common;
namespace Ursa.Controls;
@@ -40,7 +39,7 @@ public class ThemeToggleButton: ThemeSelectorBase
// ToggleButton.IsCheckedProperty.SetValue(_currentTheme == ThemeVariant.Light, _button);
}
private void OnButtonClicked(object sender, RoutedEventArgs e)
private void OnButtonClicked(object? sender, RoutedEventArgs e)
{
bool? currentState = _state;
if (IsThreeState)

View File

@@ -271,8 +271,8 @@ public class TimeBox : TemplatedControl
{
if (e.Handled) return;
string? s = e.Text;
if (string.IsNullOrEmpty(s)) return;
if (!char.IsNumber(s![0])) return;
if (s is null || string.IsNullOrEmpty(s)) return;
if (!char.IsNumber(s[0])) return;
if (_currentActiveSectionIndex is null) return;
int caretIndex = Math.Min(_presenters[_currentActiveSectionIndex.Value].CaretIndex
@@ -332,7 +332,11 @@ public class TimeBox : TemplatedControl
MoveCaret(_currentActiveSectionIndex.Value);
}
}
e.Pointer.Capture(_presenters[_currentActiveSectionIndex.Value]);
if (_currentActiveSectionIndex is not null)
{
e.Pointer.Capture(_presenters[_currentActiveSectionIndex.Value]);
}
e.Handled = true;
}
@@ -409,7 +413,7 @@ public class TimeBox : TemplatedControl
private void ParseTimeSpan(bool showLeadingZero, bool skipParseFromText = false)
{
string format = showLeadingZero ? "D2" : "";
string millisecondformat = showLeadingZero ? "D3" : "";
string millisecondFormat = showLeadingZero ? "D3" : "";
if (!skipParseFromText)
{
@@ -424,10 +428,10 @@ public class TimeBox : TemplatedControl
_hourText?.SetValue(TextPresenter.TextProperty, _values[0].ToString(format));
_minuteText?.SetValue(TextPresenter.TextProperty, _values[1].ToString(format));
_secondText?.SetValue(TextPresenter.TextProperty, _values[2].ToString(format));
_milliSecondText?.SetValue(TextPresenter.TextProperty, _values[3].ToString(millisecondformat));
_milliSecondText?.SetValue(TextPresenter.TextProperty, _values[3].ToString(millisecondFormat));
}
private void OnDragPanelPointerMoved(object sender, PointerEventArgs e)
private void OnDragPanelPointerMoved(object? sender, PointerEventArgs e)
{
if (!AllowDrag) return;
if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;
@@ -475,14 +479,14 @@ public class TimeBox : TemplatedControl
/// <summary>
/// Set dragPanel IsVisible to false if AllowDrag is true, and select all text in the section
/// </summary>
/// <param name="index">The index of section that will be enter</param>
/// <param name="index">The index of section that will be entered</param>
private void EnterSection(int index)
{
if (index < 0 || index > 3) return;
if (AllowDrag)
_dragPanels[index].IsVisible = false;
ShowCaretInteral(index);
ShowCaretInternal(index);
_presenters[index].SelectAll();
}
@@ -490,7 +494,7 @@ public class TimeBox : TemplatedControl
{
if (!_isShowedCaret[index])
{
ShowCaretInteral(index);
ShowCaretInternal(index);
}
_presenters[index].ClearSelection();
var caretPosition =
@@ -508,7 +512,7 @@ public class TimeBox : TemplatedControl
_presenters[index].ClearSelection();
if (_isShowedCaret[index])
{
HideCaretInteral(index);
HideCaretInternal(index);
}
if (AllowDrag)
@@ -595,7 +599,7 @@ public class TimeBox : TemplatedControl
private void DeleteImplementation(int index)
{
if (index < 0 || index > 3) return;
var oldText = _presenters[index].Text;
var oldText = _presenters[index].Text??string.Empty;
if (_presenters[index].SelectionStart != _presenters[index].SelectionEnd)
{
_presenters[index].DeleteSelection();
@@ -608,8 +612,8 @@ public class TimeBox : TemplatedControl
else
{
int caretIndex = _presenters[index].CaretIndex;
string newText = oldText?.Substring(0, caretIndex - 1) +
oldText?.Substring(Math.Min(caretIndex, oldText.Length));
string newText = oldText.Substring(0, caretIndex - 1) +
oldText.Substring(Math.Min(caretIndex, oldText.Length));
_presenters[index].MoveCaretHorizontal(LogicalDirection.Backward);
_presenters[index].Text = newText;
}
@@ -622,7 +626,7 @@ public class TimeBox : TemplatedControl
_values[index] += lowerCarry;
int carry = _values[index] >= 0 ? _values[index] / _limits[index] : -1 + (_values[index] / _limits[index]);
if (carry == 0) return true;
bool success = false;
bool success;
if (carry > 0)
{
success = HandlingCarry(index - 1, carry);
@@ -699,13 +703,13 @@ public class TimeBox : TemplatedControl
return milliSecond;
}
private void ShowCaretInteral(int index)
private void ShowCaretInternal(int index)
{
_presenters[index].ShowCaret();
_isShowedCaret[index] = true;
}
private void HideCaretInteral(int index)
private void HideCaretInternal(int index)
{
_presenters[index].HideCaret();
_isShowedCaret[index] = false;

View File

@@ -1,12 +1,8 @@
using System.Collections.Specialized;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Generators;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Data;
using Avalonia.Layout;
using Avalonia.Metadata;
namespace Ursa.Controls;
@@ -162,7 +158,10 @@ public class Timeline: ItemsControl
protected override Size ArrangeOverride(Size finalSize)
{
var panel = this.ItemsPanelRoot as TimelinePanel;
panel.Mode = this.Mode;
if (panel is not null)
{
panel.Mode = this.Mode;
}
SetItemMode();
return base.ArrangeOverride(finalSize);
}
@@ -195,17 +194,11 @@ public class Timeline: ItemsControl
}
else if (Mode == TimelineDisplayMode.Alternate)
{
bool left = false;
var left = false;
foreach (var item in items)
{
if (left)
{
SetIfUnset(item, TimelineItem.PositionProperty, TimelineItemPosition.Left);
}
else
{
SetIfUnset(item, TimelineItem.PositionProperty, TimelineItemPosition.Right);
}
SetIfUnset(item, TimelineItem.PositionProperty,
left ? TimelineItemPosition.Left : TimelineItemPosition.Right);
left = !left;
}
}

View File

@@ -6,7 +6,7 @@ namespace Ursa.Controls;
public class TimelineFormatConverter: IMultiValueConverter
{
public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
public object Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
{
if (values.Count> 1 && values[0] is DateTime date && values[1] is string s)
{

View File

@@ -4,8 +4,6 @@ using Avalonia.Controls.Metadata;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Data;
using Avalonia.Media;
namespace Ursa.Controls;

View File

@@ -1,6 +1,5 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Layout;
namespace Ursa.Controls;

View File

@@ -3,7 +3,6 @@ using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Irihi.Avalonia.Shared.Helpers;
using Irihi.Avalonia.Shared.Reactive;
namespace Ursa.Controls;
@@ -36,10 +35,10 @@ public class CaptionButtons: Avalonia.Controls.Chrome.CaptionButtons
_restoreButton = e.NameScope.Get<Button>(PART_RestoreButton);
_minimizeButton = e.NameScope.Get<Button>(PART_MinimizeButton);
_fullScreenButton = e.NameScope.Get<Button>(PART_FullScreenButton);
Button.ClickEvent.AddHandler((o, args) => OnClose(), _closeButton);
Button.ClickEvent.AddHandler((o, args) => OnRestore(), _restoreButton);
Button.ClickEvent.AddHandler((o, args) => OnMinimize(), _minimizeButton);
Button.ClickEvent.AddHandler((o, args) => OnToggleFullScreen(), _fullScreenButton);
Button.ClickEvent.AddHandler((_, _) => OnClose(), _closeButton);
Button.ClickEvent.AddHandler((_, _) => OnRestore(), _restoreButton);
Button.ClickEvent.AddHandler((_, _) => OnMinimize(), _minimizeButton);
Button.ClickEvent.AddHandler((_, _) => OnToggleFullScreen(), _fullScreenButton);
Window.WindowStateProperty.Changed.AddClassHandler<Window, WindowState>(WindowStateChanged);
if (this.HostWindow is not null && !HostWindow.CanResize)
@@ -75,7 +74,7 @@ public class CaptionButtons: Avalonia.Controls.Chrome.CaptionButtons
public override void Attach(Window hostWindow)
{
base.Attach(hostWindow);
_visibilityDisposable = HostWindow?.GetObservable(Window.WindowStateProperty).Subscribe((a) =>
_visibilityDisposable = HostWindow?.GetObservable(Window.WindowStateProperty).Subscribe((_) =>
{
UpdateVisibility();
});

View File

@@ -1,9 +1,7 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Platform;
using Irihi.Avalonia.Shared.Helpers;
namespace Ursa.Controls;
@@ -47,7 +45,7 @@ public class TitleBar: ContentControl
// this.UpdateSize(visualRoot);
}
private void OnPointerPressed(object sender, PointerPressedEventArgs e)
private void OnPointerPressed(object? sender, PointerPressedEventArgs e)
{
if(_visualRoot is not null
&& _visualRoot.WindowState == WindowState.FullScreen)
@@ -63,7 +61,7 @@ public class TitleBar: ContentControl
}
}
private void OnDoubleTapped(object sender, TappedEventArgs e)
private void OnDoubleTapped(object? sender, TappedEventArgs e)
{
if (_visualRoot is not null)
{

View File

@@ -5,8 +5,6 @@ using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Layout;
using Avalonia.Markup.Xaml.Templates;
using Irihi.Avalonia.Shared.Helpers;
namespace Ursa.Controls;

View File

@@ -4,7 +4,6 @@ using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Layout;
using Avalonia.LogicalTree;
using Irihi.Avalonia.Shared.Helpers;
namespace Ursa.Controls;

View File

@@ -1,14 +1,10 @@
using System.Windows.Input;
using Avalonia;
using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Utilities;
using Irihi.Avalonia.Shared.Helpers;
namespace Ursa.Controls;
@@ -18,7 +14,7 @@ public class VerificationCode: TemplatedControl
{
public const string PART_ItemsControl = "PART_ItemsControl";
private ItemsControl? _itemsControl;
private int _currentIndex = 0;
private int _currentIndex;
public static readonly StyledProperty<ICommand?> CompleteCommandProperty = AvaloniaProperty.Register<VerificationCode, ICommand?>(
nameof(CompleteCommand));
@@ -105,9 +101,9 @@ public class VerificationCode: TemplatedControl
PointerPressedEvent.AddHandler(OnControlPressed, RoutingStrategies.Tunnel, false, this);
}
private void OnControlPressed(object sender, PointerPressedEventArgs e)
private void OnControlPressed(object? sender, PointerPressedEventArgs e)
{
if (e.Source is Control t)
if (e.Source is Control)
{
/*
var item = t.FindLogicalAncestorOfType<VerificationCodeItem>();
@@ -117,7 +113,7 @@ public class VerificationCode: TemplatedControl
_currentIndex = _itemsControl?.IndexFromContainer(item) ?? 0;
}
*/
_currentIndex = MathUtilities.Clamp(_currentIndex, 0, Count - 1);
_currentIndex = MathHelpers.SafeClamp(_currentIndex, 0, Count - 1);
_itemsControl?.ContainerFromIndex(_currentIndex)?.Focus();
}
e.Handled = true;
@@ -162,7 +158,7 @@ public class VerificationCode: TemplatedControl
base.OnKeyDown(e);
if (e.Key == Key.Back && _currentIndex >= 0)
{
_currentIndex = MathUtilities.Clamp(_currentIndex, 0, Count - 1);
_currentIndex = MathHelpers.SafeClamp(_currentIndex, 0, Count - 1);
var presenter = _itemsControl?.ContainerFromIndex(_currentIndex) as VerificationCodeItem;
if (presenter is null) return;
Digits[_currentIndex] = string.Empty;

View File

@@ -1,9 +1,5 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Data;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Media;
namespace Ursa.Controls;

View File

@@ -1,4 +1,3 @@
using Avalonia.Collections;
using Avalonia.Interactivity;
namespace Ursa.Controls;

View File

@@ -17,7 +17,7 @@ public enum CornerRadiusPosition
Bottom = 12,
}
public class CornerRadiusIncludeConverter: IValueConverter
public class CornerRadiusIncludeConverter(CornerRadiusPosition position) : IValueConverter
{
public static CornerRadiusIncludeConverter TopLeft { get; } = new( CornerRadiusPosition.TopLeft );
public static CornerRadiusIncludeConverter TopRight { get; } = new( CornerRadiusPosition.TopRight );
@@ -27,27 +27,21 @@ public class CornerRadiusIncludeConverter: IValueConverter
public static CornerRadiusIncludeConverter Left { get; } = new( CornerRadiusPosition.Left );
public static CornerRadiusIncludeConverter Right { get; } = new( CornerRadiusPosition.Right );
public static CornerRadiusIncludeConverter Bottom { get; } = new( CornerRadiusPosition.Bottom );
private readonly CornerRadiusPosition _position;
public CornerRadiusIncludeConverter(CornerRadiusPosition position)
{
_position = position;
}
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is CornerRadius r)
{
double topLeft = _position.HasFlag(CornerRadiusPosition.TopLeft) ? r.TopLeft : 0;
double topRight = _position.HasFlag(CornerRadiusPosition.TopRight) ? r.TopRight : 0;
double bottomLeft = _position.HasFlag(CornerRadiusPosition.BottomLeft) ? r.BottomLeft : 0;
double bottomRight = _position.HasFlag(CornerRadiusPosition.BottomRight) ? r.BottomRight : 0;
double topLeft = position.HasFlag(CornerRadiusPosition.TopLeft) ? r.TopLeft : 0;
double topRight = position.HasFlag(CornerRadiusPosition.TopRight) ? r.TopRight : 0;
double bottomLeft = position.HasFlag(CornerRadiusPosition.BottomLeft) ? r.BottomLeft : 0;
double bottomRight = position.HasFlag(CornerRadiusPosition.BottomRight) ? r.BottomRight : 0;
return new CornerRadius(topLeft, topRight, bottomRight, bottomLeft);
}
return AvaloniaProperty.UnsetValue;
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
@@ -70,7 +64,7 @@ public class CornerRadiusExcludeConverter : IValueConverter
{
_position = position;
}
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is CornerRadius r)
{
@@ -83,7 +77,7 @@ public class CornerRadiusExcludeConverter : IValueConverter
return AvaloniaProperty.UnsetValue;
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}

View File

@@ -15,7 +15,7 @@ public class DivideByTwoConverter : IValueConverter
return value;
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}

View File

@@ -17,7 +17,7 @@ public enum ThicknessPosition
BottomRight = 12,
}
public class ThicknessExcludeConverter: IValueConverter
public class ThicknessExcludeConverter(ThicknessPosition position) : IValueConverter
{
public static ThicknessExcludeConverter Left { get; } = new( ThicknessPosition.Left );
public static ThicknessExcludeConverter Top { get; } = new( ThicknessPosition.Top );
@@ -28,33 +28,27 @@ public class ThicknessExcludeConverter: IValueConverter
public static ThicknessExcludeConverter BottomLeft { get; } = new( ThicknessPosition.BottomLeft );
public static ThicknessExcludeConverter BottomRight { get; } = new( ThicknessPosition.BottomRight );
private readonly ThicknessPosition _position;
public ThicknessExcludeConverter(ThicknessPosition position)
{
_position = position;
}
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is Thickness t)
{
double left = _position.HasFlag(ThicknessPosition.Left) ? 0d: t.Left;
double top = _position.HasFlag(ThicknessPosition.Top) ? 0d : t.Top;
double right = _position.HasFlag(ThicknessPosition.Right) ? 0d : t.Right;
double bottom = _position.HasFlag(ThicknessPosition.Bottom) ? 0d : t.Bottom;
double left = position.HasFlag(ThicknessPosition.Left) ? 0d: t.Left;
double top = position.HasFlag(ThicknessPosition.Top) ? 0d : t.Top;
double right = position.HasFlag(ThicknessPosition.Right) ? 0d : t.Right;
double bottom = position.HasFlag(ThicknessPosition.Bottom) ? 0d : t.Bottom;
return new Thickness(left, top, right, bottom);
}
return AvaloniaProperty.UnsetValue;
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class ThicknessIncludeConverter: IValueConverter
public class ThicknessIncludeConverter(ThicknessPosition position) : IValueConverter
{
public static ThicknessIncludeConverter Left { get; } = new( ThicknessPosition.Left );
public static ThicknessIncludeConverter Top { get; } = new( ThicknessPosition.Top );
@@ -65,26 +59,20 @@ public class ThicknessIncludeConverter: IValueConverter
public static ThicknessIncludeConverter BottomLeft { get; } = new( ThicknessPosition.BottomLeft );
public static ThicknessIncludeConverter BottomRight { get; } = new( ThicknessPosition.BottomRight );
private readonly ThicknessPosition _position;
public ThicknessIncludeConverter(ThicknessPosition position)
{
_position = position;
}
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is Thickness t)
{
var left = _position.HasFlag(ThicknessPosition.Left) ? t.Left : 0d;
var top = _position.HasFlag(ThicknessPosition.Top) ? t.Top : 0d;
var right = _position.HasFlag(ThicknessPosition.Right) ? t.Right : 0d;
var bottom = _position.HasFlag(ThicknessPosition.Bottom) ? t.Bottom : 0d;
var left = position.HasFlag(ThicknessPosition.Left) ? t.Left : 0d;
var top = position.HasFlag(ThicknessPosition.Top) ? t.Top : 0d;
var right = position.HasFlag(ThicknessPosition.Right) ? t.Right : 0d;
var bottom = position.HasFlag(ThicknessPosition.Bottom) ? t.Bottom : 0d;
return new Thickness(left, top, right, bottom);
}
return AvaloniaProperty.UnsetValue;
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}

View File

@@ -17,7 +17,7 @@
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)"/>
<PackageReference Include="Irihi.Avalonia.Shared" Version="0.1.8" />
<PackageReference Include="Irihi.Avalonia.Shared" Version="0.1.9" />
</ItemGroup>
<ItemGroup>

View File

@@ -1,6 +1,5 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Platform;
namespace Ursa.Controls;