I am having a couple of issues with sizing objects using GridBagSizer.
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).
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. 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. 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–@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).
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.