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

Recalculate the node position of the TreeView when DrawMode = TreeViewDrawMode.OwnerDrawText #12698

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

LeafShi1
Copy link
Member

@LeafShi1 LeafShi1 commented Dec 31, 2024

Fixes #12681

Root Cause

When treeView.DrawMode = TreeViewDrawMode.OwnerDrawText, the node's FillRectangle and FocusRectangle positions are calculated incorrectly

Proposed changes

  • Update function CustomDraw of the TreeView.cs, When RightToLeft == RightToLeft.Yes && RightToLeftLayout reverses the X drawing coordinates of FillRectangle and FocusRectangle

Customer Impact

  • When setting RightToLeft = Yes and RightToLeftLayout = True, the selected node box is fully rendered

Regression?

  • No

Risk

  • Minimal

Screenshots

Before

image

After

When setting RightToLeft = Yes, RightToLeftLayout = True and .DrawMode = TreeViewDrawMode.OwnerDrawText, the selected node box is fully rendered
image

Test methodology

  • Manually

Test environment(s)

  • .net 10.0.0-alpha.1.24628.1
Microsoft Reviewers: Open in CodeFlow

@LeafShi1 LeafShi1 requested a review from a team as a code owner December 31, 2024 08:05
Copy link

codecov bot commented Dec 31, 2024

Codecov Report

Attention: Patch coverage is 64.33710% with 1041 lines in your changes missing coverage. Please review.

Project coverage is 61.29163%. Comparing base (d1bbb32) to head (5cb9458).
Report is 171 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                  @@
##                main      #12698          +/-   ##
====================================================
- Coverage   76.13468%   61.29163%   -14.84306%     
====================================================
  Files           3242        1541        -1701     
  Lines         642363      158281      -484082     
  Branches       47271       14743       -32528     
====================================================
- Hits          489061       97013      -392048     
+ Misses        149751       60571       -89180     
+ Partials        3551         697        -2854     
Flag Coverage Δ
Debug 61.29163% <64.33710%> (-14.84306%) ⬇️
integration 10.73249% <13.88305%> (-7.36435%) ⬇️
production 39.16159% <59.46392%> (-10.91881%) ⬇️
test 95.67602% <88.25911%> (-1.30056%) ⬇️
unit 36.58737% <58.39175%> (-10.93210%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@LeafShi1 LeafShi1 added the waiting-review This item is waiting on review by one or more members of team label Jan 3, 2025
@ricardobossan
Copy link
Member

I proceeded to test the PR and the issue seems to have been solved:

image

The code LGTM!

Copy link
Member

@Tanya-Solyanik Tanya-Solyanik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had you tested this change at different scaling factors and in different level nodes in a tree view? For example 3rd level child?
It will be helpful to add code comments that describe what the constants are for.

@Tanya-Solyanik Tanya-Solyanik added waiting-author-feedback The team requires more information from the author and removed waiting-review This item is waiting on review by one or more members of team labels Jan 7, 2025
@dotnet-policy-service dotnet-policy-service bot removed the waiting-author-feedback The team requires more information from the author label Jan 7, 2025
@Tanya-Solyanik Tanya-Solyanik added waiting-for-testing The PR is awaiting manual testing by the primary team; no action is yet required from the author(s) waiting-author-feedback The team requires more information from the author labels Jan 7, 2025
@dotnet-policy-service dotnet-policy-service bot removed the waiting-author-feedback The team requires more information from the author label Jan 8, 2025
@LeafShi1 LeafShi1 removed the waiting-for-testing The PR is awaiting manual testing by the primary team; no action is yet required from the author(s) label Jan 10, 2025
@Tanya-Solyanik Tanya-Solyanik added the waiting-for-testing The PR is awaiting manual testing by the primary team; no action is yet required from the author(s) label Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (3)

src/System.Windows.Forms/src/System/Windows/Forms/Controls/TreeView/TreeView.cs:2907

  • [nitpick] The method name 'PreferredHeight' is not very descriptive. Consider renaming it to 'CalculatePreferredHeight'.
private int PreferredHeight

src/System.Windows.Forms/src/System/Windows/Forms/Controls/TreeView/TreeView.cs:2921

  • [nitpick] The method name 'GetNodeHeight' is not very descriptive. Consider renaming it to 'CalculateNodeHeight'.
private int GetNodeHeight(TreeNode node)

src/System.Windows.Forms/src/System/Windows/Forms/Controls/TreeView/TreeView.cs:2741

  • Using 'goto' is generally considered bad practice. Consider refactoring the code to eliminate the need for 'goto'.
goto default;
@Tanya-Solyanik Tanya-Solyanik added the waiting-author-feedback The team requires more information from the author label Jan 22, 2025
@dotnet-policy-service dotnet-policy-service bot removed the waiting-author-feedback The team requires more information from the author label Jan 23, 2025
@LeafShi1 LeafShi1 force-pushed the Issue_12681_fix_recalculate_node_position branch 2 times, most recently from 8ecf0b8 to c5f0f04 Compare January 26, 2025 01:47
@LeafShi1 LeafShi1 added waiting-review This item is waiting on review by one or more members of team and removed waiting-for-testing The PR is awaiting manual testing by the primary team; no action is yet required from the author(s) labels Jan 27, 2025
@LeafShi1
Copy link
Member Author

No regressions found in private PRs

@Tanya-Solyanik
Copy link
Member

@LeafShi1 - even though "issue5" as reported by Olina, is not a regression from the previous release, it is a regression from .NET Framework, could you please investigate it?

@Tanya-Solyanik Tanya-Solyanik added waiting-author-feedback The team requires more information from the author and removed waiting-review This item is waiting on review by one or more members of team labels Jan 28, 2025
@LeafShi1
Copy link
Member Author

LeafShi1 commented Mar 4, 2025

The issue5: The right border of the node's checkbox is not visible in the edit mode of the node
image

This issue repro in MFC app and not repro in .NET Framework project:
image

@LeafShi1 LeafShi1 force-pushed the Issue_12681_fix_recalculate_node_position branch from ac643af to b4fc154 Compare March 6, 2025 08:33
@LeafShi1 LeafShi1 force-pushed the Issue_12681_fix_recalculate_node_position branch from 402e5a3 to b4fc154 Compare March 6, 2025 08:42
@LeafShi1 LeafShi1 closed this Mar 6, 2025
@LeafShi1 LeafShi1 force-pushed the Issue_12681_fix_recalculate_node_position branch from d7b8138 to d1bbb32 Compare March 6, 2025 09:11
Rebase main
@LeafShi1 LeafShi1 reopened this Mar 6, 2025
@LeafShi1 LeafShi1 requested a review from Tanya-Solyanik March 6, 2025 09:18
@LeafShi1 LeafShi1 added waiting-review This item is waiting on review by one or more members of team and removed waiting-author-feedback The team requires more information from the author labels Mar 6, 2025
{
float dpiScale = (float)DeviceDpi / ScaleHelper.OneHundredPercentLogicalDpi;

PInvoke.SetWindowPos((HWND)editHandle,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reposition the edit text box to fix the issue The right border of the node's checkbox is not visible in the edit mode of the node

image

@LeafShi1 LeafShi1 requested a review from JeremyKuhne March 7, 2025 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-review This item is waiting on review by one or more members of team
Projects
None yet
3 participants