Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix image binding to stretch initialization issue. #521

Merged
merged 3 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
};
}
}
Loading