kxgames / glooey

An object-oriented GUI library for pyglet.
MIT License
91 stars 6 forks source link

Weird behaviour with composite alignment #21

Closed UplinkPhobia closed 5 years ago

UplinkPhobia commented 5 years ago

When trying to create a VBox with a "composite" alignment (e.g. "fill left"), the alignment completely messes up. The following code is a minimal way to show it.

import glooey
import pyglet

win = pyglet.window.Window(800, 600)

gui = glooey.Gui(win)

box = glooey.VBox()
box.padding = 100 
box.alignment = "fill left"
gui.add(box)

p = glooey.Placeholder(50, 50)
box.add(p)

box.debug_placement_problems()
pyglet.app.run()

bug

Instead of filling the left side as expected, the content sticks to the bottom side.

Is it an expected behaviour, or is there something wrong with the way it behaves?

kalekundert commented 5 years ago

Thanks for the bug report and the nice minimal example. I poked around a little, and can definitely reproduce the bug. I get the right behavior with box.padding = 0, so it seems like the issue is that the padding is not being correctly handled somehow. I'll try to track this down more specifically in the next few days.

UplinkPhobia commented 5 years ago

I did a few more tests, and apparently even with no explicit padding it's possible to recreate the bug (it is probably due to padding anyway, but implicitely created by stacking up widgets). Here's what I used :

import glooey
import pyglet

win = pyglet.window.Window(800, 600)

gui = glooey.Gui(win)

box = glooey.VBox()
gui.add(box)

# We create another box inside the first.
# The idea was to have a menu filling the bottom of the window, 
# and a side pane sticking to the left side of the upper part of the window
side_pane = glooey.VBox()
side_pane.alignment = "fill left"  # Toggling this line toggles the bug
box.add(side_pane)
p = glooey.Placeholder(50, 50)
side_pane.add(p)

# This placeholder is just used to show the bug, no padding or alignment
# since we don't want to make it bug too
p = glooey.Placeholder(50, 50) 
box.add(p)

box.debug_placement_problems()
pyglet.app.run()

My first example showed that padding on a VBox was showing the bug, but from this new little example it seems that putting a VBox inside of another, even without padding, will make it bug if you add alignment constraints. However I can't tell whether it's because widgets inside of the VBox have an implicit padding that recreates the bug, or whether it's because the bug isn't limited/due to padding.

kalekundert commented 5 years ago

This should be fixed now. There was a bug in the 'fill left' alignment function that basically resulted in widgets being stuck to the bottom of the window, no matter what. Similar problems in 'fill right', 'fill top', and 'fill bottom' were also fixed.

Thanks for the bug report, and sorry it took me so long to get around to fixing it!