From f2efed0d13c49afcd930f42350fa7a33738cd129 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Thu, 26 Dec 2024 17:24:02 +0800 Subject: [PATCH 1/3] fix: fix image binding to stretch initialization issue. --- src/Ursa/Controls/ImageViewer/ImageViewer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Ursa/Controls/ImageViewer/ImageViewer.cs b/src/Ursa/Controls/ImageViewer/ImageViewer.cs index e0abde2..021151f 100644 --- a/src/Ursa/Controls/ImageViewer/ImageViewer.cs +++ b/src/Ursa/Controls/ImageViewer/ImageViewer.cs @@ -163,8 +163,9 @@ public class ImageViewer: TemplatedControl private void OnStretchChanged(AvaloniaPropertyChangedEventArgs args) { + if (_image is null) return; var stretch = args.GetNewValue(); - 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; } From 41a60d47e12f4996912f7db66c2b6cbce31f8af0 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Thu, 26 Dec 2024 18:07:56 +0800 Subject: [PATCH 2/3] feat: add unit test. --- .../Stretch_Initial_Value/StretchValueTest.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/Test.Ursa/ImageViewerTests/Stretch_Initial_Value/StretchValueTest.cs diff --git a/tests/Test.Ursa/ImageViewerTests/Stretch_Initial_Value/StretchValueTest.cs b/tests/Test.Ursa/ImageViewerTests/Stretch_Initial_Value/StretchValueTest.cs new file mode 100644 index 0000000..c187394 --- /dev/null +++ b/tests/Test.Ursa/ImageViewerTests/Stretch_Initial_Value/StretchValueTest.cs @@ -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 + }; + } +} \ No newline at end of file From 1b032dd7de19b81fcd31c6f032f6a415e21cbb1d Mon Sep 17 00:00:00 2001 From: rabbitism Date: Thu, 26 Dec 2024 18:11:24 +0800 Subject: [PATCH 3/3] chore: include UT in workflow. --- .github/workflows/test.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ac81f27..2d9e8a0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 \ No newline at end of file + run: dotnet test ./tests/HeadlessTest.Ursa