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

Fix tool strip border in dark theme #8899

Merged
merged 1 commit into from
Feb 28, 2021
Merged

Fix tool strip border in dark theme #8899

merged 1 commit into from
Feb 28, 2021

Conversation

NikolayXHD
Copy link
Member

Fixes #8864

Screenshots

Before

image
image

After

image
image

Proposed changes

At the moment there is a couple of cases where a custom ToolStrip.Renderer solves a task not related to dark theme.

  1. emulate context menu "caption" item, which serves as an item group header
    image
    image
  2. remove ToolStrip borders (ToolStripEx class)

Current implementation of dark theme does not consider the cases above. It does

toolStrip.Renderer = new ThemeAwareToolStripRenderer();

to all toolstrips, which breaks the cases 1. 2. above.

This PR does such that if a ToolStrip needs custom rendering, it uses on of 2 predefined renderers,
ToolStripExRenderer or ToolStripExThemeAwareRenderer, both of which support scenarios 1. and 2. from above.

Why not use 1 renderer per 1 solved problem?

Because ToolStripRenderer design makes it impossible.

It offers 2 ways of customization:

  • subscribe to an event such as RenderMenuItemBackground
  • override a virtual method such as OnRenderMenuItemBackground

The event mechanism fails because it cannot suppress default painting, except the few cases when ther is an eventArgs.Handled field.

The inheritance mechanism does not allow you to compose different renderers so that each is responsible for solving 1 problem.

Amusingly, ToolStripRenderer does offer an ok way to compose renderers, which is a virtual property ToolStripRenderer.RendererOverride, but guess what, it's internal.

Every time I stumble upon virtual internal pattern in a library code, I cannot help feel that library developer considers other developers, especially me, second class.

Test environment(s)

  • Windows10
  • default dpi, 100%

✒️ I contribute this code under The Developer Certificate of Origin.

@ghost ghost assigned NikolayXHD Feb 27, 2021
@NikolayXHD NikolayXHD requested review from a user, RussKie and gerhardol February 27, 2021 21:44
@codecov
Copy link

codecov bot commented Feb 27, 2021

Codecov Report

Merging #8899 (00dfa3f) into master (b4cbe02) will decrease coverage by 0.10%.
The diff coverage is 40.38%.

@@            Coverage Diff             @@
##           master    #8899      +/-   ##
==========================================
- Coverage   56.14%   56.04%   -0.11%     
==========================================
  Files         918      925       +7     
  Lines       65695    65899     +204     
  Branches    12055    12091      +36     
==========================================
+ Hits        36886    36934      +48     
- Misses      25795    25948     +153     
- Partials     3014     3017       +3     
Flag Coverage Δ
production 43.27% <42.30%> (-0.09%) ⬇️
tests 94.83% <ø> (+0.01%) ⬆️

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

@RussKie
Copy link
Member

RussKie commented Feb 28, 2021

Awesome work!

I pushed few tweaks to API names, reordered methods, etc.

@RussKie RussKie added this to the 3.5 milestone Feb 28, 2021
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

👍

@NikolayXHD NikolayXHD merged commit deaefda into gitextensions:master Feb 28, 2021
@ghost ghost modified the milestones: 3.5, 3.6 Feb 28, 2021
RussKie pushed a commit that referenced this pull request Mar 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Theming] ToolStrip visual artifacts
3 participants