Skip to content

Commit

Permalink
Merge pull request #521 from irihitech/image
Browse files Browse the repository at this point in the history
fix: fix image binding to stretch initialization issue.
  • Loading branch information
rabbitism authored Dec 26, 2024
2 parents cbda1e0 + 1b032dd commit e53e416
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
- name: Ursa Unit Test
run: dotnet test ./tests/Test.Ursa
- name: Ursa Headless Test
run: dotnet test ./tests/HeadlessTest.Ursa

ubuntu:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
- name: Ursa Unit Test
run: dotnet test ./tests/Test.Ursa
- name: Ursa Headless Test
run: dotnet test ./tests/HeadlessTest.Ursa
run: dotnet test ./tests/HeadlessTest.Ursa
3 changes: 2 additions & 1 deletion src/Ursa/Controls/ImageViewer/ImageViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ private void OnSourceChanged(AvaloniaPropertyChangedEventArgs args)

private void OnStretchChanged(AvaloniaPropertyChangedEventArgs args)
{
if (_image is null) return;
var stretch = args.GetNewValue<Stretch>();
Scale = GetScaleRatio(Width / _image!.Width, Height / _image!.Height, stretch);
Scale = GetScaleRatio(Width / _image.Width, Height / _image.Height, stretch);
_sourceMinScale = _image is not null ? Math.Min(Width * MinScale / _image.Width, Height * MinScale / _image.Height) : MinScale;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Avalonia.Controls;
using Avalonia.Media;
using Ursa.Controls;

namespace Test.Ursa.Controls.ImageViewerTests.Stretch_Initial_Value;

public class StretchValueTest
{
[Fact]
public void Stretch_Initial_Value_Does_Not_Crash()
{
ImageViewer iv = new ImageViewer()
{
Stretch = Stretch.UniformToFill
};
}
}

0 comments on commit e53e416

Please sign in to comment.