-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2143 from erri120/tree-columns
TreeDataGrid column definitions
- Loading branch information
Showing
13 changed files
with
341 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/NexusMods.App.UI/Controls/TreeDataGrid/IColumnDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using Avalonia.Controls.Models.TreeDataGrid; | ||
using JetBrains.Annotations; | ||
|
||
namespace NexusMods.App.UI.Controls; | ||
|
||
/// <summary> | ||
/// Static interface for column definitions | ||
/// </summary> | ||
[PublicAPI] | ||
public interface IColumnDefinition<TModel, TSelf> | ||
where TModel : class | ||
where TSelf : IColumnDefinition<TModel, TSelf>, IComparable<TSelf> | ||
{ | ||
static virtual int Compare(TModel? a, TModel? b) | ||
{ | ||
return (a, b) switch | ||
{ | ||
(TSelf itemA, TSelf itemB) => itemA.CompareTo(itemB), | ||
|
||
// b precedes a | ||
(TSelf, _) => 1, | ||
|
||
// a precedes b | ||
(_, TSelf) => -1, | ||
|
||
// a and b are in the same position | ||
(_, _) => 0, | ||
}; | ||
} | ||
|
||
static abstract string GetColumnHeader(); | ||
static abstract string GetColumnTemplateResourceKey(); | ||
static virtual string GetColumnId() => TSelf.GetColumnTemplateResourceKey(); | ||
|
||
static virtual IColumn<TModel> CreateColumn() | ||
{ | ||
return new CustomTemplateColumn<TModel>( | ||
header: TSelf.GetColumnHeader(), | ||
cellTemplateResourceKey: TSelf.GetColumnTemplateResourceKey(), | ||
options: new TemplateColumnOptions<TModel> | ||
{ | ||
CanUserSortColumn = true, | ||
CanUserResizeColumn = true, | ||
CompareAscending = static (a, b) => TSelf.Compare(a, b), | ||
CompareDescending = static (a, b) => TSelf.Compare(b, a), | ||
} | ||
) | ||
{ | ||
Id = TSelf.GetColumnId(), | ||
}; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Column helper. | ||
/// </summary> | ||
[PublicAPI] | ||
public static class ColumnCreator | ||
{ | ||
/// <summary> | ||
/// Creates a column from a static interface definition. | ||
/// </summary> | ||
public static IColumn<TModel> CreateColumn<TModel, TColumnInterface>() | ||
where TModel : class | ||
where TColumnInterface : IColumnDefinition<TModel, TColumnInterface>, IComparable<TColumnInterface> | ||
{ | ||
return TColumnInterface.CreateColumn(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using NexusMods.App.UI.Controls; | ||
|
||
namespace NexusMods.App.UI.Pages.LibraryPage; | ||
|
||
public interface ILibraryItemModel : ITreeDataGridItemModel; |
35 changes: 35 additions & 0 deletions
35
src/NexusMods.App.UI/Pages/LibraryPage/ILibraryItemWithAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using NexusMods.App.UI.Controls; | ||
using R3; | ||
|
||
namespace NexusMods.App.UI.Pages.LibraryPage; | ||
|
||
public interface ILibraryItemWithAction : ILibraryItemModel, IComparable<ILibraryItemWithAction>, IColumnDefinition<ILibraryItemModel, ILibraryItemWithAction> | ||
{ | ||
int IComparable<ILibraryItemWithAction>.CompareTo(ILibraryItemWithAction? other) | ||
{ | ||
return (this, other) switch | ||
{ | ||
(ILibraryItemWithInstallAction, ILibraryItemWithDownloadAction) => -1, | ||
(ILibraryItemWithDownloadAction, ILibraryItemWithInstallAction) => 1, | ||
_ => 0, | ||
}; | ||
} | ||
|
||
public const string ColumnTemplateResourceKey = "LibraryItemActionColumn"; | ||
static string IColumnDefinition<ILibraryItemModel, ILibraryItemWithAction>.GetColumnHeader() => "Action"; | ||
static string IColumnDefinition<ILibraryItemModel, ILibraryItemWithAction>.GetColumnTemplateResourceKey() => ColumnTemplateResourceKey; | ||
} | ||
|
||
public interface ILibraryItemWithInstallAction : ILibraryItemWithAction | ||
{ | ||
ReactiveCommand<Unit, Unit> InstallItemCommand { get; } | ||
|
||
BindableReactiveProperty<bool> IsInstalled { get; } | ||
|
||
BindableReactiveProperty<string> InstallButtonText { get; } | ||
} | ||
|
||
public interface ILibraryItemWithDownloadAction : ILibraryItemWithAction | ||
{ | ||
ReactiveCommand<Unit, Unit> DownloadItemCommand { get; } | ||
} |
16 changes: 16 additions & 0 deletions
16
src/NexusMods.App.UI/Pages/LibraryPage/ILibraryItemWithDownloadedDate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using NexusMods.App.UI.Controls; | ||
using R3; | ||
|
||
namespace NexusMods.App.UI.Pages.LibraryPage; | ||
|
||
public interface ILibraryItemWithDownloadedDate : ILibraryItemModel, IComparable<ILibraryItemWithDownloadedDate>, IColumnDefinition<ILibraryItemModel, ILibraryItemWithDownloadedDate> | ||
{ | ||
ReactiveProperty<DateTime> DownloadedDate { get; } | ||
BindableReactiveProperty<string> FormattedDownloadedDate { get; } | ||
|
||
int IComparable<ILibraryItemWithDownloadedDate>.CompareTo(ILibraryItemWithDownloadedDate? other) => other is null ? 1 : DateTime.Compare(DownloadedDate.Value, other.DownloadedDate.Value); | ||
|
||
public const string ColumnTemplateResourceKey = "LibraryItemDownloadedDateColumn"; | ||
static string IColumnDefinition<ILibraryItemModel, ILibraryItemWithDownloadedDate>.GetColumnHeader() => "Downloaded"; | ||
static string IColumnDefinition<ILibraryItemModel, ILibraryItemWithDownloadedDate>.GetColumnTemplateResourceKey() => ColumnTemplateResourceKey; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/NexusMods.App.UI/Pages/LibraryPage/ILibraryItemWithInstalledDate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using NexusMods.App.UI.Controls; | ||
using R3; | ||
|
||
namespace NexusMods.App.UI.Pages.LibraryPage; | ||
|
||
public interface ILibraryItemWithInstalledDate : ILibraryItemModel, IComparable<ILibraryItemWithInstalledDate>, IColumnDefinition<ILibraryItemModel, ILibraryItemWithInstalledDate> | ||
{ | ||
ReactiveProperty<DateTime> InstalledDate { get; } | ||
BindableReactiveProperty<string> FormattedInstalledDate { get; } | ||
|
||
int IComparable<ILibraryItemWithInstalledDate>.CompareTo(ILibraryItemWithInstalledDate? other) => other is null ? 1 : DateTime.Compare(InstalledDate.Value, other.InstalledDate.Value); | ||
|
||
public const string ColumnTemplateResourceKey = "LibraryItemInstalledDateColumn"; | ||
static string IColumnDefinition<ILibraryItemModel, ILibraryItemWithInstalledDate>.GetColumnHeader() => "Installed"; | ||
static string IColumnDefinition<ILibraryItemModel, ILibraryItemWithInstalledDate>.GetColumnTemplateResourceKey() => ColumnTemplateResourceKey; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/NexusMods.App.UI/Pages/LibraryPage/ILibraryItemWithName.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using NexusMods.App.UI.Controls; | ||
using R3; | ||
|
||
namespace NexusMods.App.UI.Pages.LibraryPage; | ||
|
||
public interface ILibraryItemWithName : ILibraryItemModel, IComparable<ILibraryItemWithName>, IColumnDefinition<ILibraryItemModel, ILibraryItemWithName> | ||
{ | ||
BindableReactiveProperty<string> Name { get; } | ||
|
||
int IComparable<ILibraryItemWithName>.CompareTo(ILibraryItemWithName? other) => string.CompareOrdinal(Name.Value, other?.Name.Value); | ||
|
||
public const string ColumnTemplateResourceKey = "LibraryItemNameColumn"; | ||
static string IColumnDefinition<ILibraryItemModel, ILibraryItemWithName>.GetColumnHeader() => "Name"; | ||
static string IColumnDefinition<ILibraryItemModel, ILibraryItemWithName>.GetColumnTemplateResourceKey() => ColumnTemplateResourceKey; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/NexusMods.App.UI/Pages/LibraryPage/ILibraryItemWithSize.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using NexusMods.App.UI.Controls; | ||
using NexusMods.Paths; | ||
using R3; | ||
|
||
namespace NexusMods.App.UI.Pages.LibraryPage; | ||
|
||
public interface ILibraryItemWithSize : ILibraryItemModel, IComparable<ILibraryItemWithSize>, IColumnDefinition<ILibraryItemModel, ILibraryItemWithSize> | ||
{ | ||
ReactiveProperty<Size> ItemSize { get; } | ||
BindableReactiveProperty<string> FormattedSize { get; } | ||
|
||
int IComparable<ILibraryItemWithSize>.CompareTo(ILibraryItemWithSize? other) => other is null ? 1 : ItemSize.Value.CompareTo(other.ItemSize.Value); | ||
|
||
public const string ColumnTemplateResourceKey = "LibraryItemSizeColumn"; | ||
static string IColumnDefinition<ILibraryItemModel, ILibraryItemWithSize>.GetColumnHeader() => "Size"; | ||
static string IColumnDefinition<ILibraryItemModel, ILibraryItemWithSize>.GetColumnTemplateResourceKey() => ColumnTemplateResourceKey; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/NexusMods.App.UI/Pages/LibraryPage/ILibraryItemWithVersion.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using NexusMods.App.UI.Controls; | ||
using R3; | ||
|
||
namespace NexusMods.App.UI.Pages.LibraryPage; | ||
|
||
public interface ILibraryItemWithVersion : ILibraryItemModel, IComparable<ILibraryItemWithVersion>, IColumnDefinition<ILibraryItemModel, ILibraryItemWithVersion> | ||
{ | ||
BindableReactiveProperty<string> Version { get; } | ||
|
||
int IComparable<ILibraryItemWithVersion>.CompareTo(ILibraryItemWithVersion? other) => string.CompareOrdinal(Version.Value, other?.Version.Value); | ||
|
||
public const string ColumnTemplateResourceKey = "LibraryItemVersionColumn"; | ||
static string IColumnDefinition<ILibraryItemModel, ILibraryItemWithVersion>.GetColumnHeader() => "Version"; | ||
static string IColumnDefinition<ILibraryItemModel, ILibraryItemWithVersion>.GetColumnTemplateResourceKey() => ColumnTemplateResourceKey; | ||
} |
Oops, something went wrong.