# Choosing a Sizer

**URL:** <https://www.ruby-forum.com/t/choosing-a-sizer/137291>\
**Category:** wxRuby\
**Created:** [May 11, 2008, 2:26pm UTC](https://www.ruby-forum.com/t/choosing-a-sizer/137291 "2008-05-11T14:26:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yvon\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/ecc23a/32.png) [@Yvon\_T](https://www.ruby-forum.com/u/Yvon_T)\
**Post date:** [May 11, 2008, 2:26pm UTC](https://www.ruby-forum.com/t/choosing-a-sizer/137291/1 "2008-05-11T14:26:21Z")

</div>

Following alex advices, i’ve used both “text/textctrl.rb” and  
“etc/threaded.rb” to build my first wxApp.  
I’ve changed the Sizer type mainly (from “Wx::BoxSizer” to  
“Wx::FlexGridSizer”).  
I didn’t find the way to let @log (Wx::TextCtrl) span 2 columns. At the  
time  
of writing it’s growing only vertically.  
And also how to get 16px filler|spacer|border (for window resizer,  
bottom-right corner, on Mac OS X) for SOUTH and EAST and 5/16 px for  
NORTH  
and WEST

What i want as a layout;  
±—  
5/16 px  
|

±------------------------------------------------------------------v----------+

> | |\<-- 5/16  
> px |  
> | [Fixed length Wx::Button] [ \<---------- Growable Wx::Gauge  
> ----^-----\> ] |

|  
|  
|  
±-----------------------------------------------------------------------+  
|  
| |  
^ | |  
| |  
| | |  
| |  
| | |  
| | \<------------------ Growable Wx::TextCtrl -----------------\>

> | |\<-- 16 px  
> | |  
> | | |  
> | |  
> | | |  
> | |  
> V | |  
> |  
> ±---------------------------------------------------------------v-------+  
> |

|  
|

±-----------------------------------------------------------------------------+  
^  
|  
±—  
16 px

What i get:

±-----------------------------------------------------------------------------+  
|  
|  
| [Fixed length Wx::Button] [ \<---------- Growable Wx::Gauge ----------\>  
] |  
|  
|  
|  
±------------------------+  
|  
| | ^  
| |  
| | |  
| |  
| | |  
| |  
| |Fixed width Wx::TextCtrl  
| |  
| | |  
| |  
| | |  
| |  
| | V  
| |  
|  
±------------------------+  
|  
|  
|  
±-----------------------------------------------------------------------------+

What i’ve cut’n paste as code:

The sizer:

```
sizer = Wx::FlexGridSizer.new( 2, 2, 5, 5)
sizer.add_growable_col( 1, 1)
sizer.add_growable_row( 1, 1)

```

Three items added:

```
@button = Wx::Button.new(panel, :label => 'Export')
sizer.add(button, 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2 )

@gauge = Wx::Gauge.new(panel, :range => STEPS)
sizer.add(@gauge, 0, Wx::GROW|Wx::ALL, 2)

@log = LogTextCtrl.new(panel) # (LogTextCtrl < Wx::TextCtrl)
sizer.add(@log, 1, Wx::GROW|Wx::ALL, 2)

```

Yvon

---

<div class="post-metadata">

**Author:** ![Yvon\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/ecc23a/32.png) [@Yvon\_T](https://www.ruby-forum.com/u/Yvon_T)\
**Post date:** [May 11, 2008, 3:46pm UTC](https://www.ruby-forum.com/t/choosing-a-sizer/137291/2 "2008-05-11T15:46:17Z")

</div>

Hello Yvon,

In this example, my suggestion would be to throw away FlexGridSizer, and  
actually use a couple of BoxSizers to get your desired effect. Here’s  
how I  
would do it:

vsizer = Wx::BoxSizer.new(Wx::VERTICAL)  
hsizer = Wx::BoxSizer.new(Wx::HORIZONTAL)

# … create your controls …

hsizer.add(@button,0,Wx::ADJUST\_MINSIZE|Wx::ALL,2)  
hsizer.add(@guage,1,Wx::GROW|Wx::ALL,2)  
vsizer.add(hsizer,0,Wx::EXPAND|Wx::ALL,2)  
vsizer.add(@log,1,Wx::GROW|Wx::ALL,2)  
self.set\_sizer(vsizer)

This will create the desired effect that you want, hope this helps.

L8ers,

---

<div class="post-metadata">

**Author:** ![Yvon\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/ecc23a/32.png) [@Yvon\_T](https://www.ruby-forum.com/u/Yvon_T)\
**Post date:** [May 11, 2008, 3:57pm UTC](https://www.ruby-forum.com/t/choosing-a-sizer/137291/3 "2008-05-11T15:57:28Z")

</div>

Yvon T. wrote:

> Following alex advices, i’ve used both “text/textctrl.rb” and  
> “etc/threaded.rb” to build my first wxApp.  
> I’ve changed the Sizer type mainly (from “Wx::BoxSizer” to  
> “Wx::FlexGridSizer”).

Yeah, ditto what Mario suggested. I think 95% of the time it is easier  
and more manageable to nest BoxSizers within one another to get complex  
layouts than it is to use FlexGrid or GridBag. Sizers take few resources  
so that’s not a problem. I’ve written quite a lot of wxRuby code and I  
don’t think I’ve ever used anything but BoxSizer/StaticBoxSizer and the  
occasional specialist sizer like Grid or StdDialogButtonSizer.

Aside from the documentation, a good way to get a feel for the way sizer  
options work together is to look at the “wxSizer.rbw” demo inside  
“bigdemo”, or to use a GUI designer like DialogBlocks where you can see  
the effect of switching on and off individual options immediately.

alex

---

<div class="post-metadata">

**Author:** ![Yvon\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/ecc23a/32.png) [@Yvon\_T](https://www.ruby-forum.com/u/Yvon_T)\
**Post date:** [May 11, 2008, 7:41pm UTC](https://www.ruby-forum.com/t/choosing-a-sizer/137291/4 "2008-05-11T19:41:53Z")

</div>

2008/5/11 Mario S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> hsizer.add(@button,0,Wx::ADJUST\_MINSIZE|Wx::ALL,2)  
> hsizer.add(@guage,1,Wx::GROW|Wx::ALL,2)  
> vsizer.add(hsizer,0,Wx::EXPAND|Wx::ALL,2)  
> vsizer.add(@log,1,Wx::GROW|Wx::ALL,2)  
> self.set\_sizer(vsizer)
> 
> This will create the desired effect that you want, hope this helps.
> 
> L8ers,

hey mario,

thanks for the tips !  
i’ll try that asap…

in fact i’ve added another FlexGridSizer with something like 9  
spacers…  
this is too much  
i was not so far of the desired result :  
[http://cjoint.com/data/fltHDvhhzl.htm](http://cjoint.com/data/fltHDvhhzl.htm)

except the Wx::Gauge which is not aligned verticaly to the Wx::Button on  
it’s left, i’ve tried :  
@gauge = Wx::Gauge.new(panel, :range =\> STEPS)  
#sizer\_top.add(@gauge, 0, Wx::GROW|Wx::ALL, 2)  
#sizer\_top.add(@gauge, 0, Wx::GROW|Wx::ALL|Wx::ALIGN\_BOTTOM, 2)  
sizer\_top.add(@gauge, 0, Wx::GROW|Wx::ALL|Wx::ALIGN\_CENTER\_VERTICAL,  
2)

without visible effect.

yvon

---

<div class="post-metadata">

**Author:** ![Yvon\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/ecc23a/32.png) [@Yvon\_T](https://www.ruby-forum.com/u/Yvon_T)\
**Post date:** [May 11, 2008, 7:46pm UTC](https://www.ruby-forum.com/t/choosing-a-sizer/137291/5 "2008-05-11T19:46:36Z")

</div>

2008/5/11 Alex F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> than it is to use FlexGrid or GridBag. Sizers take few resources so that’s

ok, i’ll follow mario’s advices and look further to “wxSizer.rbw”, my  
idae  
of using two Wx::FlexGridSizer with a lot of spacers isn’t the right  
solution.

best,

yvon
