Skip to content

Commit

Permalink
fix(dui): preview issues #1961 #1960 (#1964)
Browse files Browse the repository at this point in the history
* fix(dui): preview issues #1961 #1960

* fix(dui): ensures preview state is reset when changing branch
  • Loading branch information
teocomi committed Dec 6, 2022
1 parent 9cf0b3c commit 22b8bbf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
14 changes: 12 additions & 2 deletions DesktopUI2/DesktopUI2/ViewModels/StreamViewModel.cs
Expand Up @@ -212,8 +212,6 @@ public BranchViewModel SelectedBranch
AddNewBranch();
else
GetCommits();


}
}

Expand Down Expand Up @@ -260,6 +258,7 @@ public Commit SelectedCommit
set
{
this.RaiseAndSetIfChanged(ref _selectedCommit, value);
PreviewImage360Loaded = false;
if (_selectedCommit != null)
{
if (_selectedCommit.id == "latest")
Expand Down Expand Up @@ -472,6 +471,13 @@ public Avalonia.Media.Imaging.Bitmap PreviewImage360
set => this.RaiseAndSetIfChanged(ref _previewImage360, value);
}

private bool _previewImage360Loaded;
public bool PreviewImage360Loaded
{
get => _previewImage360Loaded;
set => this.RaiseAndSetIfChanged(ref _previewImage360Loaded, value);
}

public bool CanOpenCommentsIn3DView { get; set; } = false;
public bool CanReceive { get; set; }
public bool HasSettings { get; set; } = true;
Expand Down Expand Up @@ -1028,6 +1034,10 @@ public async Task DownloadImage360(string url)

_previewImage360 = new Bitmap(stream);
this.RaisePropertyChanged(nameof(PreviewImage360));
//the default 360 image width is 34300
//this is a quick hack to see if the returned image is not an error image like "you do not have access" etc
if (_previewImage360.Size.Width > 30000)
PreviewImage360Loaded = true;

}
catch (Exception ex)
Expand Down
Expand Up @@ -212,6 +212,7 @@
<Image
x:Name="Image360"
Height="200"
Opacity="0"
Source="{Binding PreviewImage360}" />
</Viewbox>
</Grid>
Expand Down
@@ -1,6 +1,7 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using DesktopUI2.ViewModels;
using System;

namespace DesktopUI2.Views.Controls.StreamEditControls
Expand All @@ -18,18 +19,37 @@ public Receive()
Image360 = this.FindControl<Image>("Image360");
ImageBasic = this.FindControl<Image>("ImageBasic");



PreviewBox360.PointerMoved += PreviewBox360_PointerMoved;
PreviewBox360.PointerEnter += PreviewBox360_PointerEnter;
PreviewBox360.PointerLeave += PreviewBox360_PointerLeave;

}



private void PreviewBox360_PointerMoved(object sender, Avalonia.Input.PointerEventArgs e)
{
ImageBasic.IsVisible = false;


var mouseX = e.GetPosition(PreviewBox360).X + PreviewBox360.Margin.Left;
SetMargin(mouseX);
}

private void PreviewBox360_PointerEnter(object sender, Avalonia.Input.PointerEventArgs e)
{
var svm = PreviewBox360.DataContext as StreamViewModel;
if (!svm.PreviewImage360Loaded)
return;
Image360.Opacity = 1;
ImageBasic.IsVisible = false;
}

private void PreviewBox360_PointerLeave(object sender, Avalonia.Input.PointerEventArgs e)
{
Image360.Opacity = 0;
ImageBasic.IsVisible = true;
}

private void SetMargin(double mouseX)
{
if (mouseX == 0)
Expand Down

0 comments on commit 22b8bbf

Please sign in to comment.