I experienced a problem similar to this using GridBagSizer earlier today (http://www.ruby-forum.com/topic/164539#new). The problem was resolved at that point by using a BoxSizer instead of the GridBagSizer, but now I''ve run into the same problem with a FlexGridSizer. In the top half of the attached image, I use a series of horizontal BoxSizers, each with a StaticText (proportion = 0) and a TextCtrl (proportion = 1). This fills up the space nicely, but I want the left sides of the TextCtrls to line up. Keeping the BoxSizers and changing the proportions to something like 1 and 4 instead of 0 and 1 works, but it leaves large gaps between the label and the textbox when the window is large and lets the textbox unnecessarily force the labels to wrap when the window is smaller. Using a FlexGridSizer accomplishes the goal, but the TextCtrls no longer fill up the available space. The source looks something like this: require ''wx'' include Wx class AddPanel < Panel DEFAULT_FIELDS = ["A Label", "Another Label", "A third label", "And so on..."] def initialize(parent) super parent @fields = {} @field_panels = {} @field_labels = {} @field_textboxes = {} @field_layouts = FlexGridSizer.new 2 set_sizer @field_layouts DEFAULT_FIELDS.each do |label| @fields[label] = '''' @field_labels[label] = StaticText.new self, :label => label @field_textboxes[label] = TextCtrl.new self, :value => @fields[label] @field_layouts.add @field_labels[label], 0, EXPAND @field_layouts.add @field_textboxes[label], 1, LEFT, 4 ... end show end ... end In the larger Window, the following code is relevant: @add_panel = AddPanel.new @parent_panel ... @option_layout = BoxSizer.new VERTICAL @option_panel.set_sizer @option_layout ... @option_layout.add @add_panel, 1, EXPAND @add_panel.show ... @option_layout.layout Any suggestions? The only other option I can think of is to use a single horizontal BoxSizer with two vertical BoxSizers inside--one with all of the StaticTexts on the left, and the other with all of the TextCtrls on the right. This could potentially cause mis-alignment between the labels and their corresponding fields (if a label gets forced to wrap), though, so I''d rather avoid it. Thanks, Doug Attachments: http://www.ruby-forum.com/attachment/2641/expand-vs-lineup.jpg -- Posted via http://www.ruby-forum.com/.
Alex Fenton
2008-Sep-02 18:59 UTC
[wxruby-users] Lack of proper expansion using FlexGridSizer
Doug Glidden wrote:> I experienced a problem similar to this using GridBagSizer earlier today > (http://www.ruby-forum.com/topic/164539#new). The problem was resolved > at that point by using a BoxSizer instead of the GridBagSizer, but now > I''ve run into the same problem with a FlexGridSizer. In the top half of > the attached image, I use a series of horizontal BoxSizers, each with a > StaticText (proportion = 0) and a TextCtrl (proportion = 1). This fills > up the space nicely, but I want the left sides of the TextCtrls to line > up. >...> Any suggestions?FlexGridSizer is the right type of sizer for that sort of layout. Maybe look at FlexGridSizer#add_growable_col ? http://wxruby.rubyforge.org/doc/flexgridsizer.html#FlexGridSizer_addgrowablecol alex
Doug Glidden
2008-Sep-02 19:15 UTC
[wxruby-users] Lack of proper expansion using FlexGridSizer
Alex Fenton wrote: [snip]> Maybe look at FlexGridSizer#add_growable_col ?[snip] Alex, Thanks, that (combined with using the EXPAND flag when adding @field_textboxes[label] to @field_layouts) did the trick. Doug -- Posted via http://www.ruby-forum.com/.