c++wxwidgetswxformbuilder

How to add a wxPanel to a Frame in wxFormBuilder without AUI manager


I'm currently learning wxWidgets that I'm finding quite flexible so far. However, when I move to wxFormBuilder in order to create more complex UI, it becomes painful. Let me give you a quick example that builds just fine in Visual Studio 2022 (just putting the MainFrame.cpp here):

#include "MainFrame.h"
#include <wx/wx.h>
#include <vector>

MainFrame::MainFrame(const wxString& title) : wxFrame(nullptr, wxID_ANY, title)
{
    wxPanel* panel = new wxPanel(this);
    wxButton* button = new wxButton(panel, wxID_ANY, "Button", wxPoint(300, 275), wxSize(200, 50));
}

When I'm trying to create the same in wxFormBuilder, it complains as soon as I want to add a panel to my main frame. It seems it absolutely wants me to use the AUI Manager. Without aui_managed selected for my frame, there's no way I can add any widget, whereas it is totally possible to implement while coding the app manually.

enter image description here

Am I missing something or is it a constraint in wxFormBuilder? When I select AUI Manager at Frame level, I can add widgets but I have to deal with a lot more complexity as widgets now come with AUI and a whole set of new properties. A simple button for instance comes with border, caption, close button etc. and I can't even attach it to the pane but only to the frame. I don't understand the rational of adding this constraint.


Solution

  • Of the current designers, only wxSmith (CodeBlocks) and wxUiEditor allow you to create a control as a direct child of a wxFrame window. wxCrafter and wxFormBuilder both require a parent sizer to place the control in.

    Creating a single control, such as a wxRichTextCtrl as the sole child of a wxFrame window works because it will fill the entire client area of the frame. However, if you place controls onto something like a wxPanel without using a sizer, then you run the risk of it not scaling correctly on high dpi displays, and controls with text may not be sized correctly on different platforms that use different default system fonts and point sizes. Using sizers to handle the layout of your controls ensures your UI will display correctly on all platforms and all screen resolutions.