mirror of https://github.com/kivy/kivy.git
Update GridLayout to use CssListProperty for padding.
This commit is contained in:
parent
93c1aa25d5
commit
0bc8c0ce49
|
@ -90,7 +90,7 @@ __all__ = ('GridLayout', 'GridLayoutException')
|
|||
from kivy.logger import Logger
|
||||
from kivy.uix.layout import Layout
|
||||
from kivy.properties import NumericProperty, BooleanProperty, DictProperty, \
|
||||
BoundedNumericProperty, ReferenceListProperty
|
||||
BoundedNumericProperty, ReferenceListProperty, CssListProperty
|
||||
from math import ceil
|
||||
|
||||
|
||||
|
@ -111,11 +111,23 @@ class GridLayout(Layout):
|
|||
0.
|
||||
'''
|
||||
|
||||
padding = NumericProperty(0)
|
||||
'''Padding between widget box and children, in pixels.
|
||||
padding = CssListProperty([0, 0, 0, 0])
|
||||
'''Padding between layout box and children, in pixels.
|
||||
|
||||
:data:`padding` is a :class:`~kivy.properties.NumericProperty`, default to
|
||||
0.
|
||||
padding[0] represents the left padding, padding[1] the right padding,
|
||||
padding[2] the top padding and padding[3] the bottom padding.
|
||||
|
||||
If padding is given only two arguments, the first will represent left and
|
||||
right padding, and the second top and bottom padding.
|
||||
|
||||
If padding is given only one argument, it will represent all four
|
||||
directions.
|
||||
|
||||
.. versionchanged:: 1.7.0
|
||||
Replaced NumericProperty with CssListProperty.
|
||||
|
||||
:data:`padding` is a :class:`~kivy.properties.CssListProperty`, default to
|
||||
[0, 0, 0, 0].
|
||||
'''
|
||||
|
||||
cols = BoundedNumericProperty(None, min=0, allow_none=True)
|
||||
|
@ -332,10 +344,11 @@ class GridLayout(Layout):
|
|||
i = i - 1
|
||||
|
||||
# calculate minimum width/height needed, starting from padding + spacing
|
||||
padding2 = self.padding * 2
|
||||
padding_x = self.padding[0] + self.padding[1]
|
||||
padding_y = self.padding[2] + self.padding[3]
|
||||
spacing = self.spacing
|
||||
width = padding2 + spacing * (current_cols - 1)
|
||||
height = padding2 + spacing * (current_rows - 1)
|
||||
width = padding_x + spacing * (current_cols - 1)
|
||||
height = padding_y + spacing * (current_rows - 1)
|
||||
# then add the cell size
|
||||
width += sum(cols)
|
||||
height += sum(rows)
|
||||
|
@ -362,7 +375,8 @@ class GridLayout(Layout):
|
|||
return
|
||||
|
||||
# speedup
|
||||
padding = self.padding
|
||||
padding_left = self.padding[0]
|
||||
padding_top = self.padding[2]
|
||||
spacing = self.spacing
|
||||
selfx = self.x
|
||||
selfw = self.width
|
||||
|
@ -413,9 +427,9 @@ class GridLayout(Layout):
|
|||
|
||||
# reposition every child
|
||||
i = len_children - 1
|
||||
y = self.top - padding
|
||||
y = self.top - padding_top
|
||||
for row_height in rows:
|
||||
x = selfx + padding
|
||||
x = selfx + padding_left
|
||||
for col_width in cols:
|
||||
if i < 0:
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue