-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Adjust ToolStripComboBox size based on DPI scaling #11865
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
Adjust ToolStripComboBox size based on DPI scaling #11865
Conversation
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.
looks sensible
Co-authored-by: Michael Seibt <36601201+mstv@users.noreply.github.com>
I didn't include 100% scaling screenshots this time, but if by I've been suffering these tiny search fields for years until I snapped 😅 I haven't had a 100% scaled screen in my life for over 5 years now |
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.
We have AdjustForDpiScaling
extensions, is there a reason we can't enhance it to deal with all ToolStripComboBox
?
public static class ControlDpiExtensions | |
{ | |
public static void AdjustForDpiScaling(this Control control) |
tscboBranchFilter.Size = new Size(DpiUtil.Scale(tscboBranchFilter.Size.Width), tscboBranchFilter.Size.Height); | ||
tstxtRevisionFilter.Size = new Size(DpiUtil.Scale(tstxtRevisionFilter.Size.Width), tstxtRevisionFilter.Size.Height); |
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.
Any reason we can't do the following?
tscboBranchFilter.Size = new Size(DpiUtil.Scale(tscboBranchFilter.Size.Width), tscboBranchFilter.Size.Height); | |
tstxtRevisionFilter.Size = new Size(DpiUtil.Scale(tstxtRevisionFilter.Size.Width), tstxtRevisionFilter.Size.Height); | |
tscboBranchFilter.Size = DpiUtil.Scale(tscboBranchFilter.Size); | |
tstxtRevisionFilter.Size = DpiUtil.Scale(tstxtRevisionFilter.Size); |
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.
I had it the way you showed at first, but when comparing with unscaled version I noticed that the toolbar was getting higher for no good reason and thus switched to only scaling the width.
When it gets higher it's with DpiUtil.Scale(tscboBranchFilter.Size)
type of scaling
combobox-dpi.mp4
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.
Please add a comment explaining this, otherwise it's a hidden knowledge. Thanks
@RussKie oh wow, turns out Trying to add it to This would require to create a similar "structure" to iterate through |
Yes, we'll need to create a new overload. |
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.
Good stuff! 🚀
{ | ||
case ToolStripComboBox toolStripComboBox: | ||
{ | ||
if (toolStripComboBox.Tag as string != "__DPI_SCALED__") |
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 could lead to issues if Tag
is set to something...
I suggest to add DebugHelpers.Fail
check to alert developers in event the tag is set explicitly.
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.
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.
yes or #11865 (comment) with your message
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.
@mstv I don't see how this solves the problem. There are two separate use cases that want to use a Tag
property and neither would work if the other one took over. After some googling I've seen people use a Dictionary<string, object>
and some wrapper methods to add support for multiple tags on a control.
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 could lead to issues if
Tag
is set to something...
...
I don't see how this solves the problem. There are two separate use cases that want to use a
Tag
property and neither would work if the other one took over. After some googling I've seen people use aDictionary<string, object>
and some wrapper methods to add support for multiple tags on a control.
I was not aware that there are two usages of Tag
- at least with your addition.
Then rather do not use Tag
at all, which always is a good advice because it is not obvious for what Tag
is used.
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.
@mdonatas controls should be scaled in the .ctor, which means the scaling should happen once. Am I missing something?
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.
You are probably not missing anything... I've just seen other cases where this tag was used and assumed that was necessary and then fell into the rabbit hole :)
Removed the check. Scaling still works as expected.
if (toolStripComboBox.Tag as string != "__DPI_SCALED__") | ||
{ | ||
toolStripComboBox.Tag = "__DPI_SCALED__"; |
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.
if (toolStripComboBox.Tag as string != "__DPI_SCALED__") | |
{ | |
toolStripComboBox.Tag = "__DPI_SCALED__"; | |
const string alreadyScaled = "__DPI_SCALED__"; | |
if (toolStripComboBox.Tag as string != alreadyScaled) | |
{ | |
Debug.Assert(toolStripComboBox.Tag is null); | |
toolStripComboBox.Tag = alreadyScaled; |
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.
have not run
Proposed changes
ToolStripComboBox
is immune to AutoScaling things.. thus it's necessary to perform the scaling manuallyToolStripComboBox
Screenshots
Before / After
Test methodology
Test environment(s)
Merge strategy
I agree that the maintainer squash merge this PR (if the commit message is clear).
✒️ I contribute this code under The Developer Certificate of Origin.