sizer help 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
jcfuller
Knows some wx things
Knows some wx things
Posts: 33
Joined: Sat May 01, 2010 1:27 pm

sizer help

Post by jcfuller »

As a Windows programer using resource dialogs for 90% of my former code I am struggling with wxWidgets sizers.

I am trying to create this:

Code: Select all

 ------------       -------------------------------------------------
|   button   |     |                                                 |
 ------------      |                                                 |
 ------------      |              Multi Line Edit Control            |
|   button   |     |                                                 |
 ------------      |                                                 |
 ------------      |                                                 |
|   button   |     |                                                 |
 ------------       -------------------------------------------------

 ------------
|   button   |
 ------------
 ------------
|   button   |
 ------------

 ------------       -------------------------------------------------
|   button   |     |                                                 |
 ------------      |                                                 |
 ------------      |              Multi Line Edit Control            |
|   button   |     |                  (Read Only)                    |
 ------------      |                                                 |
 ------------      |                                                 |
|   button   |     |                                                 |
 ------------       -------------------------------------------------
The top three and bottom three buttons are associated with the Edit controls
The edit controls should grow and shrink both height and width.
The placement of the buttons could also be on the right. I just assumed it would be
easier to do with them on the left?

Any help would be appreciated.

James
orbitcowboy
I live to help wx-kind
I live to help wx-kind
Posts: 178
Joined: Mon Jul 23, 2007 9:01 am

Post by orbitcowboy »

i recommend to use wxFormBuilder for this:

http://wxformbuilder.org/

Hope it helps

Orbitcowboy
OS: Ubuntu 9.04 (32/64-Bit), Debian Lenny (32-Bit)
Compiler: gcc/g++-4.3.3 , gcc/g++-4.4.0
wxWidgets: 2.8.10,2.9.0
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

I'm not sure exactly where you're having issues, so my answer may be a bit off.

Here's the layout I'd envision :

Code: Select all

// this is not real code, only an outline
wxBoxSizer(wxHORIZONTAL)
{
    wxBoxSizer(wxVERTICAL, proportion=0, wxEXPAND)
    {
        button 1
        button 2
        ...
    }
    wxBoxSizer(wxVERTICAL, proportion=1, wxEXPAND)
    {
        edit control 1 (proportion=1)
        edit control 2 (proportion=1)
    }
}

unless you want the buttons to be aligned precisely by groups next to the text controls. Then wxFlexGridSizer should be used instead
"Keyboard not detected. Press F1 to continue"
-- Windows
jcfuller
Knows some wx things
Knows some wx things
Posts: 33
Joined: Sat May 01, 2010 1:27 pm

Post by jcfuller »

Auria,
Yes I do want the buttons aligned with the text controls.
I am using a translator BcxWx (basic -> c++) and have translated all the code from zetcode.com but I still can't get a good grip on sizers.
I've just bitten off more than I can chew it appears. At my age this happens quite often lately.

I have looked at wxFormbuilder but I have no use for the c++ code so it's not worth the effort or time to learn it in my opinion. First impression is you need a GOOD wxWidget foundation just to understand how to use it. Not for a noob like me.

Thanks for taking the time guys

James
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Ok, then it will be more like

Code: Select all


// still pseudo-code
wxFlexGridSizer(2 cells horizontally, 3 cells vertically)
{
  wxBoxSizer(wxVERTICAL)
  {
    3 buttons here
  }
  wxTextCtrl
  {
  }

  wxBoxSizer(wxVERTICAL)
  {
    2 buttons here
  }
  [spacer]

  wxBoxSizer(wxVERTICAL)
  {
    3 buttons here
  }
  wxTextCtrl
  {
  }

}

This layout can be created quite quickly in wxFB too; just add a flex grid sizer of 2x3 cells then populate the cells
"Keyboard not detected. Press F1 to continue"
-- Windows
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Post by evstevemd »

orbitcowboy wrote:i recommend to use wxFormBuilder for this:

http://wxformbuilder.org/

Hope it helps

Orbitcowboy
I second that :D
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
jcfuller
Knows some wx things
Knows some wx things
Posts: 33
Joined: Sat May 01, 2010 1:27 pm

Post by jcfuller »

Ok I bit the bullet and fired up WxFB and surprise using Auria's pseudo-code I was able to get a start. I have the layout but I don't know where to go from here on setting the sizing rules. The Text controls should grow but he buttons should just move.

Is there a way to view actual sizing as the Frame grows or shrinks in WxFB? As I said I'm not using c++ directly although I believe I can use the generated c++ code but it's not something that is easy to do in the design phase.

James
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

start by setting which rows and columns of the flex grid sizer should grow (I hope you used a flex grid sizer and not a regular grid sizer). See the "growablecols" and "growablerows" property if in wxFB.

About growing, once you chose which rows and col grows, simply give the flag wxEXPAND to the contents of the grid in the said row that needs to expand to take the space
"Keyboard not detected. Press F1 to continue"
-- Windows
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »


Is there a way to view actual sizing as the Frame grows or shrinks in WxFB? As I said I'm not using c++ directly although I believe I can use the generated c++ code but it's not something that is easy to do in the design phase.
Yes, use the XRC preview (F5). It will show a warning because wxFB does not have full XRC support, but for what you're doing it should be fine.

EDIT: sorry for double-post, I wanted to click "EDIT" but clicked "reply" instead
"Keyboard not detected. Press F1 to continue"
-- Windows
jcfuller
Knows some wx things
Knows some wx things
Posts: 33
Joined: Sat May 01, 2010 1:27 pm

Post by jcfuller »

Thanks Auria. Got it!

James
Post Reply