This repository was archived by the owner on Feb 25, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add lazy loading threshold for ImageEx control #3483
Merged
Merged
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
ff33aa2
Merge pull request #16 from windows-toolkit/master
h82258652 48a3bff
Merge pull request #17 from windows-toolkit/master
h82258652 9fc4599
Merge pull request #18 from windows-toolkit/master
h82258652 8dfc8e3
Add lazy loading threshold
h82258652 01349a6
Merge branch 'master' into lazyLoadingThreshold
h82258652 07c4e85
use FindAscendants instead
h82258652 cf34c64
Merge branch 'lazyLoadingThreshold' of https://github.com/h82258652/U…
h82258652 c94aaa0
Merge branch 'master' into lazyLoadingThreshold
h82258652 7ae5a0c
remove IsLazyLoadingSupported property
h82258652 fb40d85
Merge branch 'master' into lazyLoadingThreshold
h82258652 ad1c678
Merge branch 'master' into lazyLoadingThreshold
h82258652 74502e4
Add RectExtensions
h82258652 a2cc630
Use extension method to detect is intersect
h82258652 1600c78
Merge branch 'master' into lazyLoadingThreshold
h82258652 63dcc3e
Merge branch 'master' into lazyLoadingThreshold
h82258652 46e4bbb
Add more test cases
h82258652 21c4fb5
Merge branch 'master' into lazyLoadingThreshold
michael-hawker cef75d1
Merge branch 'master' into lazyLoadingThreshold
h82258652 4eef5ab
improve performance while lazy loading is not enabled
h82258652 731f70f
Merge branch 'master' into lazyLoadingThreshold
michael-hawker de190e4
Merge branch 'master' into lazyLoadingThreshold
michael-hawker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System.Diagnostics.Contracts; | ||
| using System.Runtime.CompilerServices; | ||
| using Rect = Windows.Foundation.Rect; | ||
|
|
||
| namespace Microsoft.Toolkit.Uwp.Extensions | ||
| { | ||
| /// <summary> | ||
| /// Extensions for the <see cref="Rect"/> type. | ||
| /// </summary> | ||
| public static class RectExtensions | ||
| { | ||
| /// <summary> | ||
| /// Determines if a rectangle intersects with another rectangle. | ||
| /// </summary> | ||
| /// <param name="rect1">The first rectangle to test.</param> | ||
| /// <param name="rect2">The second rectangle to test.</param> | ||
| /// <returns>This method returns <see langword="true"/> if there is any intersection, otherwise <see langword="false"/>.</returns> | ||
| [Pure] | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static bool IntersectsWith(this Rect rect1, Rect rect2) | ||
| { | ||
| if (rect1.IsEmpty || rect2.IsEmpty) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| return (rect1.Left <= rect2.Right) && | ||
| (rect1.Right >= rect2.Left) && | ||
| (rect1.Top <= rect2.Bottom) && | ||
| (rect1.Bottom >= rect2.Top); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; | ||
| using Microsoft.Toolkit.Uwp.Extensions; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using Windows.Foundation; | ||
|
|
||
| namespace UnitTests.Extensions | ||
| { | ||
| [TestClass] | ||
| public class Test_RectExtensions | ||
| { | ||
| [TestCategory("RectExtensions")] | ||
| [TestMethod] | ||
| [DataRow(0, 0, 2, 2, 0, 0, 2, 2, true)]// Full intersection. | ||
| [DataRow(0, 0, 2, 2, 1, 1, 2, 2, true)]// Partial intersection. | ||
| [DataRow(0, 0, 2, 2, -2, 0, 2, 2, true)]// Left edge intersection. | ||
| [DataRow(0, 0, 2, 2, 0, -2, 2, 2, true)]// Top edge intersection. | ||
| [DataRow(0, 0, 2, 2, 2, 0, 2, 2, true)]// Right edge intersection. | ||
| [DataRow(0, 0, 2, 2, 0, 2, 2, 2, true)]// Bottom edge intersection. | ||
| [DataRow(0, 0, 2, 2, -2, -2, 2, 2, true)]// Left top corner(0, 0) intersection. | ||
| [DataRow(0, 0, 2, 2, 2, -2, 2, 2, true)]// Right top corner(2, 0) intersection. | ||
| [DataRow(0, 0, 2, 2, 2, 2, 2, 2, true)]// Right bottom corner(2, 2) intersection. | ||
| [DataRow(0, 0, 2, 2, -2, 2, 2, 2, true)]// Left bottom corner(0, 2) intersection. | ||
| [DataRow(0, 0, 2, 2, 3, 0, 2, 2, false)]// No intersection. | ||
|
michael-hawker marked this conversation as resolved.
|
||
| [SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1117:Parameters should be on same line or separate lines", Justification = "Put the parameters of the same rectangle on the same line is clearer.")] | ||
| public static void Test_RectExtensions_IntersectsWith( | ||
| double rect1X, double rect1Y, double rect1Width, double rect1Height, | ||
| double rect2X, double rect2Y, double rect2Width, double rect2Height, | ||
| bool shouldIntersectsWith) | ||
| { | ||
| var rect1 = new Rect(rect1X, rect1Y, rect1Width, rect1Height); | ||
| var rect2 = new Rect(rect2X, rect2Y, rect2Width, rect2Height); | ||
| var isIntersectsWith = rect1.IntersectsWith(rect2); | ||
| Assert.IsTrue(isIntersectsWith == shouldIntersectsWith); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason you picked 300?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michael-hawker About this I think a lot. I searched google and it tells me Chromium will calculate this by the screen size and network type. And then I searched the most widely used JavaScript image lazy loading library, got this. This lib use 300px as default. I think UWP is mostly used on a PC, not a mobile device. The network should be not bad, 300px should be suitable for most situations.