# Static box sizing problems

**URL:** <https://www.ruby-forum.com/t/static-box-sizing-problems/124456>\
**Category:** wxRuby\
**Created:** [December 28, 2007, 9:04pm UTC](https://www.ruby-forum.com/t/static-box-sizing-problems/124456 "2007-12-28T21:04:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ratkins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bcef8e/32.png) [@ratkins](https://www.ruby-forum.com/u/ratkins)\
**Post date:** [December 28, 2007, 9:04pm UTC](https://www.ruby-forum.com/t/static-box-sizing-problems/124456/1 "2007-12-28T21:04:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ratkins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bcef8e/32.png) [@ratkins](https://www.ruby-forum.com/u/ratkins)\
**Post date:** [December 29, 2007, 2:56am UTC](https://www.ruby-forum.com/t/static-box-sizing-problems/124456/2 "2007-12-29T02:56:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ratkins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bcef8e/32.png) [@ratkins](https://www.ruby-forum.com/u/ratkins)\
**Post date:** [December 29, 2007, 3:40am UTC](https://www.ruby-forum.com/t/static-box-sizing-problems/124456/3 "2007-12-29T03:40:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ratkins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bcef8e/32.png) [@ratkins](https://www.ruby-forum.com/u/ratkins)\
**Post date:** [December 29, 2007, 5:57am UTC](https://www.ruby-forum.com/t/static-box-sizing-problems/124456/4 "2007-12-29T05:57:28Z")

</div>

On Dec 28, 2007 7:09 PM, Alex F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![ratkins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bcef8e/32.png) [@ratkins](https://www.ruby-forum.com/u/ratkins)\
**Post date:** [December 29, 2007, 4:13am UTC](https://www.ruby-forum.com/t/static-box-sizing-problems/124456/5 "2007-12-29T04:13:22Z")

</div>

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
