Expand, Sizer and Panel Problem...

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
Tom82
Experienced Solver
Experienced Solver
Posts: 58
Joined: Wed May 11, 2005 7:45 am

Expand, Sizer and Panel Problem...

Post by Tom82 » Tue Aug 30, 2005 2:09 pm

Hi there,
i have really a problem Concerning Sizers...
i have a Panel witch is hanged into a wxBoxSizer.

i want:
The Panel should: take all the Space witch he can get.

i get:
the Panel makes: takes as less space as possible

http://thomash.typo3trial.de/fileadmin/ ... lKlein.jpg

i tried it to add it with flag wxEXPAND into a Box sizer.

greetings, tom
Developing for and with WinXp
wxWidgets 2.6.1
+ Jorg's wxTreeMultiCtrl
with VC++ 2003

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Tue Aug 30, 2005 2:23 pm

Hi, did you use the 1 for the proportional grow and wxEXPAND to tell the control to expand in the directions it can grow?

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

cg
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 201
Joined: Sun Aug 29, 2004 12:33 am
Location: Canada
Contact:

Post by cg » Tue Aug 30, 2005 2:27 pm

I just tested this in Chinook and it seems to give the effect your are describing:

Code: Select all

    wxPanel *p1 = new wxPanel(this, -1, wxDefaultPosition, wxSize(150,300));
    p1->SetBackgroundColour(wxColour("RED"));

    wxPanel *p2 = new wxPanel(this, -1);
    p2->SetBackgroundColour(wxColour("BLUE"));
    
    wxBoxSizer *siz0 = new wxBoxSizer(wxHORIZONTAL);    
    siz0->Add( p1, 0, wxEXPAND );
    siz0->Add( p2, 1, wxEXPAND );
    
    SetSizer(siz0);
HTH

Chris

------------------------------------------------------------
Chinook Developer Studio
*Free multiplatform IDE for BSD.Linux.Solaris.Windows*
http://www.degarrah.com/chinookfree.php

Zephyr Automated Test Runner
*Cross platform automated functional and regression testing*
http://www.degarrah.com/zephyr.php
------------------------------------------------------------

Tom82
Experienced Solver
Experienced Solver
Posts: 58
Joined: Wed May 11, 2005 7:45 am

Post by Tom82 » Tue Aug 30, 2005 2:38 pm

yes, i made

MidSizer->Add( panel_right, 1, wxEXPAND );

where Midsizer is the Sizer witch holds 2 Panels (left and right)


after adding it is possible that the panel_right points to another Panel.
(something like this:

Code: Select all

if( panel_right != NULL )
{
	delete panel_right;
}
 panel_right = new JournalScreen( main_panel, wxPoint( 230, 70 ), wxSize( m_w-250, m_h-150) );

but the panel doesn't keep the given size (i think it's because the Panel goes back to its minimum size )
Developing for and with WinXp
wxWidgets 2.6.1
+ Jorg's wxTreeMultiCtrl
with VC++ 2003

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Tue Aug 30, 2005 2:40 pm

Chris, do you mean my solution or from Tom's ?

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

Tom82
Experienced Solver
Experienced Solver
Posts: 58
Joined: Wed May 11, 2005 7:45 am

Post by Tom82 » Tue Aug 30, 2005 3:07 pm

strange.....

i think i undestand the principe of sizer less and less...


i thought this example code from chris:

Code: Select all

    wxPanel *p1 = new wxPanel(this, -1, wxDefaultPosition, wxSize(150,300));
    p1->SetBackgroundColour(wxColour(wxT("RED")));

    wxPanel *p2 = new wxPanel(this, -1);
    p2->SetBackgroundColour(wxColour(wxT("BLUE")));
   
    wxBoxSizer *siz0 = new wxBoxSizer(wxHORIZONTAL);   
    siz0->Add( p1, 0, wxEXPAND );
    siz0->Add( p2, 1, wxEXPAND );
   
    SetSizer(siz0);
would do the Following:
it would show a Blue screen, because p2 has proportion 1,
p1 has no chance to grow in size (0 ) and no controlls, so minimal Size would be wxSize(0,0).
P2 would tke the Whole space then, i thought.

the reallity was complettely different:
http://thomash.typo3trial.de/fileadmin/ ... trange.jpg
Developing for and with WinXp
wxWidgets 2.6.1
+ Jorg's wxTreeMultiCtrl
with VC++ 2003

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Tue Aug 30, 2005 3:47 pm

Hi!
This is a bit weird. Using Chris code the output should simply look like this
Image
as expected.

Maybe try using

Code: Select all

SetAutoLayout(true);
    SetSizer(siz0); 
    siz0->Fit(this);
    siz0->SetSizeHints(this);
    Layout();
Another thing that might help is using SetSizeHints() to setup the sizes for the panel and passing the wxFIXED_MINSIZE style when adding it to the sizer.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Tue Aug 30, 2005 5:54 pm

To understand sizers fully, download a copy of dialogblocks. Fiddle around with the parameters and check the code that is created. Even if you only use the evaluation version, you can study how it behaves and what you might have forgotten as flag.

Regards,
- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

Post Reply