On Tue, 19 Mar 2019 01:58:45 +0200 Teodor Petrov wrote:
TP> I'm trying to make Code::Blocks look good on the three OSes (4 different
TP> ports).
Excellent, we really need to have a concrete example of problems
encountered (and solved) when adding high DPI support to a non-trivial
application using wx and, ideally, an open-source one, so that we could
point people directly to the relevant commits/parts of its source. And as
C::B satisfies both the "non-trivial" and "open-source", you're very
welcome to be our guinea pig^W^W valuable contributor helping us to improve
our high DPI support!
TP> My main struggle is that I don't know what is really the correct approach.
TP> Is there some guide about this? It would be rather helpful.
I promise to write it once I know what to put into it :-)
TP> So what I'm currently doing:
TP> I'm working on the toolbars, because they are the most affected by HiDPI.
TP> Our toolbars are wxToolbars created from xrc files using custom XRC handler.
TP> We use wxAUI and the toolbars could be re-arranged by the user.
TP> The images and xrc files for the toolbars are stored in a zip file.
TP> We don't use the Apple's suffixes in filenames.
In (non open-source) applications I worked on so far, I've always used the
@2x suffix because, as much as I dislike Apple in general, this just seems
to be the most reasonable way to do it.
TP> The plan is to have as many icon sizes as possible and allow the user to
TP> choose the size and probably use the scale factor to adjust it.
Why should users be bothered with this? IMO it would be a pretty poor user
experience. Perhaps you want to provide a choice between small, medium and
large toolbar icons in the options, but surely the icons should appear in
the correct size, appropriate for the current resolution, by default?
Of course, this does require some way of finding the right bitmap for the
given logical size and the current DPI. If you don't use the suffixes (and
wx doesn't support them out of the box in non-Mac ports anyhow currently),
there must be some other mechanism for doing it. Ideal would be to have
such mechanism inside wxWidgets, while making it sufficiently flexible, so
that it could be customized by the different applications to their needs.
TP> Currently I do something like:
TP>
TP> wxToolBar* Manager::CreateEmptyToolbar()
TP> {
TP> const wxSize size(m_ToolbarImageSize, m_ToolbarImageSize);
TP> wxWindow *appFrame = GetAppFrame();
TP> #if wxCHECK_VERSION(3, 0, 0)
TP> const double scaleFactor = appFrame->GetContentScaleFactor();
TP> const wxSize scaledSize(size.x/scaleFactor, size.y/scaleFactor);
TP> #else
TP> const wxSize scaledSize = size;
TP> #endif // wxCHECK_VERSION(3, 0, 0)
TP>
TP> wxToolBar* toolbar = new wxToolBar(appFrame, -1, wxDefaultPosition,
TP> scaledSize, wxTB_FLAT | wxTB_NODIVIDER);
TP> toolbar->SetToolBitmapSize(scaledSize);
TP>
TP> return toolbar;
TP> }
The question for me is whether we should apply the scaling inside
SetToolBitmapSize() itself. On one hand, this would be more convenient,
IMO. OTOH it would break your existing code and any other code doing its
own scale adjustment. We could add a new SetToolBitmapLogicalSize(), which
would be 100% backwards compatible, but I don't know if it's a good idea to
add new variants of all the existing functions dealing with sizes... For
once, I think we should break compatibility here and decide, once and for
all, that all wxWindow-level functions work with logical pixels.
TP> So I create a toolbar based on the scaling factor.
TP> This is the only way I've found to get a good looking toolbar on macOS. I
TP> also have to use the special wxBitmap constructor to set proper scaling
TP> to the images, because they aren't marked with a suffix.
In the absence of some general mechanism allowing to do it, all
applications providing high DPI bitmaps would have to do something like
this which is, of course, quite suboptimal...
TP> On linux this works fine, too, but I'm not able to get any scaling
TP> different from 1.0 on both gtk2 and gtk3 :(
For GTK+ 2 it's not a surprise, it just doesn't support high DPI and
trying to do anything with it is hopeless. For GTK+ 3 it should really
work, I tested this relatively recently and there is even a small patch to
the toolbar sample at
https://trac.wxwidgets.org/ticket/18225 which
definitely worked for me. Could you please check if it works for you?
TP> On windows this also works, but the the result of
TP> wxToolbar::GetToolBitmapSize changes after a call to realize and I'm a
TP> bit confused and worried that I don't do the correct thing.
What does GetToolBitmapSize() return?
TP> Should I create the toolbar to match the size of my images on windows and
TP> gtk2/3 and do the scaling corrections only on macOS?
Of course we want the same code to work under all platforms.
TP> Another problem I have is that on windows 7 wxComboBox and wxComboCtrl
TP> have different heights. This makes all toolbars on a given row look a
TP> bit off and ugly. Is this expected? Can I do something about this?
Not sure, but please wait until
https://trac.wxwidgets.org/ticket/18294
is finally resolved, as this might change things. If it doesn't, please
open a separate ticket for this with, as usual, a minimal patch allowing me
to see/debug the problem if possible.
TIA,
VZ