Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,14 @@
<!-- https://github.com/dotnet/msbuild/issues/2661 -->
<AddSyntheticProjectReferencesForSolutionDependencies>false</AddSyntheticProjectReferencesForSolutionDependencies>
<MSBuildEnableWorkloadResolver>false</MSBuildEnableWorkloadResolver>
</PropertyGroup>

<!-- 'NET6_0_OR_GREATER' equivalent -->
<PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '6.0'))">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors>nullable</WarningsAsErrors>
</PropertyGroup>

<!-- '!NET6_0_OR_GREATER' equivalent -->
<PropertyGroup Condition="!('$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '6.0')))">
<NoWarn>$(NoWarn);8604;8602</NoWarn>
<NoWarn>$(NoWarn);NU1903</NoWarn>
</PropertyGroup>

<PropertyGroup>
<AvaloniaVersion>11.0.0</AvaloniaVersion>
<AvaloniaSamplesVersion>11.3.6</AvaloniaSamplesVersion>
<AvaloniaVersion>12.0.1</AvaloniaVersion>
<AvaloniaSamplesVersion>12.0.*</AvaloniaSamplesVersion>
</PropertyGroup>


Expand Down
4 changes: 2 additions & 2 deletions build/SourceLink.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project>
<Project>
<PropertyGroup>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
Expand All @@ -19,7 +19,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.*" PrivateAssets="All"/>
</ItemGroup>

<!-- Workaround for https://github.com/dotnet/sdk/issues/11105 -->
Expand Down
2 changes: 1 addition & 1 deletion nukebuild/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nuke.Common" Version="10.0.0" />
<PackageReference Include="Nuke.Common" Version="10.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions samples/TreeDataGridDemo/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public override void Initialize()

public override void OnFrameworkInitializationCompleted()
{
this.AttachDeveloperTools();

if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow();
Expand Down
2 changes: 0 additions & 2 deletions samples/TreeDataGridDemo/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
Expand All @@ -20,7 +19,6 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();
this.AttachDevTools();
DataContext = new MainWindowViewModel();

_tabs = this.FindControl<TabControl>("tabs");
Expand Down
2 changes: 1 addition & 1 deletion samples/TreeDataGridDemo/TreeDataGridDemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaSamplesVersion)" />
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaSamplesVersion)" />
<PackageReference Include="Avalonia.Diagnostics" Version="$(AvaloniaSamplesVersion)" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="$(AvaloniaSamplesVersion)" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="$(AvaloniaSamplesVersion)" />
<PackageReference Include="AvaloniaUI.DiagnosticsSupport" Version="2.2.1" />
<PackageReference Include="Bogus" Version="35.6.5" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ private void OnColumnCountChanged(int newValue)
{
TextSearchValueSelector = value => value.Value,
IsReadOnlyGetter = value => value.ReadOnly,
CompareAscending = (a, b) => Comparer<string>.Default.Compare(a.Value, b.Value),
CompareDescending = (b, a) => Comparer<string>.Default.Compare(a.Value, b.Value),
CompareAscending = (a, b) => Comparer<string>.Default.Compare(a?.Value, b?.Value),
CompareDescending = (b, a) => Comparer<string>.Default.Compare(a?.Value, b?.Value),
}));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0;net10.0;net48</TargetFrameworks>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<IsPackable>True</IsPackable>
<RootNamespace>Avalonia.Controls</RootNamespace>
<PackageReadmeFile>readme.md</PackageReadmeFile>
Expand All @@ -19,23 +19,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="PolySharp" Version="1.15.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<InternalsVisibleTo Include="Avalonia.Controls.TreeDataGrid.Benchmark" />
<InternalsVisibleTo Include="Avalonia.Controls.TreeDataGrid.Tests" />
</ItemGroup>

<!-- '!NET6_0_OR_GREATER' equivalent -->
<ItemGroup Condition="!('$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '6.0')))">
<PackageReference Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
</ItemGroup>
<!-- 'NET6_0_OR_GREATER' equivalent -->
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '6.0'))">
<Compile Remove="StandardExtensions\**" />
<None Remove="StandardExtensions\**" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;

namespace Avalonia.Experimental.Data.Core;

/// <summary>
/// Provides math utilities not provided in System.Math.
/// </summary>
internal class MathWrapper
{
// smallest such that 1.0+DoubleEpsilon != 1.0
internal const double DoubleEpsilon = 2.2204460492503131e-016;

internal const float FloatEpsilon = 1.192092896e-07F;

/// <summary>
/// AreClose - Returns whether or not two doubles are "close". That is, whether or
/// not they are within epsilon of each other.
/// </summary>
/// <param name="value1"> The first double to compare. </param>
/// <param name="value2"> The second double to compare. </param>
public static bool AreClose(double value1, double value2)
{
//in case they are Infinities (then epsilon check does not work)
if (value1 == value2)
return true;
double eps = (Math.Abs(value1) + Math.Abs(value2) + 10.0) * DoubleEpsilon;
double delta = value1 - value2;
return (-eps < delta) && (eps > delta);
}

/// <summary>
/// GreaterThan - Returns whether or not the first double is greater than the second double.
/// That is, whether or not the first is strictly greater than *and* not within epsilon of
/// the other number.
/// </summary>
/// <param name="value1"> The first double to compare. </param>
/// <param name="value2"> The second double to compare. </param>
public static bool GreaterThan(double value1, double value2)
{
return (value1 > value2) && !AreClose(value1, value2);
}

/// <summary>
/// IsZero - Returns whether or not the double is "close" to 0. Same as AreClose(double, 0),
/// but this is faster.
/// </summary>
/// <param name="value"> The double to compare to 0. </param>
public static bool IsZero(double value)
{
return Math.Abs(value) < 10.0 * DoubleEpsilon;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System;
using Avalonia.Threading;

namespace Avalonia.Controls.Experimental.Data.Core;
namespace Avalonia.Experimental.Data.Core;

internal abstract class SingleSubscriberObservableBase<T> : IObservable<T>, IDisposable
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Avalonia.Controls.Experimental.Data.Core;
using Avalonia.Experimental.Data.Core;

namespace Avalonia.Experimental.Data
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Avalonia.Controls.Experimental.Data.Core;
using Avalonia.Experimental.Data.Core;
using Avalonia.VisualTree;

namespace Avalonia.Experimental.Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ internal class AnonymousRow<TModel> : IRow<TModel>, IModelIndexableRow
private int _modelIndex;
[AllowNull] private TModel _model;

#if !NET5_0_OR_GREATER
object? IRow.Model => _model;
#endif

public object? Header => _modelIndex;
public TModel Model => _model;
public int ModelIndex => _modelIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using Avalonia.Controls.Utils;
using Avalonia.Utilities;
using Avalonia.Experimental.Data.Core;

namespace Avalonia.Controls.Models.TreeDataGrid
{
Expand Down Expand Up @@ -83,7 +83,7 @@ public void Dispose()
{
// Rows in an AnonymousSortableRows collection have Auto height so we only
// know the start position of the first row.
if (MathUtilities.IsZero(y))
if (MathWrapper.IsZero(y))
return (0, 0);
return (-1, -1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.ComponentModel;
using Avalonia.Data;
using Avalonia.Experimental.Data;
using Avalonia.Utilities;
using Avalonia.Experimental.Data.Core;

namespace Avalonia.Controls.Models.TreeDataGrid
{
Expand Down Expand Up @@ -156,7 +156,7 @@ void IUpdateColumnLayout.CalculateStarWidth(double availableWidth, double totalS

var width = (availableWidth / totalStars) * Width.Value;
_starWidth = CoerceActualWidth(width);
_starWidthWasConstrained = !MathUtilities.AreClose(_starWidth, width);
_starWidthWasConstrained = !MathWrapper.AreClose(_starWidth, width);
}

bool IUpdateColumnLayout.CommitActualWidth()
Expand Down Expand Up @@ -184,7 +184,7 @@ bool IUpdateColumnLayout.CommitActualWidth()
return false;
}

return !MathUtilities.AreClose(oldWidth, ActualWidth);
return !MathWrapper.AreClose(oldWidth, ActualWidth);
}

void IUpdateColumnLayout.SetWidth(GridLength width) => SetWidth(width);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using Avalonia.Collections;
using Avalonia.Utilities;
using Avalonia.Experimental.Data.Core;

namespace Avalonia.Controls.Models.TreeDataGrid
{
Expand Down Expand Up @@ -160,7 +160,7 @@ private void UpdateColumnSizes()
// If the width of any star columns was constrained by their min/max size, and we
// actually had any space to distribute between star columns, then we need to update
// the star width for the non-constrained columns.
if (starWidthWasConstrained && MathUtilities.GreaterThan(availableSpace, 0))
if (starWidthWasConstrained && MathWrapper.GreaterThan(availableSpace, 0))
{
for (var i = 0; i < Count; ++i)
{
Expand Down
24 changes: 8 additions & 16 deletions src/Avalonia.Controls.TreeDataGrid/Models/TreeDataGrid/DragInfo.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
using System.Collections.Generic;
using Avalonia.Input;

namespace Avalonia.Controls.Models.TreeDataGrid
{
/// <summary>
/// Holds information about an automatic row drag/drop operation carried out
/// by <see cref="Avalonia.Controls.TreeDataGrid.AutoDragDropRows"/>.
/// </summary>
public class DragInfo
/// <param name="source">The source of the drag operation/</param>
/// <param name="indexes">The indexes being dragged.</param>
public class DragInfo(ITreeDataGridSource source, IEnumerable<IndexPath> indexes)
{
/// <summary>
/// Defines the data format in an <see cref="Avalonia.Input.IDataObject"/>.
/// Defines the data format for dragging TreeDataGrid rows.
/// </summary>
public const string DataFormat = "TreeDataGridDragInfo";

/// <summary>
/// Initializes a new instance of the <see cref="DragInfo"/> class.
/// </summary>
/// <param name="source">The source of the drag operation/</param>
/// <param name="indexes">The indexes being dragged.</param>
public DragInfo(ITreeDataGridSource source, IEnumerable<IndexPath> indexes)
{
Source = source;
Indexes = indexes;
}
public static readonly DataFormat<DragInfo> Format = DataFormat.CreateInProcessFormat<DragInfo>("TreeDataGridDragInfo");

/// <summary>
/// Gets the <see cref="ITreeDataGridSource"/> that rows are being dragged from.
/// </summary>
public ITreeDataGridSource Source { get; }
public ITreeDataGridSource Source { get; } = source;

/// <summary>
/// Gets or sets the model indexes of the rows being dragged.
/// </summary>
public IEnumerable<IndexPath> Indexes { get; }
public IEnumerable<IndexPath> Indexes { get; } = indexes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ public class HierarchicalRow<TModel> : NotifyingBase,
private bool _isExpanded;
private bool? _showExpander;

#if !NET5_0_OR_GREATER
object? IRow.Model => Model;
#endif

public HierarchicalRow(
IExpanderRowController<TModel> controller,
IExpanderColumn<TModel> expanderColumn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using Avalonia.Utilities;
using Avalonia.Experimental.Data.Core;

namespace Avalonia.Controls.Models.TreeDataGrid
{
Expand Down Expand Up @@ -130,7 +130,7 @@ public void Collapse(IndexPath index)
/// <inheritdoc/>
public (int index, double y) GetRowAt(double y)
{
if (MathUtilities.IsZero(y))
if (MathWrapper.IsZero(y))
return (0, 0);
return (-1, -1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ public interface IRow<TModel> : IRow
/// </summary>
new TModel Model { get; }

#if !!NET5_0_OR_GREATER
/// <summary>
/// Gets the untyped row model.
/// </summary>
object? IRow.Model => Model;
#endif

/// <summary>
/// Updates the model index due to a change in the data source.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface IRows : IReadOnlyList<IRow>, INotifyCollectionChanged
(int index, double y) GetRowAt(double y);

/// <summary>
/// Given a model index, returns an index into <see cref="Rows"/>.
/// Given a model index, returns an index into <see cref="ITreeDataGridSource.Rows"/>.
/// </summary>
/// <param name="modelIndex">The model index.</param>
/// <returns>The row index, or -1 if the model index is not displayed.</returns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using Avalonia.Controls.Experimental.Data.Core;
using Avalonia.Data;
using Avalonia.Experimental.Data;
using Avalonia.Experimental.Data.Core;

namespace Avalonia.Controls.Models.TreeDataGrid
{
Expand Down
Loading