-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Update Anchor Layout to support high DPI machines. #7956
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f6b3f4c
Update Anchor and Anchor destination calculations
dreddy-work b3c1bbe
Add unit tests
dreddy-work c3a0a8d
Cleanup.
dreddy-work fa3d9c5
Address feedback and fix test inputs
dreddy-work 372588e
Address feedback.
dreddy-work 2b24b7c
Remove unnecessary usings
dreddy-work fd247fe
Moving test UI integration tests.
dreddy-work 85617ba
Handle scenarios where Parent's handle is created after childs handle…
dreddy-work f9b9874
Handle scenarios where Parent's handle is created after childs handle…
dreddy-work 186d7ef
Apply suggestions from code review
dreddy-work 46f4e9e
Update src/System.Windows.Forms/src/System/Windows/Forms/Layout/Defau…
dreddy-work ef4ecff
Address feedback on comments.
dreddy-work 817d61e
Address further feedback.
dreddy-work df1edc1
Address feedback
dreddy-work b1c10af
Caching bounds is not right and broke test
dreddy-work 71b2bee
Change scope to private.
dreddy-work 9db65cd
Revert analyzer suggestion for perf.
dreddy-work 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,15 +10,35 @@ namespace System.Windows.Forms.Primitives | |
| // Borrowed from https://github.com/dotnet/runtime/blob/main/src/libraries/Common/src/System/LocalAppContextSwitches.Common.cs | ||
| internal static partial class LocalAppContextSwitches | ||
| { | ||
| // Switch names declared internal below are used in unit/integration tests. Refer to | ||
| // https://github.com/microsoft/winforms/blob/tree/main/docs/design/anchor_layout_changes_in_net80.md | ||
| // for more details on how to enable these switches in the application. | ||
| private const string ScaleTopLevelFormMinMaxSizeForDpiSwitchName = "System.Windows.Forms.ScaleTopLevelFormMinMaxSizeForDpi"; | ||
| internal const string AnchorLayoutV2SwitchName = "System.Windows.Forms.AnchorLayoutV2"; | ||
|
|
||
| private static int s_scaleTopLevelFormMinMaxSizeForDpi; | ||
| private static int s_AnchorLayoutV2; | ||
|
|
||
| public static bool ScaleTopLevelFormMinMaxSizeForDpi | ||
| { | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| get => GetCachedSwitchValue(ScaleTopLevelFormMinMaxSizeForDpiSwitchName, ref s_scaleTopLevelFormMinMaxSizeForDpi); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Indicates whether AnchorLayoutV2 feature is enabled. | ||
| /// </summary> | ||
| /// <devdoc> | ||
| /// Returns AnchorLayoutV2 switch value from runtimeconfig.json. Defaults to true if application is targeting .NET 8.0 and beyond. | ||
|
dreddy-work marked this conversation as resolved.
|
||
| /// Refer to | ||
| /// https://github.com/microsoft/winforms/blob/tree/main/docs/design/anchor_layout_changes_in_net80.md for more details. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. diito |
||
| /// </devdoc> | ||
| public static bool AnchorLayoutV2 | ||
| { | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| get => GetCachedSwitchValue(AnchorLayoutV2SwitchName, ref s_AnchorLayoutV2); | ||
| } | ||
|
|
||
| private static readonly FrameworkName? s_targetFrameworkName = GetTargetFrameworkName(); | ||
|
|
||
| private static readonly bool s_isNetCoreApp = (s_targetFrameworkName?.Identifier) == ".NETCoreApp"; | ||
|
|
@@ -33,9 +53,14 @@ private static bool GetCachedSwitchValue(string switchName, ref int cachedSwitch | |
| { | ||
| // The cached switch value has 3 states: 0 - unknown, 1 - true, -1 - false | ||
| if (cachedSwitchValue < 0) | ||
|
Tanya-Solyanik marked this conversation as resolved.
|
||
| { | ||
| return false; | ||
| } | ||
|
|
||
| if (cachedSwitchValue > 0) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| return GetSwitchValue(switchName, ref cachedSwitchValue); | ||
| } | ||
|
|
@@ -64,6 +89,8 @@ static bool GetSwitchDefaultValue(string switchName) | |
| return false; | ||
| } | ||
|
|
||
| // We are introducing switch defaults in .NET 8.0+ and support matrix for this product is | ||
| // limited to Windows 10 and above versions. | ||
| if (OsVersion.IsWindows10_1703OrGreater()) | ||
| { | ||
| if (s_targetFrameworkName!.Version.CompareTo(new Version("8.0")) >= 0) | ||
|
|
@@ -72,6 +99,11 @@ static bool GetSwitchDefaultValue(string switchName) | |
| { | ||
| return true; | ||
| } | ||
|
|
||
| if (switchName == AnchorLayoutV2SwitchName) | ||
| { | ||
|
dreddy-work marked this conversation as resolved.
|
||
| return true; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
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
Oops, something went wrong.
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.
Changing name to anchor-layout-changes-in-net80.md when renaming it on doc PR. Intentionally underscored here.
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.
❗ This link is still incorrect.