Skip to content

Instantly share code, notes, and snippets.

@PBfordev
Created April 11, 2021 12:12
Show Gist options
  • Select an option

  • Save PBfordev/734fb2bc3cdedd5d8254bbb922cc985a to your computer and use it in GitHub Desktop.

Select an option

Save PBfordev/734fb2bc3cdedd5d8254bbb922cc985a to your computer and use it in GitHub Desktop.
#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, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxFULL_REPAINT_ON_RESIZE);
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 0
m_scrolled->EnableScrolling(false, false);
#endif
m_scrolled->Bind(wxEVT_PAINT, &MyFrame::OnPaintScrolled, this);
m_logoBitmap = wxArtProvider::GetBitmap(wxART_INFORMATION);
}
private:
wxScrolledWindow* m_scrolled;
wxBitmap m_logoBitmap;
void OnPaintScrolled(wxPaintEvent&)
{
wxPaintDC dc(m_scrolled);
wxPoint topLeft;
m_scrolled->DoPrepareDC(dc);
topLeft = m_scrolled->CalcUnscrolledPosition(wxPoint(0,0));
dc.DrawBitmap(m_logoBitmap, topLeft);
}
};
class MyApp : public wxApp
{
public:
bool OnInit() override
{
(new MyFrame())->Show();
return true;
}
}; wxIMPLEMENT_APP(MyApp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment