When looking into the topic, on Windows I encountered something I think may be a bug (Windows 10, wxWidgets master)?
The code draws a logo in the top left corner, which is not scrolled with the controls. When I do not call EnableScrolling(false, false), there are drawing artifacts. This is expected because Windows will just move the window area including the bitmap. So EnableScrolling(false, false) has to be called.
However when EnableScrolling(false, false) is called, the controls are not properly redrawn after the scrolling. They scrolling result shows only after I resize the frame. I find this unexpected, I believe calling EnableScrolling() should not have any effect on this. The issue is present regardless of binding the paint event or creating m_scrolled with wxFULL_REPAINT_ON_RESIZE, only EnableScrolling() call affects this.
Code: Select all
#include <wx/wx.h>
#include <wx/artprov.h>
#include <wx/scrolwin.h>
class MyFrame: public wxFrame
{
public:
MyFrame() : wxFrame (nullptr, wxID_ANY, "Test")
{
wxSizer* scrolledSizer = new wxBoxSizer(wxVERTICAL);
m_scrolled = new wxScrolledWindow(this);
for ( size_t i = 0; i < 50; ++i )
scrolledSizer->Add(new wxButton(m_scrolled, wxID_ANY, wxString::Format("Button %zu", i)), wxSizerFlags().Center().Border());
m_scrolled->SetSizer(scrolledSizer);
m_scrolled->FitInside();
m_scrolled->SetScrollRate(16, 16);
#if 1
m_scrolled->EnableScrolling(false, false);
#endif
m_scrolled->Bind(wxEVT_PAINT, &MyFrame::OnPaintScrolled, this);
m_logoBitmap = wxArtProvider::GetBitmap(wxART_INFORMATION);
}
private:
wxBitmap m_logoBitmap;
wxScrolledWindow* m_scrolled;
void OnPaintScrolled(wxPaintEvent&)
{
wxPaintDC dc(m_scrolled);
dc.DrawBitmap(m_logoBitmap, 0, 0);
}
};
class MyApp : public wxApp
{
public:
bool OnInit() override
{
(new MyFrame())->Show();
return true;
}
}; wxIMPLEMENT_APP(MyApp);
EDIT
The same happens on Ubuntu and reading EnableScrolling() docs, I may have misunderstood what it does. I thought it basically only speeds-up drawing by reusing the scrolled part of the window and drawing only the newly uncovered one.
EDIT2
On Ubuntu, there are no artifacts even without calling EnableScrolling(false, false). I guess it does not do what ScrollWindowEx() does on MSW, i.e., reusing the scrolled part?
EDIT3
It was bugging me so I asked in wx-users:
https://groups.google.com/u/1/g/wx-users/c/9Ww1ACmJG4k
EDIT4
Based on the answer from the "main" wxWidgets developer, this may not be possible:
https://groups.google.com/g/wx-users/c/ ... B9FPMIBQAJ