Skip to content

Address Graphics state reset issue in DarkMode Button renderers #13641

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

Conversation

KlausLoeffelmann
Copy link
Member

@KlausLoeffelmann KlausLoeffelmann commented Jun 23, 2025

This PR makes sure, that the Graphics state is reset to the original state after rendering the DarkMode Button but implementing the render logic based on ButtonDarkModeRendererBase.

Follows up respective issues pointed out by the DarkMode feature reviews.

Microsoft Reviewers: Open in CodeFlow

@KlausLoeffelmann KlausLoeffelmann requested a review from a team as a code owner June 23, 2025 23:22
@github-actions github-actions bot added the area-DarkMode Issues relating to Dark Mode feature label Jun 23, 2025
Copy link

codecov bot commented Jun 24, 2025

Codecov Report

Attention: Patch coverage is 0% with 18 lines in your changes missing coverage. Please review.

Project coverage is 76.75863%. Comparing base (e037b05) to head (0d940b7).
Report is 23 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main      #13641         +/-   ##
===================================================
+ Coverage   76.75572%   76.75863%   +0.00290%     
===================================================
  Files           3256        3256                 
  Lines         642016      642019          +3     
  Branches       47548       47548                 
===================================================
+ Hits          492784      492805         +21     
+ Misses        145574      145554         -20     
- Partials        3658        3660          +2     
Flag Coverage Δ
Debug 76.75863% <0.00000%> (+0.00290%) ⬆️
integration 18.98494% <0.00000%> (-0.00682%) ⬇️
production 51.32509% <0.00000%> (+0.00675%) ⬆️
test 97.41719% <ø> (ø)
unit 48.70966% <0.00000%> (+0.01303%) ⬆️

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.

Copy link
Member

@JeremyKuhne JeremyKuhne left a comment

Choose a reason for hiding this comment

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

See note on the scope

@@ -44,39 +45,50 @@ public void RenderButton(
ArgumentNullException.ThrowIfNull(paintImage);
ArgumentNullException.ThrowIfNull(paintField);

// Clear the background over the whole button area.
ClearBackground(graphics, parentBackgroundColor);
GraphicsState? graphicsState = default;
Copy link
Member

Choose a reason for hiding this comment

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

Use the GraphicsStateScope here and elsewhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's assumingly the same approach with PenScope and BrushScope, right?

Copy link
Member

Choose a reason for hiding this comment

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

Similar, but simpler. Should be a lot of other uses. We have scopes for most things that need cleaned up or reset. Reduces nesting and ensures ordering. There are also opportunities to further optimize in some cases as well now that we control the internals of System.Drawing (could, for example, avoid creating wrapper classes in some cases,).

@dotnet-policy-service dotnet-policy-service bot added waiting-author-feedback The team requires more information from the author and removed waiting-author-feedback The team requires more information from the author labels Jun 24, 2025
@KlausLoeffelmann KlausLoeffelmann force-pushed the DarkModeButtonRendererResetState branch from 5e106ae to dbb74b0 Compare July 1, 2025 07:32
@KlausLoeffelmann KlausLoeffelmann force-pushed the DarkModeButtonRendererResetState branch from a3468e5 to a481476 Compare July 9, 2025 21:45
@KlausLoeffelmann KlausLoeffelmann force-pushed the DarkModeButtonRendererResetState branch from a481476 to 0d940b7 Compare July 9, 2025 21:46

if (focused && showFocusCues)
// Scope the graphics state so all changes are reverted after rendering
using (new GraphicsStateScope(graphics))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
using (new GraphicsStateScope(graphics))
using GraphicsStateScope graphicsScope = new(graphics);

@KlausLoeffelmann KlausLoeffelmann dismissed JeremyKuhne’s stale review July 16, 2025 19:15

Out on vacation, and we need to get this merged.

@KlausLoeffelmann KlausLoeffelmann merged commit c9252f6 into dotnet:main Jul 16, 2025
8 checks passed
@KlausLoeffelmann KlausLoeffelmann deleted the DarkModeButtonRendererResetState branch August 13, 2025 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-DarkMode Issues relating to Dark Mode feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants