私は教育目的でいくつかのwxWidgetsサンプルを書いています。私の問題は単純です。wxNotebookを使用しています。単一のタブの現在のサイズ、特に高さを取得するには、いくつかのトリックが必要です。簡単に言うと、たとえば、彼のwxMenubar(明らかに高さで発生する)を持つwxFrame内にwxNotebookを配置すると、タブの高さの値のみが取得され、wxMenubarのサイズも含まれるwxFrameの高さの値は取得されません。 。新しいコンポーネントを適切に中央に配置するには、この情報が必要です。
例については、以下のサンプルコードを参照してください。
#include "wx/wx.h"
#include "wx/gbsizer.h"
class MyFrame : public wxFrame
{
public:
MyFrame() : wxFrame(NULL, wxID_ANY, wxT("Application"), wxDefaultPosition, wxSize(500, 300))
{
wxNotebook *tabs = new wxNotebook(this, wxID_ANY, wxPoint(-1,-1), wxSize(-1,-1), wxNB_TOP);
wxPanel *extPanel = new wxPanel(tabs, wxID_ANY); // external panel will be directly added to wxNotebook
wxPanel *innerPanel = new wxPanel(extPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize); /* for now, innerPanel has default size */
innerPanel->SetBackgroundColour(wxColor(0, 0, 255)); // I change background color for debug only
innerPanel->SetMinSize(wxSize(200, 200)); // I use SetMinSize() method to communicate to the sizer _required_ size for the panel
wxGridBagSizer *gbs = new wxGridBagSizer(3, 3); // I use a wxGridBagSizer to position one panel inside external
/* **** THE FOLLOWING IS THE CRITICAL LINE **** */
wxSize mainSize = this->GetSize(); /* for now, I get the _wxFRAME_ wxSize; I would get wxNOTEBOOK size instead */
wxSize innPSize = innerPanel->GetMinSize(); // I get current (Min)Size of innerPanel
wxSize emptyCellSize((mainSize.GetWidth() - innPSize.GetWidth()) / 2, (mainSize.GetHeight() - innPSize.GetHeight()) / 2);
gbs->SetEmptyCellSize(emptyCellSize); // I Use SetEmptyCellSize() method to center the inner panel
gbs->Add(innerPanel, wxGBPosition(1, 1)); // 1, 1: central cell
extPanel->SetSizer(gbs);
tabs->AddPage(extPanel, wxT("Positioning test"));
Show(true);
}
};
class MyApp : public wxApp
{
public:
virtual bool OnInit()
{
MyFrame *frame = new MyFrame();
}
};
IMPLEMENT_APP(MyApp);
ご覧のとおり、レイアウトは不完全です。ps wxGridBagSizerを使用してコンポーネントを中央に配置する別のより効率的な方法を知っている場合は、私に知らせてください。