BoxLayout doesn't honor pos_hint #698

Closed
Titousensei opened this Issue Sep 25, 2012 · 8 comments

Comments

Projects
None yet
5 participants
Contributor

Titousensei commented Sep 25, 2012

BoxLayout honrs size_hint, allowing, for instance, a button to be 50% the width of the container box (if orientation = vertical). But the button will always be aligned to the left, since neither pos_hint nor pos seem to have any effect.

It would make sens to apply pos_hint whenever size_hint is possible in a Layout.

(A workaround to put a Layout inside the Layout to get the same effect, but that complicates the tree unncessarily.)

Owner

akshayaurora commented Sep 25, 2012

Layouts except FloatLayout and RelativeLayout control the positioning of
there children, and therefore don't honor pos_hint. If you want to control
the positioning of the Children then you should either use one of
FloatLayout or RelativeLayout. You can either add a Float/RelativeLayout
under your BoxLayout or add dummy/empty Widget to be used as empty
spacing.

[BoxLayout]
[BBB]
BBB = 1 Button <- widget takes all space and is aligned to the left
[X_B_X]
B = Button
X = empty Widget()<- Three widgets in BoxLayout with no size_hint
specified Button Widget will be positioned in the middle. You can control
the widget order and the size_hint of the widgets control the Buttons
position. This would only work to provide you rudimentary control over the
widgets positioning and therefore should only be used for when you just
need to align the widget either to left/middle/right/top/bottom. For
further control over positioning one should simply use Float/RelativeLayout.

Regards

On Tue, Sep 25, 2012 at 8:04 AM, Titousensei notifications@github.comwrote:

BoxLayout honrs size_hint, allowing, for instance, a button to be 50% the
width of the container box (if orientation = vertical). But the button will
always be aligned to the left, since neither pos_hint nor pos seem to have
any effect.

It would make sens to apply pos_hint whenever size_hint is possible in a
Layout.

(A workaround to put a Layout inside the Layout to get the same effect,
but that complicates the tree unncessarily.)


Reply to this email directly or view it on GitHubhttps://github.com/kivy/kivy/issues/698.

Contributor

Titousensei commented Sep 25, 2012

I see. The dummy Widget solution only allows for absolute positioning, though, and it's not possible to center the button. I find that a very ugly solution and I prefer wrapping my button in a FloatLayout. (Which is the workaround I suggested.)

However, I would argue that BoxLayout only controls one dimension of the positioning of its children: the dimension defined by the orientation. The positioning on the other dimension is not defined in BoxLayout, and indeed arbitrary. So it would make sens to allow the user to specify the positioning only for the other dimension, by borrowing existing mechanisms of FloatLayout: pos and pos_hint.

Owner

tshirtman commented Sep 25, 2012

Le 25/09/2012 19:22, Titousensei a écrit :

I see. The dummy Widget solution only allows for absolute positioning,
though, and it's not possible to center the button. I find that a very
ugly solution and I prefer wrapping my button in a FloatLayout. (Which
is the workaround I suggested.)

However, I would argue that BoxLayout only controls one dimension of
the positioning of its children: the dimension defined by the
orientation. The positioning on the other dimension is not defined in
BoxLayout, and indeed arbitrary. So it would make sens to allow the
user to specify the positioning only for the other dimension, by
borrowing existing mechanisms of FloatLayout: pos and pos_hint.


Reply to this email directly or view it on GitHub
#698 (comment).

I agree that maybe boxlayout should honors the 'x', 'center_x', 'right'
keys when its orientation is vertical, and honors the 'y', 'center_y',
'top', keys when it's horizontal, as it's honoring the size_hint_x when
it's vertical, and size_hint_y when it's horizontal.

Would be good for consistency.

Contributor

hansent commented Sep 25, 2012

box layouts arrange widgtes next to each other, honoring the siuze_hint of
each widget. it cant honor pos_hint, since it cacluates teh position to
put them next to each other.

What exactly are you trying to do, ill try to give you an example of a
clean way to use the layout system?

Thomas

On Tue, Sep 25, 2012 at 12:27 PM, Gabriel Pettier
notifications@github.comwrote:

Le 25/09/2012 19:22, Titousensei a écrit :

I see. The dummy Widget solution only allows for absolute positioning,
though, and it's not possible to center the button. I find that a very
ugly solution and I prefer wrapping my button in a FloatLayout. (Which
is the workaround I suggested.)

However, I would argue that BoxLayout only controls one dimension of
the positioning of its children: the dimension defined by the
orientation. The positioning on the other dimension is not defined in
BoxLayout, and indeed arbitrary. So it would make sens to allow the
user to specify the positioning only for the other dimension, by
borrowing existing mechanisms of FloatLayout: pos and pos_hint.


Reply to this email directly or view it on GitHub
#698 (comment).

I agree that maybe boxlayout should honors the 'x', 'center_x', 'right'
keys when its orientation is vertical, and honors the 'y', 'center_y',
'top', keys when it's horizontal, as it's honoring the size_hint_x when
it's vertical, and size_hint_y when it's horizontal.

Would be good for consistency.


Reply to this email directly or view it on GitHubhttps://github.com/kivy/kivy/issues/698#issuecomment-8862730.

Contributor

Titousensei commented Sep 25, 2012

My use case is the following:

BoxLayout "vertical"
Slider
Button
Progressbar

The slider and progressbar can be 100% width, but I want the button to be smaller (50% width with size_hint), and centered.

My issue is that it seems completely arbitrary to have the widgets aligned to the left by default, and no simple way to change this hard-coded behavior.

The only solution I can find is putting a FloatLayout around the button. This is acceptable in the simple case above, but it can become ugly very fast if you have more than a few widgets you want to custom-align.

(Another option I thought about was to add the property valign or halign to the BoxLayout, but it seems less consistent with the overall design of Kivy.)

Contributor

hansent commented Sep 25, 2012

oh, sorry, I missed the part about it being the opposite dimension! I
agree this sounds like a good idea/approach. The only thing I'd be worried
about is incosistentcy with exisitng apps; but since pos_hint isn't set by
default on widget, it might be ok to just add it?!

Thomas

On Tue, Sep 25, 2012 at 12:50 PM, Titousensei notifications@github.comwrote:

My use case is the following:

BoxLayout "vertical"
Slider
Button
Progressbar

The slider and progressbar can be 100% width, but I want the button to be
smaller (50% width with size_hint), and centered.

My issue is that it seems completely arbitrary to have the widgets aligned
to the left by default, and no simple way to change this hard-coded
behavior.

The only solution I can find is putting a FloatLayout around the button.
This is acceptable in the simple case above, but it can become ugly very
fast if you have more than a few widgets you want to custom-align.

(Another option I thought about was to add the property valign or halign
to the BoxLayout, but it seems less consistent with the overall design of
Kivy.)


Reply to this email directly or view it on GitHubhttps://github.com/kivy/kivy/issues/698#issuecomment-8863487.

Owner

tito commented Sep 25, 2012

Yep, i think using pos_hint in BoxLayout for inner aligment would be ok.

tito was assigned Sep 28, 2012

Owner

tito commented Sep 28, 2012

Ok, doing it.

tito closed this in cfb118c Sep 29, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment