Merge branch 'splitter-highdpi'

Fix splitter in high DPI under wxGTK and wxOSX by not scaling the
positions by DPI there unnecessarily.

See #24126.
This commit is contained in:
Vadim Zeitlin 2023-12-12 20:06:36 +01:00
commit f32e92d55b
2 changed files with 18 additions and 17 deletions

View file

@ -126,13 +126,14 @@ public:
int GetSashPos() const { return m_sashPos; }
private:
wxWindow *m_left, *m_right;
wxWindow *m_left = nullptr,
*m_right = nullptr;
wxSplitterWindow* m_splitter;
wxWindow *m_replacewindow;
int m_sashPos;
bool m_lockSash;
bool m_allowDClick;
wxSplitterWindow* m_splitter = nullptr;
wxWindow *m_replacewindow = nullptr;
int m_sashPos = 0;
bool m_lockSash = false;
bool m_allowDClick = true;
wxDECLARE_EVENT_TABLE();
wxDECLARE_NO_COPY_CLASS(MyFrame);
@ -225,13 +226,8 @@ wxEND_EVENT_TABLE()
// My frame constructor
MyFrame::MyFrame()
: wxFrame(nullptr, wxID_ANY, "wxSplitterWindow sample",
wxDefaultPosition, wxSize(420, 300))
: wxFrame(nullptr, wxID_ANY, "wxSplitterWindow sample")
{
m_lockSash = false;
m_sashPos = 0;
m_allowDClick = true;
SetIcon(wxICON(sample));
#if wxUSE_STATUSBAR
@ -334,14 +330,14 @@ MyFrame::MyFrame()
m_splitter->Initialize(m_left);
#else
// you can also try -100
m_splitter->SplitVertically(m_left, m_right, 100);
m_splitter->SplitVertically(m_left, m_right, FromDIP(100));
#endif
#if wxUSE_STATUSBAR
SetStatusText("Min pane size = 0", 1);
#endif // wxUSE_STATUSBAR
m_replacewindow = nullptr;
SetInitialSize(FromDIP(wxSize(420, 300)));
}
MyFrame::~MyFrame()
@ -625,13 +621,13 @@ void MyCanvas::OnDraw(wxDC& dcOrig)
wxMirrorDC dc(dcOrig, m_mirror);
dc.SetPen(*wxBLACK_PEN);
dc.DrawLine(0, 0, 100, 200);
dc.DrawLine(wxPoint(0, 0), dc.FromDIP(wxPoint(100, 200)));
dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
dc.DrawText("Testing", 50, 50);
dc.DrawText("Testing", dc.FromDIP(wxPoint(50, 50)));
dc.SetPen(*wxRED_PEN);
dc.SetBrush(*wxGREEN_BRUSH);
dc.DrawRectangle(120, 120, 100, 80);
dc.DrawRectangle(dc.FromDIP(wxPoint(120, 120)), dc.FromDIP(wxSize(100, 80)));
}

View file

@ -531,9 +531,14 @@ void wxSplitterWindow::OnSize(wxSizeEvent& event)
void wxSplitterWindow::OnDPIChanged(wxDPIChangedEvent& event)
{
// On platforms requiring scaling by DPI factor we need to do it whenever
// DPI changes, but elsewhere we shouldn't do it as the same logical
// coordinates are used irrespectively of the current DPI value.
#ifndef wxHAS_DPI_INDEPENDENT_PIXELS
m_minimumPaneSize = event.ScaleX(m_minimumPaneSize);
m_sashPosition = event.ScaleX(m_sashPosition);
m_lastSize = event.Scale(m_lastSize);
#endif // !wxHAS_DPI_INDEPENDENT_PIXELS
event.Skip();
}