Skip to content

Commit

Permalink
Moved FlexPanel.
Browse files Browse the repository at this point in the history
  • Loading branch information
jp2masa committed Sep 20, 2023
1 parent c2f7239 commit 2ecf1eb
Show file tree
Hide file tree
Showing 18 changed files with 989 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Avalonia.Labs.sln
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Labs.Catalog.Deskt
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Labs.Qr", "src\Avalonia.Labs.Qr\Avalonia.Labs.Qr.csproj", "{D7196459-710E-4057-BA38-8265C7C94854}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.Labs.Lottie", "src\Avalonia.Labs.Lottie\Avalonia.Labs.Lottie.csproj", "{633A51E9-65E7-4350-9AE6-E527FECD15F9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Labs.Lottie", "src\Avalonia.Labs.Lottie\Avalonia.Labs.Lottie.csproj", "{633A51E9-65E7-4350-9AE6-E527FECD15F9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Labs.Panels", "src\Avalonia.Labs.Panels\Avalonia.Labs.Panels.csproj", "{BEDDF9B6-5B8D-4524-975C-485F87DDE7A2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -94,6 +96,10 @@ Global
{633A51E9-65E7-4350-9AE6-E527FECD15F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{633A51E9-65E7-4350-9AE6-E527FECD15F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{633A51E9-65E7-4350-9AE6-E527FECD15F9}.Release|Any CPU.Build.0 = Release|Any CPU
{BEDDF9B6-5B8D-4524-975C-485F87DDE7A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BEDDF9B6-5B8D-4524-975C-485F87DDE7A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BEDDF9B6-5B8D-4524-975C-485F87DDE7A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BEDDF9B6-5B8D-4524-975C-485F87DDE7A2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 2 additions & 0 deletions samples/Avalonia.Labs.Catalog.Desktop/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using Avalonia;
using Avalonia.Labs.Controls.Cache;
using Avalonia.ReactiveUI;

namespace Avalonia.Labs.Catalog.Desktop;

Expand All @@ -18,6 +19,7 @@ public static void Main(string[] args) => BuildAvaloniaApp()
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.UseReactiveUI()
.AfterSetup(builder =>
{
CacheOptions.SetDefault(new CacheOptions()
Expand Down
1 change: 1 addition & 0 deletions samples/Avalonia.Labs.Catalog/Avalonia.Labs.Catalog.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\Avalonia.Labs.Controls\Avalonia.Labs.Controls.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Labs.Lottie\Avalonia.Labs.Lottie.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Labs.Panels\Avalonia.Labs.Panels.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Labs.Qr\Avalonia.Labs.Qr.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Globalization;

using Avalonia.Data.Converters;

namespace Avalonia.Labs.Catalog.Converters
{
internal sealed class FlexDemoNumberToThicknessConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is int x && targetType.IsAssignableFrom(typeof(Thickness)))
{
var y = 16 + 2 * ((x * 5) % 9);
return new Thickness(2 * y, y);
}

throw new NotSupportedException();
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) =>
throw new NotSupportedException();
}
}
57 changes: 57 additions & 0 deletions samples/Avalonia.Labs.Catalog/ViewModels/FlexItemViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Reactive.Linq;

using Avalonia.Labs.Panels;

using ReactiveUI;

namespace Avalonia.Labs.Catalog.ViewModels
{
public sealed class FlexItemViewModel : ReactiveObject
{
internal const AlignItems AlignSelfAuto = (AlignItems)(-1);

private readonly ObservableAsPropertyHelper<AlignItems?> _alignSelf;

private bool _isSelected;
private bool _isVisible = true;

private AlignItems _alignSelfItem = AlignSelfAuto;
private int _order;

public FlexItemViewModel(int value)
{
Value = value;

_alignSelf = (from item in this.WhenAnyValue(vm => vm.AlignSelfItem)
select item == AlignSelfAuto ? default(AlignItems?) : item).ToProperty(this, nameof(AlignSelf));
}

public int Value { get; }

public bool IsSelected
{
get => _isSelected;
set => this.RaiseAndSetIfChanged(ref _isSelected, value);
}

public bool IsVisible
{
get => _isVisible;
set => this.RaiseAndSetIfChanged(ref _isVisible, value);
}

public AlignItems AlignSelfItem
{
get => _alignSelfItem;
set => this.RaiseAndSetIfChanged(ref _alignSelfItem, value);
}

public AlignItems? AlignSelf => _alignSelf.Value;

public int Order
{
get => _order;
set => this.RaiseAndSetIfChanged(ref _order, value);
}
}
}
130 changes: 130 additions & 0 deletions samples/Avalonia.Labs.Catalog/ViewModels/FlexViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive.Linq;
using System.Windows.Input;

using Avalonia.Labs.Catalog.Views;
using Avalonia.Labs.Panels;

using ReactiveUI;

namespace Avalonia.Labs.Catalog.ViewModels
{
public sealed class FlexViewModel : ViewModelBase
{
private readonly ObservableCollection<FlexItemViewModel> _numbers;

private FlexDirection _direction = FlexDirection.Row;
private JustifyContent _justifyContent = JustifyContent.FlexStart;
private AlignItems _alignItems = AlignItems.FlexStart;
private AlignContent _alignContent = AlignContent.FlexStart;
private FlexWrap _wrap = FlexWrap.Wrap;

private int _columnSpacing = 8;
private int _rowSpacing = 32;

private int _currentNumber = 41;

private FlexItemViewModel? _selectedItem;

static FlexViewModel()
{
ViewLocator.Register(typeof(FlexViewModel), () => new FlexView());
}

public FlexViewModel()
{
Title = "Flex View";

_numbers = new ObservableCollection<FlexItemViewModel>(Enumerable.Range(1, 40).Select(x => new FlexItemViewModel(x)));

Numbers = new ReadOnlyObservableCollection<FlexItemViewModel>(_numbers);

AddItemCommand = ReactiveCommand.Create(AddItem);
RemoveItemCommand = ReactiveCommand.Create(RemoveItem, this.WhenAnyValue(vm => vm.SelectedItem).Select(x => x != null));
}

public IEnumerable DirectionValues { get; } = Enum.GetValues(typeof(FlexDirection));

public IEnumerable JustifyContentValues { get; } = Enum.GetValues(typeof(JustifyContent));

public IEnumerable AlignItemsValues { get; } = Enum.GetValues(typeof(AlignItems));

public IEnumerable AlignContentValues { get; } = Enum.GetValues(typeof(AlignContent));

public IEnumerable WrapValues { get; } = Enum.GetValues(typeof(FlexWrap));

public IEnumerable AlignSelfValues { get; } = Enum.GetValues(typeof(AlignItems)).Cast<AlignItems>().Prepend(FlexItemViewModel.AlignSelfAuto);

public FlexDirection Direction
{
get => _direction;
set => this.RaiseAndSetIfChanged(ref _direction, value);
}

public JustifyContent JustifyContent
{
get => _justifyContent;
set => this.RaiseAndSetIfChanged(ref _justifyContent, value);
}

public AlignItems AlignItems
{
get => _alignItems;
set => this.RaiseAndSetIfChanged(ref _alignItems, value);
}

public AlignContent AlignContent
{
get => _alignContent;
set => this.RaiseAndSetIfChanged(ref _alignContent, value);
}

public FlexWrap Wrap
{
get => _wrap;
set => this.RaiseAndSetIfChanged(ref _wrap, value);
}

public int ColumnSpacing
{
get => _columnSpacing;
set => this.RaiseAndSetIfChanged(ref _columnSpacing, value);
}

public int RowSpacing
{
get => _rowSpacing;
set => this.RaiseAndSetIfChanged(ref _rowSpacing, value);
}

public ReadOnlyObservableCollection<FlexItemViewModel> Numbers { get; }

public FlexItemViewModel? SelectedItem
{
get => _selectedItem;
set => this.RaiseAndSetIfChanged(ref _selectedItem, value);
}

public ICommand AddItemCommand { get; }

public ICommand RemoveItemCommand { get; }

private void AddItem() => _numbers.Add(new FlexItemViewModel(_currentNumber++));

private void RemoveItem()
{
if (SelectedItem is null)
{
throw new InvalidOperationException();
}

_numbers.Remove(SelectedItem);

SelectedItem.IsSelected = false;
SelectedItem = null;
}
}
}
Loading

0 comments on commit 2ecf1eb

Please sign in to comment.