I would like to request an additional Layout: BoxLayout.
Here is a use case from a project I am working on: I am using a GridLayout to simplify laying out the information on the screen. I have defined 4 rows and 1 column in the grid. I want each row to contain multiple Labels and a TileGrid bitmap. The allows me to position these objects without having to manually calculate all of the horizontal positions.
I created a primitive horizontal boxlayout that works with Label and TileGrid to create a Group that can be placed in the GridLayout.
Here is the code I used this works for my limited use case:
class HBoxLayout(Group):
@property
def width(self):
_width = 0
for w in self:
if isinstance(w, TileGrid):
_width += w.width * w.tile_width
else:
_width += w.width * w.scale
#_width = sum([w.width * w.scale for w in self]) #TileGrid does not have a scale attribute
return _width
@property
def height(self):
return max([w.height for w in self]) # also needs scale - but not needed for my use case.
def append(self, layer):
if not len(self):
layer.x = 0 # the first widget starts at zero
else:
layer.x = self.width
super().append(layer)
As you can see in the code above, the HBoxLayout adds height and width properties to Group, and overrides the append method to automatically position "widgets".
I would like to request an additional Layout: BoxLayout. Here is a use case from a project I am working on: I am using a GridLayout to simplify laying out the information on the screen. I have defined 4 rows and 1 column in the grid. I want each row to contain multiple Labels and a TileGrid bitmap. The allows me to position these objects without having to manually calculate all of the horizontal positions.
I created a primitive horizontal boxlayout that works with Label and TileGrid to create a Group that can be placed in the GridLayout.
Here is the code I used this works for my limited use case:
As you can see in the code above, the HBoxLayout adds height and width properties to Group, and overrides the append method to automatically position "widgets".
Here is a simple example of the class in use:
A more robust solution would include a more general BoxLayout that supports vertical and horizontal orientations.