feat: clean up warnings.

This commit is contained in:
rabbitism
2024-07-30 18:33:30 +08:00
parent e1f91f612b
commit 15fb5a2d1b
167 changed files with 473 additions and 825 deletions

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)
{