Garbaged layout: sizers with wxPanel (still a wxNewbe();) Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
smf
Knows some wx things
Knows some wx things
Posts: 32
Joined: Wed Nov 12, 2008 7:04 pm

Garbaged layout: sizers with wxPanel (still a wxNewbe();)

Post by smf »

Hi folks,

with the code below, I get some garbage "Layout" ... Like all widgets rendered all over each other at position (0,0)...

Only if I manually resize the frame, then I get the desired layout. This completely puzzels me... I suspect it could be something with the parentship of some widgets, but what?

I hope anyone can help me out of this (and explain me, what I am doing wrong, here... *sigh*)

cu
Stefan

Code: Select all

playlist_frame::playlist_frame(wxFrame *frame, const wxString& title)
    :wxFrame((wxFrame *)NULL, wxID_ANY, title,
           wxDefaultPosition, wxSize(10, 10) )
{
    // init dragging state
    is_dragging=false;

    // init/reset drag_to_index to "NO_DRAGGING"
    drag_to_index = -1;

    // init current active item with -1 so no accidents can happen...
    current_active_index = -1;

    // ========================================================================
    // Setup widget-containers
    // ========================================================================

    //wxBoxSizer* my_top_sizer = new wxBoxSizer(wxVERTICAL);

    wxPanel*    my_panel            = new wxPanel( this );
    wxBoxSizer* my_panel_sizer      = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* my_listctrl_sizer   = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* my_button_sizer     = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* my_ctrlpanel_sizer  = new wxBoxSizer(wxVERTICAL);

    // ========================================================================
    // Setup ListCTRL-widget
    // ========================================================================

    // Create new wxListCtrl and add to my_listctrl-sizer (parent: my_panel)
    my_listctrl = new wxListCtrl(my_panel,
        ID_LISTCTRL,
        wxDefaultPosition,
        wxSize(1024,600),
        wxLC_REPORT|wxLC_SINGLE_SEL|wxLC_HRULES|wxLC_VRULES,
        wxDefaultValidator,
        _("nameoflistctrl") );

    // Setup ListCtrl as a Drop-Target
    my_listctrl->SetDropTarget(new file_drop(my_listctrl));

    // Setup Columns
    my_listctrl->InsertColumn(0, _("Filename"), wxLIST_FORMAT_LEFT, 200);
    my_listctrl->InsertColumn(1, _("Col2"), wxLIST_FORMAT_LEFT, 120);
    my_listctrl->InsertColumn(2, _("Col3"), wxLIST_FORMAT_LEFT, 100);
    my_listctrl->InsertColumn(3, _("Col4"), wxLIST_FORMAT_LEFT, 100);
    my_listctrl->InsertColumn(4, _("Col5"), wxLIST_FORMAT_LEFT, 500);

    // add listcontrol to listctrl-sizer
    my_listctrl_sizer->Add( my_listctrl,
        1,                  // allow vertical resize
        0
        | wxEXPAND          // allow horizontal resize
        | wxALL,            // set border-spacing to 4px all arround
        4);

    // setup button-sizer with some buttons and a checkbox (parent is my_panel!)
    my_button_sizer->Add( new wxButton( my_panel, ID_BUTTON_DELETE, _("Delete Entry") ),
        0,
        0
        | wxALL,
        4);
    my_button_sizer->AddStretchSpacer( 1 );
    checkbox_relative = new wxCheckBox( my_panel, ID_CHECKBOX_RELATIVE,
                        _("Save pathes relative to playlist") );
    my_button_sizer->Add( checkbox_relative ,
        0,
        0
        | wxALL,
        4);
    my_button_sizer->AddStretchSpacer( 1 );
    my_button_sizer->Add( new wxButton( my_panel, ID_BUTTON_SAVE, _("Save Playlist") ),
        0,
        0
        | wxALL,
        2);
    my_button_sizer->Add( new wxButton( my_panel, ID_BUTTON_LOAD, _("Load Playlist") ),
        0,
        0
        | wxALL,
        4);
    my_button_sizer->Add( new wxButton( my_panel, ID_BUTTON_LOADFILE, _("Load File(s)") ),
        0,
        0
        | wxALL,
        4);

    // Setup controls-sizer
    wxStaticBoxSizer* static_box_sizer = new wxStaticBoxSizer( wxVERTICAL, my_panel, _("File properties") );

    my_ctrlpanel_sizer->Add( static_box_sizer,
        0,
        0
        | wxALL,
        4);
    static_box_sizer->Add( new wxButton( my_panel, ID_BUTTON_SAVE, _("Test -> Save Playlist") ),
        0,
        0
        | wxALL,
        4);

    // Add listctrl_sizer to panel_sizer
    my_panel_sizer->Add( my_listctrl_sizer,
        1,                  // allow vertical resize
        0
        | wxEXPAND          // allow horizontal resize
        | wxALL,            // set border-spacing to 4px all arround
        4);

    // Add ctrlpanel_sizer to panel_sizer
    my_panel_sizer->Add( my_ctrlpanel_sizer,
        0,                  // do not allow vertical resize
        0
        | wxEXPAND          // allow horizontal resize
        | wxALL,            // set border-spacing to 4px all arround
        4);

    // Add button_sizer to panel_sizer
    my_panel_sizer->Add( my_button_sizer,
        0,                  // do not allow vertical resize
        0
        | wxEXPAND          // allow horizontal resize
        | wxALL,            // set border-spacing to 4px all arround
        4);

    // Honour minimum size of all contents of the panel-sizer
    my_panel_sizer->SetSizeHints(this);

    // Set base-sizer for panel, then fit and layout
    my_panel->SetSizerAndFit( my_panel_sizer );
}
smf
Knows some wx things
Knows some wx things
Posts: 32
Joined: Wed Nov 12, 2008 7:04 pm

Re: Garbaged layout: sizers with wxPanel (still a wxNewbe();

Post by smf »

Argh... found it...

SetSizerAndFit() does not imply a Layout()...


cu
Stefan
Post Reply