feat: update dependency, replace obsoleted math utilities.

This commit is contained in:
rabbitism
2024-07-31 00:47:50 +08:00
parent 12e9e728d2
commit bdb59c0335
5 changed files with 18 additions and 17 deletions

View File

@@ -2,6 +2,7 @@
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Layout; using Avalonia.Layout;
using Avalonia.Utilities; using Avalonia.Utilities;
using Irihi.Avalonia.Shared.Helpers;
using static System.Math; using static System.Math;
namespace Ursa.Controls; namespace Ursa.Controls;
@@ -132,7 +133,7 @@ public class ElasticWrapPanel : WrapPanel
sz.V = itemSetSize.V; 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.U = Max(curLineSize.U, panelSize.U);
panelSize.V += curLineSize.V; panelSize.V += curLineSize.V;
@@ -158,13 +159,13 @@ public class ElasticWrapPanel : WrapPanel
itemWidthSet ? itemWidth : child.DesiredSize.Width, itemWidthSet ? itemWidth : child.DesiredSize.Width,
itemHeightSet ? itemHeight : child.DesiredSize.Height); 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.U = Max(curLineSize.U, panelSize.U);
panelSize.V += curLineSize.V; panelSize.V += curLineSize.V;
curLineSize = sz; 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.U = Max(sz.U, panelSize.U);
panelSize.V += sz.V; panelSize.V += sz.V;
@@ -236,7 +237,7 @@ public class ElasticWrapPanel : WrapPanel
sz.V = itemSetSize.V; 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) if (curLineUIs.Count > 0)
{ {
@@ -260,7 +261,7 @@ public class ElasticWrapPanel : WrapPanel
itemWidthSet ? ItemWidth : child.DesiredSize.Width, itemWidthSet ? ItemWidth : child.DesiredSize.Width,
itemHeightSet ? ItemHeight : child.DesiredSize.Height); 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) if (curLineUIs.Count > 0)
{ {
@@ -269,7 +270,7 @@ public class ElasticWrapPanel : WrapPanel
curLineUIs = new UVCollection(Orientation, itemSetSize); curLineUIs = new UVCollection(Orientation, itemSetSize);
curLineUIs.Add(child, sz); curLineUIs.Add(child, sz);
if (MathUtilities.GreaterThan(sz.U, uvFinalSize.U)) if (MathHelpers.GreaterThan(sz.U, uvFinalSize.U))
{ {
lineUVCollection.Add(curLineUIs); lineUVCollection.Add(curLineUIs);
curLineUIs = new UVCollection(Orientation, itemSetSize); curLineUIs = new UVCollection(Orientation, itemSetSize);

View File

@@ -540,7 +540,7 @@ public class IPv4Box: TemplatedControl
IClipboard? clipboard = TopLevel.GetTopLevel(this)?.Clipboard; IClipboard? clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
if (clipboard is null) return; if (clipboard is null) return;
var s = await clipboard.GetTextAsync(); var s = await clipboard.GetTextAsync();
if (IPAddress.TryParse(s, out var address)) if (s is not null && IPAddress.TryParse(s, out var address))
{ {
IPAddress = address; IPAddress = address;
} }

View File

@@ -7,7 +7,7 @@ using Avalonia.Controls.Primitives;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.Layout; using Avalonia.Layout;
using Avalonia.Utilities; using Irihi.Avalonia.Shared.Helpers;
namespace Ursa.Controls; namespace Ursa.Controls;
@@ -239,27 +239,27 @@ public class RangeSlider: TemplatedControl
{ {
foreach (var tick in ticks) foreach (var tick in ticks)
{ {
if (MathUtilities.AreClose(tick, value)) if (MathHelpers.AreClose(tick, value))
{ {
return value; return value;
} }
if (MathUtilities.LessThan(tick, value) && MathUtilities.GreaterThan(tick, previous)) if (MathHelpers.LessThan(tick, value) && MathHelpers.GreaterThan(tick, previous))
{ {
previous = tick; previous = tick;
} }
else if (MathUtilities.GreaterThan(tick, value) && MathUtilities.LessThan(tick, next)) else if (MathHelpers.GreaterThan(tick, value) && MathHelpers.LessThan(tick, next))
{ {
next = tick; next = tick;
} }
} }
} }
else if (MathUtilities.GreaterThan(TickFrequency, 0.0)) else if (MathHelpers.GreaterThan(TickFrequency, 0.0))
{ {
previous = Minimum + Math.Round((value - Minimum) / TickFrequency) * TickFrequency; previous = Minimum + Math.Round((value - Minimum) / TickFrequency) * TickFrequency;
next = Math.Min(Maximum, previous + 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; return value;

View File

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

View File

@@ -17,7 +17,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)"/> <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>
<ItemGroup> <ItemGroup>