Choosing a Sizer

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

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,

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

2008/5/11 Mario S. [email protected]:

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

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

2008/5/11 Alex F. [email protected]:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs