resizing widgets within a window without resizing the window itself 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
oguzakyuz
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Jun 14, 2012 6:10 am

resizing widgets within a window without resizing the window itself

Post by oguzakyuz »

Here is my situation: I've a frame which has a main sizer, which in turn includes a top and bottom sizer (all of which are box sizers). It looks like this:

Code: Select all

------------------------------------------------
|             Top Region                        |
-------------------------------------------------
|           |                                   |
|           |                                   |
|   Left    |           Right                   |
|           |                                   |
|           |                                   |
|           |                                   |
-------------------------------------------------
What I want is to allow the user to resize the left-right region without resizing the main window. I want to have something like this:

Code: Select all

------------------------------------------------
|             Top Region                        |
-------------------------------------------------
|                   |                           |
|                   |                           |
|   Left            |           Right           |
|                   |                           |
|                   |                           |
|                   |                           |
-------------------------------------------------
This is actually a pretty typical situation. For instance, when we open the file browser in gnome (or most other window managers), you can resize the region on the left that shows the commonly used folders.

What would be the wx approach to achieve this behavior?

Thanks for any help,
New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 469
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Re: resizing widgets within a window without resizing the window itself

Post by New Pagodi »

I think the control you're trying to describe is wxSplitterWindow. Here's a basic sample that I think gives the behavior you're describing.

Code: Select all

// 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( wxWindow* parent, int id = wxID_ANY, wxString title = "Demo",
                 wxPoint pos = wxDefaultPosition, wxSize size = wxDefaultSize,
                 int style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
};

MyFrame::MyFrame( wxWindow* parent, int id, wxString title, wxPoint pos,
                  wxSize size, int style )
        :wxFrame( parent, id, title, pos, size, style )
{
    int topWindowHeight = 100;
    int leftWindowWidth = 150;

    wxPanel* panel1 = new wxPanel( this, wxID_ANY );
    wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );

    wxPanel* panel2 = new wxPanel( panel1, wxID_ANY, wxDefaultPosition,
                                   wxSize(-1,topWindowHeight) );
    panel2->SetBackgroundColour(*wxRED);
    bSizer->Add( panel2, 0, wxEXPAND | wxALL, 5 );

    wxSplitterWindow* splitter = new wxSplitterWindow( panel1 );

    wxPanel* panel3 = new wxPanel( splitter, wxID_ANY );
    panel3->SetBackgroundColour(*wxGREEN);
    wxPanel* panel4 = new wxPanel( splitter, wxID_ANY );
    panel4->SetBackgroundColour(*wxBLUE);
    splitter->SplitVertically( panel3, panel4, leftWindowWidth );
    bSizer->Add( splitter, 1, wxEXPAND| wxLEFT|wxRIGHT|wxBOTTOM, 5 );

    panel1->SetSizer( bSizer );
    panel1->Layout();
}

class MyApp : public wxApp
{
    public:
        virtual bool OnInit()
        {
            MyFrame* frame = new MyFrame(NULL);
            frame->Show();
            return true;
        }
};

wxIMPLEMENT_APP(MyApp);
This produces a frame like this:
splitter.png
splitter.png (2.36 KiB) Viewed 993 times
I've colored the 3 areas red, green, and blue; but obviously that's not a necessary step.
oguzakyuz
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Jun 14, 2012 6:10 am

Re: resizing widgets within a window without resizing the window itself

Post by oguzakyuz »

Thank you, this was exactly what I was looking for.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: resizing widgets within a window without resizing the window itself

Post by ONEEYEMAN »

New Pagodi,
You didn't have to provide the code.
wxWidgets provides the spliter sample in their sample folder.

Thank you.
Post Reply