I create a simple wxFrame based App, place a wxPanel on wxFrame, and then add a sizer and a button. the result layout is
The frame is much larger than the button. How can I make the frame fit to the button's size ?
What I expected is something like this:
I use wxWidgets 3.15, build with cmake
the code :
Code: Select all
#include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
class MyApp: public wxApp {
protected:
virtual bool OnInit();
};
class MyFrame:public wxFrame {
public:
MyFrame(const wxString &title);
};
MyFrame::MyFrame(const wxString &title): wxFrame(nullptr, wxID_ANY, title)
{
wxPanel *panel = new wxPanel(this, wxID_ANY);
wxButton *btn = new wxButton(panel, wxID_ANY, "Button");
wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
sizer->Add(btn, wxSizerFlags(0).Align(wxALIGN_CENTER_HORIZONTAL).Border());
panel->SetSizer(sizer);
sizer->SetSizeHints(this);
}
bool MyApp::OnInit() {
wxFrame *frame = new MyFrame("MyFrame");
frame->Show();
return true;
}
wxIMPLEMENT_APP(MyApp);