Static box sizing problems

Hi,

I tried this one over on the main wx-users list as well, but thought I
would
try it here since I am using wxRuby:

I am using wxWidgets 2.8.7 on a linux box using the GTK build.

I have pared down my issue to the simplest case: I am trying to use a
horizontal BoxSizer to split a frame into two sections: a left and
right
side. I want the left side to stretch proportionally and I want the
right
side to be of a fixed width. Moreover, I want to enclose the right side
in
a wxStaticBox.

I happen to be using wxRuby, but the code should be understandable to
C++
programmers. This is in the constructor of my frame subclass:

lr_sizer = BoxSizer.new( HORIZONTAL )

txt = StaticText.new (self, -1, "Text Left")
lr_sizer.add(txt, 1, EXPAND | ALL, 4)

static_box = StaticBox.new(self, -1, "Static Box")
right_sizer = StaticBoxSizer.new( static_box, VERTICAL )

lr_sizer.add(right_sizer, 0, EXPAND | ALL, 4)
set_sizer(lr_sizer)
layout()

This code runs and gives almost what I want. The text appears on the
left
and the static box on the right. However, the static box is a tiny
sliver.
What I want is to fix the width of the static box. So I try adding a
size
argument to the static box constructor:

static_box = StaticBox.new(self, -1, “Static Box”, :size => [100, 40]
)

But now I get something very unexpected to me. The static box is indeed
wider, but it has the same left hand screen coordinate as it did when it
was
a sliver, so that the static box is mostly out of the frame. I only see
a
tiny slice of it. Resizing the frame moves the whole box, so it is
always
mostly out of the frame. It is as if the static box were positioned
according to the minimum size, and then grown to the right, to respect
the
requested box size. But this is clearly not what I want. I want the
box to
be sized as requested, and then fit using the spacers.

How do I do that? Note that I tried using a panel inside my frame and
adding everything to the panel, but I got the exact same result.

Thanks for any help.

Hello Robert,

From reading what you have described here, it sounds as though you would
need to change the right_sizer addition to the lr_sizer.

What I would suggest, is trying this:

lr_sizer.add(right_sizer,1,EXPAND|ALL,4)

In order, the parameters are: Sizer/Window, Proportion, Flags, Border

Everything else is pretty self explanitory, except for the Proportion.
This
is often not well known, or understood. Proprotion gives the
sizer/control
being added to the sizer, and propotional view of how it should resize
itself when layout() is called. Specifically, 0 means that it will use
what
it can, and nothing else. 1 means that if you have 2 controls in the
sizer,
it will use 1/2 of the sizer’s dimensions when re-sizing / layout().
The
main thing to note here, is that if you want to get more specifics of
how to
design the layout, will allow you to expand the sizes of items included,
by
proportional values.

Check that out, you may need to do some twinking here and there between
the
controls you add, to get the spacing you want.

TTFN,

Mario S.

Mario,

I think I have a pretty reasonable understanding of the proportional
flag.
I do not want the right_sizer to be proportional at all. I want it to
be of
fixed size. Therefore proportional_flag should be 0, correct?

If I change it to 1, it changes size when the frame changes size. This
is
not what I want.

I was able to work around this apparent bug (in wxWidgets) by adding a
dummy
spacer of height 0 to the StaticBoxSizer that is of the fixed width that
I
want. I don’t see any reason why that should work whereas setting the
size
of the StaticBoxSizer does not.

Thanks,
Bob

On Dec 28, 2007 7:09 PM, Alex F. [email protected] wrote:

Robert A. wrote:

I am trying to use a horizontal BoxSizer to split a frame into two
sections: a left and right side. I want the left side to stretch
proportionally and I want the right side to be of a fixed width.
Moreover, I want to enclose the right side in a wxStaticBox.

Perhaps it would help if you add some actual widgets to the right hand
panel and see then if it sizes as you want. I think that Wx::StaticBox
itself doesn’t have a minimum notional size - it’s a grouping for other
widgets.

Yeah, that’s what I ended up doing and it does work. But this is a bug
IMO. My wxStaticBox houses a dynamic number of widgets with zero being
the
minimum number. But I always have to make sure there’s an invisible
dummy
widget in there to get the behavior right, which is awkward at best.

Thanks,
Bob

Robert A. wrote:

I am trying to use a horizontal BoxSizer to split a frame into two
sections: a left and right side. I want the left side to stretch
proportionally and I want the right side to be of a fixed width.
Moreover, I want to enclose the right side in a wxStaticBox.

Perhaps it would help if you add some actual widgets to the right hand
panel and see then if it sizes as you want. I think that Wx::StaticBox
itself doesn’t have a minimum notional size - it’s a grouping for other
widgets. I tried adding a Panel to the right hand size like:

something = Wx::Panel.new(self, :size => [100, 100])
right_sizer.add(something)

And then it gives the effect you desire: a fixed size on one size, a
variable on the other.

You might also have a look at splitter window or sash layouts, to see if
that’s what you’re looking for.

alex