[wxruby-users] Two issues using GridBagSizer

Alex Fenton alex at pressure.to
Tue Sep 2 12:06:11 EDT 2008


Hi

Doug Glidden wrote:
> The first is that the GridBagSizer itself isn't expanding to fill the
> area available to it.  For reasons that will be more clear when I get to
> the second issue, the GridBagSizer actually has only one cell.  When I
> add the panel sized with the GridBagSizer to the BoxSizer that holds it,
> I use the EXPAND flag, but it doesn't expand to fill the entire
> horizontal area (see attached image, top half).
>   
I couldn't fully follow what was going on in your code, but hope  I can 
help with a few suggestions:

* Try using one of the GUI designers (eg DialogBlocks) to test build 
your layout. They make it easy to swap and nest Sizers and you can 
immediately see the effects. From then you can go and look at the XML to 
see how the Sizers are flagged and nested.

* Use a com

> The second problem relates to the way I'm using the GridBagSizer.  It
> contains only a single cell that has two separate panels in it. 
Why are you using GridBagSizer then? If all you want is a place to swap 
two panels or widgets in and out of, a simple BoxSizer would do fine. 
Have a look at Sizer#detach and Sizer#replace methods, in conjunction 
with using Window#hide or Window#destroy on the window you're removing.

>  These
> panels are mutually exclusive (either one or the other is showing, or
> possibly neither, but never both), so I want them to occupy the same
> space, which works using the GridBagSizer.
Ok, see suggestion above. Here's a simple class which wraps multiple 
controls, presenting only one at a time.

>   When I first executed the
> code, the contents of @add_panel and @edit_panel would both be squished
> into a very small area at the upper-left corner of the @option_panel.
> At position 1 in the code, I added the following lines:
>
> @option_sizer.calc_min
> @option_sizer.recalc_sizes
>
> This fixed the problem for the @add_panel only-- at edit_panel would still
> appear squished into the corner.  I then moved the two lines to appear
> at both position 2 and position 3 in the code, but the problem persisted
> (see attached image, bottom half).
>
> [ui/detail_panel.rb]:
> require 'wx'
> require 'ui/add_panel'
> require 'ui/edit_panel'
> include Wx
>
> class DetailPanel < Panel
>   def initialize(parent)
>     super parent
>
>     @box = StaticBox.new self, :label => 'Entry Detail View'
>     ... # creating other frames
>     @option_panel = Panel.new self
>     @add_panel = AddEntryPanel.new @option_panel
>     @edit_panel = EditEntryPanel.new @option_panel
>
>     @main_sizer = BoxSizer.new VERTICAL
>     set_sizer @main_sizer
>     @box_sizer = StaticBoxSizer.new @box, VERTICAL
>     ... # defining other sizers
>     @option_sizer = GridBagSizer.new
>     @option_panel.set_sizer @option_sizer
>
>     @main_sizer.add @box_layout, 1, EXPAND|LEFT|RIGHT, 1
>
>     ... # adding other frames to @box_sizer
>     @box_sizer.add @option_panel, 1, EXPAND|TOP, 6
>
>     ... # other sizers within @box_sizer
>
>     @option_sizer.add @add_panel, GBPosition.new(0, 0), GBSpan.new,
> EXPAND
>     @option_sizer.add @edit_panel, GBPosition.new(0, 0), GBSPan.new,
> EXPAND
>     #position 1
>
>     ... # assign event handlers
>     show
>     @add_panel.hide
>     @edit_panel.hide
>   end
>
>   def add_button_click(event)
>     @edit_panel.hide
>     @add_panel.show
>     #position 2
>   end
>
>   def edit_button_click(event)
>     @add_panel.hide
>     @edit_panel.show
>     #position 3
>   end
> end
>
> ui/add_panel.rb and ui/entry_panel.rb contain the necessary class
> definitions for those AddPanel and EntryPanel, of course.
>
> Any help (including complete overhauls if there's a better way I should
> be doing this) is welcome.
>
> Thanks,
> Doug G.
>
> Attachments:
> http://www.ruby-forum.com/attachment/2640/non-expand.jpg
>
>   



More information about the wxruby-users mailing list