Skip to content
This repository has been archived by the owner on May 2, 2021. It is now read-only.

Commit

Permalink
Reactive-ish demo, new gifs
Browse files Browse the repository at this point in the history
  • Loading branch information
worldbeater committed Jan 15, 2020
1 parent 4f6ff6f commit 421b5e6
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 61 deletions.
24 changes: 10 additions & 14 deletions AvaloniaGif.Demo/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
using Avalonia;
using Avalonia.Logging.Serilog;
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;

namespace AvaloniaGif.Demo
{
public class App : Application
{
public override void Initialize()
public override void Initialize() => AvaloniaXamlLoader.Load(this);

public override void OnFrameworkInitializationCompleted()
{
AvaloniaXamlLoader.Load(this);
var window = new MainWindow
{
DataContext = new MainWindowViewModel()
};

window.Show();
base.OnFrameworkInitializationCompleted();
}

static void Main(string[] args)
=> BuildAvaloniaApp()
.Start<MainWindow>();

public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.UseReactiveUI()
.LogToDebug();
}
}
4 changes: 2 additions & 2 deletions AvaloniaGif.Demo/AvaloniaGif.Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
<EmbeddedResource Include="**\*.xaml">
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="**\*.gif"/>
<EmbeddedResource Include="**\*.gif" />
<EmbeddedResource Include="Assets\*" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.9.1" />
<PackageReference Include="Avalonia.Desktop" Version="0.9.1" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.9.1" />
<ProjectReference Include="..\AvaloniaGif\AvaloniaGif.csproj"/>
<ProjectReference Include="..\AvaloniaGif\AvaloniaGif.csproj" />
</ItemGroup>
</Project>
Binary file added AvaloniaGif.Demo/Images/c-loader.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AvaloniaGif.Demo/Images/evitare-loader.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AvaloniaGif.Demo/Images/loader.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 15 additions & 4 deletions AvaloniaGif.Demo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@
Title="GIFs on Avalonia!"
Height="480" Width="680"
Background="White">
<DockPanel LastChildFill="True">
<ListBox DockPanel.Dock="Left" Width="300" SelectedItem="{Binding SelectedGif}" Items="{Binding AvailableGifs}"/>
<Image Stretch="None" gif:GifImage.SourceUri="{Binding SelectedGif}"/>
</DockPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="3*" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<ComboBox SelectedItem="{Binding Path=Stretch}"
Items="{Binding Path=Stretches}"/>
<ListBox SelectedItem="{Binding Path=SelectedGif}"
Items="{Binding Path=AvailableGifs}" />
</StackPanel>
<Image Grid.Column="1"
Stretch="{Binding Path=Stretch}"
gif:GifImage.SourceUri="{Binding Path=SelectedGif}"/>
</Grid>
</Window>
10 changes: 5 additions & 5 deletions AvaloniaGif.Demo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia;
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
using ReactiveUI;

namespace AvaloniaGif.Demo
{
public class MainWindow : Window
public class MainWindow : ReactiveWindow<MainWindowViewModel>
{
public MainWindow()
{
AvaloniaXamlLoader.Load(this);
this.DataContext = new MainWindowViewModel();
this.WhenActivated(disposables => { });
}
}
}
70 changes: 34 additions & 36 deletions AvaloniaGif.Demo/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,64 +1,62 @@
using System.Collections.ObjectModel;
using System;
using System.ComponentModel;
using System.Collections.Generic;
using Avalonia.Media;
using ReactiveUI;

namespace AvaloniaGif.Demo
{
public class MainWindowViewModel : INotifyPropertyChanged
public class MainWindowViewModel : ReactiveObject
{
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string v)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(v));
}

public MainWindowViewModel()
{
this.AvailableGifs = new ObservableCollection<Uri>()
Stretches = new List<Stretch>
{
Stretch.None,
Stretch.Fill,
Stretch.Uniform,
Stretch.UniformToFill
};
AvailableGifs = new List<Uri>
{
new Uri("resm:AvaloniaGif.Demo.Images.laundry.gif"),
new Uri("resm:AvaloniaGif.Demo.Images.earth.gif"),
new Uri("resm:AvaloniaGif.Demo.Images.rainbow.gif"),
new Uri("resm:AvaloniaGif.Demo.Images.newton-cradle.gif"),
new Uri("resm:AvaloniaGif.Demo.Images.newton-cradle.gif"),

// Great shots by Vitaly Silkin, free to use:
// https://dribbble.com/colder/projects/219798-Loaders
new Uri("resm:AvaloniaGif.Demo.Images.loader.gif"),
new Uri("resm:AvaloniaGif.Demo.Images.evitare-loader.gif"),
new Uri("resm:AvaloniaGif.Demo.Images.c-loader.gif")
};
}

public void DisplaySelectedGif()
{
CurrentGif = SelectedGif;
}

private ObservableCollection<Uri> _availableGifs;
public ObservableCollection<Uri> AvailableGifs
private IReadOnlyList<Uri> _availableGifs;
public IReadOnlyList<Uri> AvailableGifs
{
get => _availableGifs;
set
{
_availableGifs = value;
OnPropertyChanged(nameof(AvailableGifs));
}
set => this.RaiseAndSetIfChanged(ref _availableGifs, value);
}

private Uri _selectedGif;
public Uri SelectedGif
{
get => _selectedGif;
set
{
_selectedGif = value;
OnPropertyChanged(nameof(SelectedGif));
}
set => this.RaiseAndSetIfChanged(ref _selectedGif, value);
}

private Uri _currentGif;
public Uri CurrentGif
private IReadOnlyList<Stretch> _stretches;
public IReadOnlyList<Stretch> Stretches
{
get => _currentGif;
set
{
_currentGif = value;
OnPropertyChanged(nameof(CurrentGif));
}
get => _stretches;
set => this.RaiseAndSetIfChanged(ref _stretches, value);
}

private Stretch _stretch = Stretch.None;
public Stretch Stretch
{
get => _stretch;
set => this.RaiseAndSetIfChanged(ref _stretch, value);
}
}
}
17 changes: 17 additions & 0 deletions AvaloniaGif.Demo/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Avalonia;
using Avalonia.Logging.Serilog;
using Avalonia.ReactiveUI;

namespace AvaloniaGif.Demo
{
public static class Program
{
public static void Main(string[] args) => BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);

public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.UseReactiveUI()
.LogToDebug();
}
}

0 comments on commit 421b5e6

Please sign in to comment.