sizers and a menu bar

Daniel C. Bastos dbast0s at yahoo.com.br
Sun Jun 17 09:43:48 PDT 2007


Hi there wx community.

I built a chess board, and I wanted the window (the main frame) to have
the same dimensions as the board. The board is painted on a panel. The
panel constructor sets the dimensions. When I run the application, I can
see that the frame did get the size of the panel; and, as I wanted, you
cannot resize the frame to something less than the size of the
panel. However, if I add a menu bar, then the initial frame size is a
little less than the panel size. Now ``little less'' seems to be exactly
the height of the menu bar.

Notice my comments; they might show my ignorance with sizers. I'm
following Julian Smart and Kevin Hock and Stefan Csomor's book advice to
persevere on sizers; that it will be worth. Any help is appreciated.

%wx-config --version
2.8.0

I see the same behavior in wxMSW and in wxX11.

Frame::Frame(wxFrame *fr, const wxChar* title)
  : wxFrame(fr, wxID_ANY, title)
{
  // define size of pieces, and board dimensions
  pxSquare = 44; nWid = nHei = 8; 

  // define pen width for board painting
  penWidth = 1;

  // create the panel
  pan = new Panel(this, 0, 0, szSquare() * dimWid(), szSquare() * dimHei());

  #if USE_STATUS_BAR
  CreateStatusBar(1); SetStatusText(wxT("Pinky is ready."));
  #endif

  // let's put a sizer on this frame and attach the panel to it
  wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
  
  // take the exact size of the panel
  topSizer->Add(pan, 0, 0, 0);

  // attach this sizer to the frame
  SetSizer(topSizer);

  // fit the frame to the panel
  topSizer->Fit(this);

  // dont get smaller than the panel
  topSizer->SetSizeHints(this);
}

The relevant code of my panel should be just this:

Panel::Panel(Frame *f, int x, int y, int w, int h)
  : wxPanel((wxWindow*) f , wxID_ANY, wxPoint(x, y), wxSize(w, h))
{

   (...)

  // we'll handle the background ourselves
  SetBackgroundStyle(wxBG_STYLE_CUSTOM);
}






More information about the wx-users mailing list