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

DPI awareness with different monitor DPIs #677

Closed
cjwere opened this issue Dec 14, 2016 · 24 comments
Closed

DPI awareness with different monitor DPIs #677

cjwere opened this issue Dec 14, 2016 · 24 comments
Assignees
Labels
Milestone

Comments

@cjwere
Copy link

cjwere commented Dec 14, 2016

Hi,

Love the virtual treeview! Even more now I'm using it with "High DPI" on one monitor.

When I drag my running program across to the other monitor all my forms and fonts rescale, but the virtual treeviews do not. my application declares multi monitor DPI awareness. I breakpointed on tbasevirtualTree.changescale and it is getting triggered. I have toAutoChangeScale set on (just been through and set this on all my virtual treeviews)

starting on my high DPI screen (192DPI):

image

, then dragging to my nomal 96DPI screen:

image

Note the tabs and button and font within the body of the treeview rescale correctly, but the node spacing and the header size and font do not.

Thanks,
Chris Were

@joachimmarder
Copy link
Contributor

Which version of Delphi and VirtualTreeView are you using?

@cjwere
Copy link
Author

cjwere commented Dec 14, 2016 via email

joachimmarder pushed a commit that referenced this issue Dec 14, 2016
…wn the DefaultNodeHeight in TBaseVirtualTree.AutoScale(), to which the paramter isDpiChnage has been added.
@joachimmarder
Copy link
Contributor

joachimmarder commented Dec 14, 2016

So far, TBaseVirtualTree.AutoScale() only scaled up the property DefaultNodeHeight if the text would not fit into a line. I just added some code that also scales DefaultNodeHeight down if the form's dpi changes.

However, I cannot test this right now because I have connected only one monitor to my PC. Could you please set a breakpoint in TBaseVirtualTree.ChangeScale() and see if FHeader.ChangeScale() is called?

@cjwere
Copy link
Author

cjwere commented Dec 14, 2016 via email

@cjwere
Copy link
Author

cjwere commented Dec 14, 2016 via email

@joachimmarder
Copy link
Contributor

OK Joachim, can i test it for you?

Sure. Use the GitHub master branch to test, as it already contains one fix compared to V6.4.1. Set a breakpoint on TBaseVirtualTree.ChangeScale() and see what code is executed and why.

@cjwere
Copy link
Author

cjwere commented Dec 15, 2016 via email

@joachimmarder
Copy link
Contributor

will have a look tomorrow.

Any news on how the master branch worked for you?

@joachimmarder
Copy link
Contributor

We should add a new event OnAutoScaled, that way one can easily adjust values that do not fit specific needs.

@cjwere
Copy link
Author

cjwere commented Dec 21, 2016 via email

@joachimmarder joachimmarder added this to the Version 6.5 milestone Dec 23, 2016
@joachimmarder joachimmarder self-assigned this Dec 23, 2016
@joachimmarder
Copy link
Contributor

Will have a look today.

Any news how the GitHub master works for you?

@cjwere
Copy link
Author

cjwere commented Jan 2, 2017 via email

@cjwere
Copy link
Author

cjwere commented Jan 8, 2017 via email

@cjwere
Copy link
Author

cjwere commented Jan 8, 2017 via email

@cjwere
Copy link
Author

cjwere commented Jan 9, 2017 via email

@cjwere
Copy link
Author

cjwere commented Jan 9, 2017 via email

@joachimmarder
Copy link
Contributor

joachimmarder commented Jan 9, 2017

project files attached.

Sorry, did not see any attached files in GitHub.

I’ll send through the changes when done for you to review?

The best is to send a pull request via GitHub.

I have added the lines in green, commented out the lines lines in red above.

Sorry, but GitHub issue comments do not support colors.

sfHeight didn't seem to ever be inScalingFlags so header was never scaled

Hmm, seems to be a bug in the VCL, I think it should be included. I think i must fetch another monitor and debug this myself.

@cjwere
Copy link
Author

cjwere commented Jan 9, 2017 via email

joachimmarder pushed a commit that referenced this issue Jan 9, 2017
joachimmarder pushed a commit that referenced this issue Jan 9, 2017
* TBaseVirtualTree.ChangeScale() now scales the node heights too
* TBaseVirtualTree.ChangeScale() now uses DefaultScalingFlags in case of a dpi scaling, just like TControl.ChangeScale() does it.
* TBaseVirtualTree.ChangeScale() now calls AutoScale() after calling inherited, to ensure that the Font has been updated.
@joachimmarder
Copy link
Contributor

I just committed some changes that I tested successfully with the "Minimal" demo project. Please let me know how these changes work for you. Please attach screenshots if issues still occur.

@cjwere
Copy link
Author

cjwere commented Jan 9, 2017 via email

@cjwere
Copy link
Author

cjwere commented Jan 9, 2017

Seems to be working! :)

Have launched the app on my high DPI screen, and on normal DPI, both look good.
Moving between screens behaves as expected as well.
(Same behaviour as I had achieved by ignoring scalingFlags altogether)

One issue arises though, if the user saves the column layouts in one dpi, then open the app in another dpi, the columns widths are messed up. In my version I had cached M into fCurrentPPI in the Changescale method if M<>D, as this is typically the new PPI resolution. I then publsih this as a readonly property (currentPPI). That way when the calling application saves and loads the column widths it can do so in a DPI independent way, thus:

writing column widths as if we were viewing in 96DPI:

      if in_tree.CurrentPPI<>1 then
        columnWidth := muldiv(Columns[i].Width, 96, in_tree.CurrentPPI) // get dpi of treeview?
      else 
        columnWidth := Columns[i].Width;
      Settings.WriteInteger( in_sectionName, columnName, columnWidth );

reading column widths for 96dpi and scaling them to current DPI:

        // Read column size
        columnName := in_tree.Name + '.Columns[' + IntToStr(i) + '].Width';
        if in_tree.CurrentPPI<>1 then
          columnWidth := mulDiv(m_Settings.ReadInteger( in_sectionName, columnName, 0 ), in_tree.CurrentPPI, 96)
        else
          columnWidth := m_Settings.ReadInteger( in_sectionName, columnName, 0 );

@joachimmarder
Copy link
Contributor

joachimmarder commented Jan 10, 2017

but I totally ignore scalingflags

I did it like in TControl which should lead to a consistent behavior with other VCL controls. So if it does not make a difference for you I will stick with this implementation.

@joachimmarder
Copy link
Contributor

if the user saves the column layouts in one dpi, then open the app in another dpi, the columns widths are messed up.

I think this is a separate issue and we should open a separate issue for it. While this one was a bug in Virtual TreeView code, the column stuff is more an enhancement and affects all controls that have columns or grids. So I will close this issue as resolved.

joachimmarder pushed a commit that referenced this issue Jan 10, 2017
@cjwere
Copy link
Author

cjwere commented Jan 10, 2017 via email

joachimmarder pushed a commit that referenced this issue Jan 25, 2017
…) now uses the dpi of the current monitor, not of the default monitor, in Delphi 10.1 Berlin and higher.
joachimmarder pushed a commit that referenced this issue Jan 25, 2017
…Height based on the Font only, if the paramter isDpiChnaged is False. In case of a dpi chnage the font may not yet be adapted to this.
ValtsS pushed a commit to ValtsS/Virtual-TreeView that referenced this issue Jan 25, 2019
…le up and down the DefaultNodeHeight in TBaseVirtualTree.AutoScale(), to which the paramter isDpiChnage has been added.

# Conflicts:
#	Source/VirtualTrees.pas
ValtsS pushed a commit to ValtsS/Virtual-TreeView that referenced this issue Jan 25, 2019
…r DPIs):

* TBaseVirtualTree.ChangeScale() now scales the node heights too
* TBaseVirtualTree.ChangeScale() now uses DefaultScalingFlags in case of a dpi scaling, just like TControl.ChangeScale() does it.
* TBaseVirtualTree.ChangeScale() now calls AutoScale() after calling inherited, to ensure that the Font has been updated.
# Conflicts:
#	Source/VirtualTrees.pas
ValtsS pushed a commit to ValtsS/Virtual-TreeView that referenced this issue Jan 25, 2019
… DefaultNodeHeight based on the Font only, if the paramter isDpiChnaged is False. In case of a dpi chnage the font may not yet be adapted to this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants