First, Thank you, thank you, thank you for those who put wxRuby together. I''m thrilled to be able to write GUI code in Ruby! I''m hitting some confusion about how Sizers work. I''ve read the tutorials and the section in the wxWidgets book but I still can''t seem to figure this out. Here''s an example of my code: parent = Wx::Panel.new(frame, -1, Wx::Point.new(0, 0), Wx::Size.new (823, 900)) sizer = Wx::BoxSizer.new(Wx::VERTICAL) child = Wx::Panel.new(parent, -1, Wx::Point.new(0, 0), Wx::Size.new (823, 200)) sizer.add(child, 1, Wx::ALIGN_CENTER_HORIZONTAL, 0) parent.set_sizer(sizer) When I resize the window, the size of the child panel grows to consume the entire height of the parent. I''d like the child''s height to remain 200. I''ve tried: - child.set_max_size(Size.new(823, 200)) - sizer.add(child, 1, 0|Wx::ALIGN_CENTER_HORIZONTAL, 0) # according to the book, the flag 0 means the window should not be resized. - and several other combinations of flags and settings I''d like the child to remain centered horizontally without it''s size changing at all. How is this done? Micah Martin 8th Light, Inc. 8thlight.com _______________________________________________ wxruby-users mailing list wxruby-users@rubyforge.org http://rubyforge.org/mailman/listinfo/wxruby-users
Hi Micah Micah Martin wrote:> I''m hitting some confusion about how Sizers work....> Here''s an example of my code: > > parent = Wx::Panel.new(frame, -1, Wx::Point.new(0, 0), > Wx::Size.new(823, 900)) > sizer = Wx::BoxSizer.new(Wx::VERTICAL) > child = Wx::Panel.new(parent, -1, Wx::Point.new(0, 0), > Wx::Size.new(823, 200)) > sizer.add(child, 1, Wx::ALIGN_CENTER_HORIZONTAL, 0) > parent.set_sizer(sizer) > > When I resize the window, the size of the child panel grows to consume > the entire height of the parent. I''d like the child''s height to > remain 200.Instead of your current sizer.add call, try the following sizer.add(child, 0, Wx::ALIGN_CENTRE_HORIZONTAL, 0) sizer.add_spacer(1) You were right that you wanted ''0'' as an argument, but it should be the second argument to ''add''. Think of it as a ''proportion'' argument. So 0 means: "when the parent is resized, don''t allocate any of the resize to this child window". You then need to add something that will be allocated the additional space when the window is resized. In this case we''ve used add_spacer and given it a proportion argument of 1. Since the total of all the proportion arguments to this sizer is 1 (0 for the panel + 1 for the spacer), the spacer receives 1 / 1 = 100% of the resize. I used a spacer but it could as easily be a Window like a notebook, a textctrl, another panel, whatever. you might find this useful: http://www.wxwidgets.org/manuals/2.8/wx_sizeroverview.html#boxsizerprogramming Also wxSugar is a package which sits on top of wxRuby and makes programming sizers a lot easier: http://wxruby.rubyforge.org/wiki/wiki.pl?WxSugar hth alex
That worked brilliantly! Thanks Alex. I''ll definitely give the sugar package a whirl. Micah On Feb 19, 2007, at 2:00 PM, Alex Fenton wrote:> Hi Micah > > Micah Martin wrote: >> I''m hitting some confusion about how Sizers work. > ... >> Here''s an example of my code: >> >> parent = Wx::Panel.new(frame, -1, Wx::Point.new(0, 0), >> Wx::Size.new(823, 900)) >> sizer = Wx::BoxSizer.new(Wx::VERTICAL) >> child = Wx::Panel.new(parent, -1, Wx::Point.new(0, 0), >> Wx::Size.new(823, 200)) >> sizer.add(child, 1, Wx::ALIGN_CENTER_HORIZONTAL, 0) >> parent.set_sizer(sizer) >> >> When I resize the window, the size of the child panel grows to >> consume >> the entire height of the parent. I''d like the child''s height to >> remain 200. > Instead of your current sizer.add call, try the following > > sizer.add(child, 0, Wx::ALIGN_CENTRE_HORIZONTAL, 0) > sizer.add_spacer(1) > > You were right that you wanted ''0'' as an argument, but it should be > the > second argument to ''add''. Think of it as a ''proportion'' argument. So 0 > means: "when the parent is resized, don''t allocate any of the > resize to > this child window". > > You then need to add something that will be allocated the additional > space when the window is resized. In this case we''ve used > add_spacer and > given it a proportion argument of 1. Since the total of all the > proportion arguments to this sizer is 1 (0 for the panel + 1 for the > spacer), the spacer receives 1 / 1 = 100% of the resize. > > I used a spacer but it could as easily be a Window like a notebook, a > textctrl, another panel, whatever. > > you might find this useful: > http://www.wxwidgets.org/manuals/2.8/ > wx_sizeroverview.html#boxsizerprogramming > > Also wxSugar is a package which sits on top of wxRuby and makes > programming sizers a lot easier: > > http://wxruby.rubyforge.org/wiki/wiki.pl?WxSugar > > hth > alex > > > > > > > > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/wxruby-users/attachments/20070219/ba689886/attachment.html