Reputation: 96
I'm new in wxWidgets so I'm trying to make the window like in CMake GUI. How can I divide the area into two self-resizable areas:
I'm using linux for development & cmake. I'm not using any UI editor
PS: Sory for my English, It's not my native lang :o
Upvotes: 0
Views: 139
Reputation: 3554
The way to create a frame where the elements expand like in CMake GUI is to use a wxSplitterWindow together with sizers and use the proportion in sizer flags constructor to specify how much each item should expand.
Here's a short example:
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWidgets headers)
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include <wx/splitter.h>
class MyFrame: public wxFrame
{
public:
MyFrame();
};
MyFrame::MyFrame()
:wxFrame(NULL, wxID_ANY, "CMake style frame", wxDefaultPosition,
wxSize(600, 400))
{
wxSplitterWindow* splitter = new wxSplitterWindow(this, wxID_ANY,
wxDefaultPosition, wxDefaultSize,
wxSP_LIVE_UPDATE);
wxPanel* top = new wxPanel(splitter,wxID_ANY);
wxStaticText* statText1 = new wxStaticText(top, wxID_ANY,
"Where is the source");
wxTextCtrl* textCtrl1 = new wxTextCtrl(top, wxID_ANY, wxEmptyString);
wxButton* button1 = new wxButton(top, wxID_ANY, "Browse Source...");
wxBoxSizer* sizer2 = new wxBoxSizer(wxHORIZONTAL);
sizer2->Add(statText1,wxSizerFlags(0).Centre());
sizer2->Add(textCtrl1,wxSizerFlags(1).Border(wxLEFT));
sizer2->Add(button1,wxSizerFlags(0).Border(wxLEFT));
wxStaticText* statText2 = new wxStaticText(top ,wxID_ANY, "Where to build the binaries:");
wxStaticText* statText3 = new wxStaticText(top, wxID_ANY, "Search:");
wxTextCtrl* textCtrl2 = new wxTextCtrl(top, wxID_ANY, wxEmptyString,
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE|wxTE_DONTWRAP);
wxStaticText* statText4 = new wxStaticText(top, wxID_ANY, "Press Configure:");
wxButton* button2 = new wxButton(top, wxID_ANY, "Configure");
wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
// Now Add the items to the backfround panel's sizer:
topSizer->Add(sizer2,wxSizerFlags(0).Expand().DoubleBorder(wxALL));
topSizer->Add(statText2,wxSizerFlags(0).DoubleBorder(wxLEFT|wxRIGHT|wxBOTTOM));
topSizer->Add(statText3,wxSizerFlags(0).DoubleBorder(wxLEFT|wxRIGHT|wxBOTTOM));
// The next item is added with proportion 1 so that it will expand in size.
topSizer->Add(textCtrl2,
wxSizerFlags(1).Expand().DoubleBorder(wxLEFT|wxRIGHT|wxBOTTOM));
topSizer->Add(statText4,
wxSizerFlags(0).Center().DoubleBorder(wxLEFT|wxRIGHT|wxBOTTOM));
topSizer->Add(button2,wxSizerFlags(0).DoubleBorder(wxLEFT|wxRIGHT));
top->SetSizer(topSizer);
wxPanel* botton = new wxPanel(splitter,wxID_ANY);
wxTextCtrl* textCtrl3 = new wxTextCtrl(botton, wxID_ANY, wxEmptyString,
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE|wxTE_DONTWRAP);
wxBoxSizer* botomSizer = new wxBoxSizer(wxVERTICAL);
botomSizer->Add(textCtrl3,
wxSizerFlags(1).Expand().DoubleBorder(wxLEFT|wxRIGHT|wxBOTTOM));
botton->SetSizer(botomSizer);
// Add the top and bottom parts to the splitter, and set the sash gravity to
// .5 so that both halfs will expand equally when the frame is resized.
splitter->SplitHorizontally(top,botton);
splitter->SetSashGravity(.5);
Layout();
}
class MyApp : public wxApp
{
public:
virtual bool OnInit()
{
::wxInitAllImageHandlers();
MyFrame* frame = new MyFrame();
frame->Show();
return true;
}
};
wxIMPLEMENT_APP(MyApp);
On windows, this looks like this:
I haven't copied every widget from the CMake GUI frame, but I think there's enough there to give the idea of what's going on.
Upvotes: 2