Make default wxSizer border DPI-aware.
Scale the (still hard-coded) border in pixels by the content scale factor for the platforms where this needs to be done, i.e. not wxGTK nor wxOSX where the underlying toolkit already does it.
This commit is contained in:
@@ -123,6 +123,7 @@ wxGTK:
|
||||
|
||||
wxMSW:
|
||||
|
||||
- Make default wxSizer border DPI-aware.
|
||||
- Improve wxMimeTypesManager open command detection (Eric Jensen).
|
||||
- Make wxFILTER_INCLUDE_LIST in wxTextValidator actually usable.
|
||||
- Fix appearance of toggled wxToggleButtons with bitmap (tm).
|
||||
|
@@ -117,10 +117,21 @@ public:
|
||||
// GNOME HIG says to use 6px as the base unit:
|
||||
// http://library.gnome.org/devel/hig-book/stable/design-window.html.en
|
||||
return 6;
|
||||
#else
|
||||
// FIXME: default border size shouldn't be hardcoded and at the very
|
||||
// least they should depend on the current font size
|
||||
#elif defined(__WXMAC__)
|
||||
// Not sure if this is really the correct size for the border.
|
||||
return 5;
|
||||
#else
|
||||
// For the other platforms, we need to scale raw pixel values using the
|
||||
// current DPI, do it once (and cache the result) in another function.
|
||||
#define wxNEEDS_BORDER_IN_PX
|
||||
|
||||
// We don't react to dynamic DPI changes, so we can cache the values of
|
||||
// the border in on-screen pixels after computing it once. This
|
||||
// could/should change in the future.
|
||||
if ( !ms_defaultBorderInPx )
|
||||
ms_defaultBorderInPx = DoGetDefaultBorderInPx();
|
||||
|
||||
return ms_defaultBorderInPx;
|
||||
#endif
|
||||
#else
|
||||
return 0;
|
||||
@@ -222,6 +233,12 @@ public:
|
||||
int GetBorderInPixels() const { return m_borderInPixels; }
|
||||
|
||||
private:
|
||||
#ifdef wxNEEDS_BORDER_IN_PX
|
||||
static int DoGetDefaultBorderInPx();
|
||||
|
||||
static int ms_defaultBorderInPx;
|
||||
#endif // wxNEEDS_BORDER_IN_PX
|
||||
|
||||
int m_proportion;
|
||||
int m_flags;
|
||||
int m_borderInPixels;
|
||||
|
@@ -1372,6 +1372,10 @@ public:
|
||||
/**
|
||||
Sets the wxSizerFlags to have a border of a number of pixels specified
|
||||
by @a borderinpixels with the directions specified by @a direction.
|
||||
|
||||
Prefer to use the overload below or DoubleBorder() or TripleBorder()
|
||||
versions instead of hard-coding the border value in pixels to avoid too
|
||||
small borders on devices with high DPI displays.
|
||||
*/
|
||||
wxSizerFlags& Border(int direction, int borderinpixels);
|
||||
|
||||
@@ -1478,6 +1482,10 @@ public:
|
||||
|
||||
/**
|
||||
Returns the border used by default in Border() method.
|
||||
|
||||
This value is scaled appropriately for the current DPI on the systems
|
||||
where physical pixel values are used for the control positions and
|
||||
sizes, i.e. not with wxGTK or wxOSX.
|
||||
*/
|
||||
static int GetDefaultBorder();
|
||||
|
||||
|
@@ -84,6 +84,34 @@ WX_DEFINE_EXPORTED_LIST( wxSizerItemList )
|
||||
minsize
|
||||
*/
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxSizerFlags
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifdef wxNEEDS_BORDER_IN_PX
|
||||
|
||||
int wxSizerFlags::ms_defaultBorderInPx = 0;
|
||||
|
||||
/* static */
|
||||
int wxSizerFlags::DoGetDefaultBorderInPx()
|
||||
{
|
||||
// Hard code 5px as it's the minimal border size between two controls, see
|
||||
// the table at the bottom of
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx
|
||||
//
|
||||
// Of course, ideal would be to use the appropriate sizes for the borders
|
||||
// between related and unrelated controls, as explained at the above URL,
|
||||
// but we don't have a way to specify this in our API currently.
|
||||
//
|
||||
// We also have to use the DPI for the primary monitor here as we don't
|
||||
// have any associated window, so this is wrong on systems using multiple
|
||||
// monitors with different resolutions too -- but, again, without changes
|
||||
// in the API, there is nothing we can do about this.
|
||||
return wxWindow::FromDIP(5, NULL);
|
||||
}
|
||||
|
||||
#endif // wxNEEDS_BORDER_IN_PX
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxSizerItem
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user