We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
StackLayout spacing added to top padding
When using a StackLayout, the spacing is added to the top padding.

To see the problem, run kivycatalog and change the spacing property for the StackLayout example to 20.

Tested on 1.6.0 and master.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `kivy/uix/stacklayout.py`
Content:
```
1 '''
2 Stack Layout
3 ============
4 
5 .. only:: html
6 
7     .. image:: images/stacklayout.gif
8         :align: right
9 
10 .. only:: latex
11 
12     .. image:: images/stacklayout.png
13         :align: right
14 
15 .. versionadded:: 1.0.5
16 
17 :class:`StackLayout` arranges children vertically or horizontally, as many
18 as the layout can fit.
19 
20 
21 .. warning:
22 
23     This is experimental and subject to change as long as this warning notice is
24     present.
25 
26 '''
27 
28 __all__ = ('StackLayout', )
29 
30 from kivy.uix.layout import Layout
31 from kivy.properties import NumericProperty, OptionProperty, \
32     ReferenceListProperty, VariableListProperty
33 
34 
35 class StackLayout(Layout):
36     '''Stack layout class. See module documentation for more information.
37     '''
38 
39     spacing = VariableListProperty([0, 0], length=2)
40     '''Spacing between children: [spacing_horizontal, spacing_vertical].
41 
42     spacing also accepts a one argument form [spacing].
43 
44     :data:`spacing` is a :class:`~kivy.properties.VariableListProperty`, default to
45     [0, 0].
46     '''
47 
48     padding = VariableListProperty([0, 0, 0, 0])
49     '''Padding between layout box and children: [padding_left, padding_top,
50     padding_right, padding_bottom].
51 
52     padding also accepts a two argument form [padding_horizontal,
53     padding_vertical] and a one argument form [padding].
54 
55     .. versionchanged:: 1.7.0
56 
57     Replaced NumericProperty with VariableListProperty.
58 
59     :data:`padding` is a :class:`~kivy.properties.VariableListProperty`, default to
60     [0, 0, 0, 0].
61     '''
62 
63     orientation = OptionProperty('lr-tb', options=(
64         'lr-tb', 'tb-lr', 'rl-tb', 'tb-rl', 'lr-bt', 'bt-lr', 'rl-bt', 'bt-rl'))
65     '''Orientation of the layout.
66 
67     :data:`orientation` is an :class:`~kivy.properties.OptionProperty`, default
68     to 'lr-tb'.
69 
70     Valid orientations are: 'lr-tb', 'tb-lr', 'rl-tb', 'tb-rl', 'lr-bt',
71     'bt-lr', 'rl-bt', 'bt-rl'
72 
73     .. versionchanged:: 1.5.0
74 
75         :data:`orientation` now correctly handles all valid combinations of
76         'lr','rl','tb','bt'. Before this version only 'lr-tb' and
77         'tb-lr' were supported, and 'tb-lr' was misnamed and placed
78         widgets from bottom to top and from right to left (reversed compared
79         to what was expected).
80 
81     .. note::
82 
83         lr mean Left to Right.
84         rl mean Right to Left.
85         tb mean Top to Bottom.
86         bt mean Bottom to Top.
87     '''
88 
89     minimum_width = NumericProperty(0)
90     '''Minimum width needed to contain all children.
91 
92     .. versionadded:: 1.0.8
93 
94     :data:`minimum_width` is a :class:`kivy.properties.NumericProperty`, default
95     to 0.
96     '''
97 
98     minimum_height = NumericProperty(0)
99     '''Minimum height needed to contain all children.
100 
101     .. versionadded:: 1.0.8
102 
103     :data:`minimum_height` is a :class:`kivy.properties.NumericProperty`,
104     default to 0.
105     '''
106 
107     minimum_size = ReferenceListProperty(minimum_width, minimum_height)
108     '''Minimum size needed to contain all children.
109 
110     .. versionadded:: 1.0.8
111 
112     :data:`minimum_size` is a :class:`~kivy.properties.ReferenceListProperty` of
113     (:data:`minimum_width`, :data:`minimum_height`) properties.
114     '''
115 
116     def __init__(self, **kwargs):
117         super(StackLayout, self).__init__(**kwargs)
118         self.bind(
119             padding=self._trigger_layout,
120             spacing=self._trigger_layout,
121             children=self._trigger_layout,
122             orientation=self._trigger_layout,
123             size=self._trigger_layout,
124             pos=self._trigger_layout)
125 
126     def do_layout(self, *largs):
127         # optimize layout by preventing looking at the same attribute in a loop
128         selfpos = self.pos
129         selfsize = self.size
130         orientation = self.orientation.split('-')
131         padding_left = self.padding[0]
132         padding_top = self.padding[1]
133         padding_right = self.padding[2]
134         padding_bottom = self.padding[3]
135 
136         padding_x = padding_left + padding_right
137         padding_y = padding_top + padding_bottom
138         spacing_x, spacing_y = self.spacing
139 
140         lc = []
141 
142         # Determine which direction and in what order to place the widgets
143         posattr = [0] * 2
144         posdelta = [0] * 2
145         posstart = [0] * 2
146         for i in (0, 1):
147             posattr[i] = 1 * (orientation[i] in ('tb', 'bt'))
148             k = posattr[i]
149             if orientation[i] == 'lr':
150                 # left to right
151                 posdelta[i] = 1
152                 posstart[i] = selfpos[k] + padding_left
153             elif orientation[i] == 'bt':
154                 # bottom to top
155                 posdelta[i] = 1
156                 posstart[i] = selfpos[k] + padding_bottom
157             elif orientation[i] == 'rl':
158                 # right to left
159                 posdelta[i] = -1
160                 posstart[i] = selfpos[k] + selfsize[k] - padding_right
161             else:
162                 # top to bottom
163                 posdelta[i] = -1
164                 posstart[i] = selfpos[k] + selfsize[k] - padding_top
165 
166         innerattr, outerattr = posattr
167         ustart, vstart = posstart
168         deltau, deltav = posdelta
169         del posattr, posdelta, posstart
170 
171         u = ustart  # inner loop position variable
172         v = vstart  # outer loop position variable
173 
174         # space calculation, used for determining when a row or column is full
175 
176         if orientation[0] in ('lr', 'rl'):
177             lu = self.size[innerattr] - padding_x
178             sv = padding_y  # size in v-direction, for minimum_size property
179             su = padding_x  # size in h-direction
180             spacing_u = spacing_x
181             spacing_v = spacing_y
182         else:
183             lu = self.size[innerattr] - padding_y
184             sv = padding_x  # size in v-direction, for minimum_size property
185             su = padding_y  # size in h-direction
186             spacing_u = spacing_y
187             spacing_v = spacing_x
188 
189         # space calculation, row height or column width, for arranging widgets
190         lv = 0
191 
192         urev = (deltau < 0)
193         vrev = (deltav < 0)
194         for c in reversed(self.children):
195             # Issue#823: ReferenceListProperty doesn't allow changing
196             # individual properties.
197             # when the above issue is fixed we can remove csize from below and
198             # access c.size[i] directly
199             csize = c.size[:]  # we need to update the whole tuple at once.
200             if c.size_hint[0]:
201                 # calculate width
202                 csize[0] = c.size_hint[0] * (selfsize[0] - padding_x)
203             if c.size_hint[1]:
204                 # calculate height
205                 csize[1] = c.size_hint[1] * (selfsize[1] - padding_y)
206             c.size = tuple(csize)
207 
208             # does the widget fit in the row/column?
209             if lu - c.size[innerattr] >= 0:
210                 lc.append(c)
211                 lu -= c.size[innerattr] + spacing_u
212                 lv = max(lv, c.size[outerattr])
213                 continue
214 
215             # push the line
216             sv += lv + spacing_v
217             for c2 in lc:
218                 if urev:
219                     u -= c2.size[innerattr] + spacing_u
220                 p = [0, 0]  # issue #823
221                 p[innerattr] = u
222                 p[outerattr] = v
223                 if vrev:
224                     # v position is actually the top/right side of the widget
225                     # when going from high to low coordinate values,
226                     # we need to subtract the height/width from the position.
227                     p[outerattr] -= c2.size[outerattr]
228                 c2.pos = tuple(p)  # issue #823
229                 if not urev:
230                     u += c2.size[innerattr] + spacing_u
231 
232             v += deltav * lv
233             v += deltav * spacing_v
234             lc = [c]
235             lv = c.size[outerattr]
236             lu = selfsize[innerattr] - su - c.size[innerattr] - spacing_u
237             u = ustart
238 
239         if lc:
240             # push the last (incomplete) line
241             sv += lv + spacing_v
242             for c2 in lc:
243                 if urev:
244                     u -= c2.size[innerattr] + spacing_u
245                 p = [0, 0]  # issue #823
246                 p[innerattr] = u
247                 p[outerattr] = v
248                 if vrev:
249                     p[outerattr] -= c2.size[outerattr]
250                 c2.pos = tuple(p)  # issue #823
251                 if not urev:
252                     u += c2.size[innerattr] + spacing_u
253 
254         minsize = self.minimum_size[:]  # issue #823
255         minsize[outerattr] = sv
256         self.minimum_size = tuple(minsize)
257
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/kivy/uix/stacklayout.py b/kivy/uix/stacklayout.py
--- a/kivy/uix/stacklayout.py
+++ b/kivy/uix/stacklayout.py
@@ -216,7 +216,7 @@
             sv += lv + spacing_v
             for c2 in lc:
                 if urev:
-                    u -= c2.size[innerattr] + spacing_u
+                    u -= c2.size[innerattr]
                 p = [0, 0]  # issue #823
                 p[innerattr] = u
                 p[outerattr] = v
@@ -226,7 +226,9 @@
                     # we need to subtract the height/width from the position.
                     p[outerattr] -= c2.size[outerattr]
                 c2.pos = tuple(p)  # issue #823
-                if not urev:
+                if urev:
+                    u -= spacing_u
+                else:
                     u += c2.size[innerattr] + spacing_u
 
             v += deltav * lv
@@ -241,14 +243,16 @@
             sv += lv + spacing_v
             for c2 in lc:
                 if urev:
-                    u -= c2.size[innerattr] + spacing_u
+                    u -= c2.size[innerattr]
                 p = [0, 0]  # issue #823
                 p[innerattr] = u
                 p[outerattr] = v
                 if vrev:
                     p[outerattr] -= c2.size[outerattr]
                 c2.pos = tuple(p)  # issue #823
-                if not urev:
+                if urev:
+                    u -= spacing_u
+                else:
                     u += c2.size[innerattr] + spacing_u
 
         minsize = self.minimum_size[:]  # issue #823

{"golden_diff": "diff --git a/kivy/uix/stacklayout.py b/kivy/uix/stacklayout.py\n--- a/kivy/uix/stacklayout.py\n+++ b/kivy/uix/stacklayout.py\n@@ -216,7 +216,7 @@\n             sv += lv + spacing_v\n             for c2 in lc:\n                 if urev:\n-                    u -= c2.size[innerattr] + spacing_u\n+                    u -= c2.size[innerattr]\n                 p = [0, 0]  # issue #823\n                 p[innerattr] = u\n                 p[outerattr] = v\n@@ -226,7 +226,9 @@\n                     # we need to subtract the height/width from the position.\n                     p[outerattr] -= c2.size[outerattr]\n                 c2.pos = tuple(p)  # issue #823\n-                if not urev:\n+                if urev:\n+                    u -= spacing_u\n+                else:\n                     u += c2.size[innerattr] + spacing_u\n \n             v += deltav * lv\n@@ -241,14 +243,16 @@\n             sv += lv + spacing_v\n             for c2 in lc:\n                 if urev:\n-                    u -= c2.size[innerattr] + spacing_u\n+                    u -= c2.size[innerattr]\n                 p = [0, 0]  # issue #823\n                 p[innerattr] = u\n                 p[outerattr] = v\n                 if vrev:\n                     p[outerattr] -= c2.size[outerattr]\n                 c2.pos = tuple(p)  # issue #823\n-                if not urev:\n+                if urev:\n+                    u -= spacing_u\n+                else:\n                     u += c2.size[innerattr] + spacing_u\n \n         minsize = self.minimum_size[:]  # issue #823\n", "issue": "StackLayout spacing added to top padding\nWhen using a StackLayout, the spacing is added to the top padding.\n\nTo see the problem, run kivycatalog and change the spacing property for the StackLayout example to 20.\n\nTested on 1.6.0 and master.\n\n", "before_files": [{"content": "'''\nStack Layout\n============\n\n.. only:: html\n\n    .. image:: images/stacklayout.gif\n        :align: right\n\n.. only:: latex\n\n    .. image:: images/stacklayout.png\n        :align: right\n\n.. versionadded:: 1.0.5\n\n:class:`StackLayout` arranges children vertically or horizontally, as many\nas the layout can fit.\n\n\n.. warning:\n\n    This is experimental and subject to change as long as this warning notice is\n    present.\n\n'''\n\n__all__ = ('StackLayout', )\n\nfrom kivy.uix.layout import Layout\nfrom kivy.properties import NumericProperty, OptionProperty, \\\n    ReferenceListProperty, VariableListProperty\n\n\nclass StackLayout(Layout):\n    '''Stack layout class. See module documentation for more information.\n    '''\n\n    spacing = VariableListProperty([0, 0], length=2)\n    '''Spacing between children: [spacing_horizontal, spacing_vertical].\n\n    spacing also accepts a one argument form [spacing].\n\n    :data:`spacing` is a :class:`~kivy.properties.VariableListProperty`, default to\n    [0, 0].\n    '''\n\n    padding = VariableListProperty([0, 0, 0, 0])\n    '''Padding between layout box and children: [padding_left, padding_top,\n    padding_right, padding_bottom].\n\n    padding also accepts a two argument form [padding_horizontal,\n    padding_vertical] and a one argument form [padding].\n\n    .. versionchanged:: 1.7.0\n\n    Replaced NumericProperty with VariableListProperty.\n\n    :data:`padding` is a :class:`~kivy.properties.VariableListProperty`, default to\n    [0, 0, 0, 0].\n    '''\n\n    orientation = OptionProperty('lr-tb', options=(\n        'lr-tb', 'tb-lr', 'rl-tb', 'tb-rl', 'lr-bt', 'bt-lr', 'rl-bt', 'bt-rl'))\n    '''Orientation of the layout.\n\n    :data:`orientation` is an :class:`~kivy.properties.OptionProperty`, default\n    to 'lr-tb'.\n\n    Valid orientations are: 'lr-tb', 'tb-lr', 'rl-tb', 'tb-rl', 'lr-bt',\n    'bt-lr', 'rl-bt', 'bt-rl'\n\n    .. versionchanged:: 1.5.0\n\n        :data:`orientation` now correctly handles all valid combinations of\n        'lr','rl','tb','bt'. Before this version only 'lr-tb' and\n        'tb-lr' were supported, and 'tb-lr' was misnamed and placed\n        widgets from bottom to top and from right to left (reversed compared\n        to what was expected).\n\n    .. note::\n\n        lr mean Left to Right.\n        rl mean Right to Left.\n        tb mean Top to Bottom.\n        bt mean Bottom to Top.\n    '''\n\n    minimum_width = NumericProperty(0)\n    '''Minimum width needed to contain all children.\n\n    .. versionadded:: 1.0.8\n\n    :data:`minimum_width` is a :class:`kivy.properties.NumericProperty`, default\n    to 0.\n    '''\n\n    minimum_height = NumericProperty(0)\n    '''Minimum height needed to contain all children.\n\n    .. versionadded:: 1.0.8\n\n    :data:`minimum_height` is a :class:`kivy.properties.NumericProperty`,\n    default to 0.\n    '''\n\n    minimum_size = ReferenceListProperty(minimum_width, minimum_height)\n    '''Minimum size needed to contain all children.\n\n    .. versionadded:: 1.0.8\n\n    :data:`minimum_size` is a :class:`~kivy.properties.ReferenceListProperty` of\n    (:data:`minimum_width`, :data:`minimum_height`) properties.\n    '''\n\n    def __init__(self, **kwargs):\n        super(StackLayout, self).__init__(**kwargs)\n        self.bind(\n            padding=self._trigger_layout,\n            spacing=self._trigger_layout,\n            children=self._trigger_layout,\n            orientation=self._trigger_layout,\n            size=self._trigger_layout,\n            pos=self._trigger_layout)\n\n    def do_layout(self, *largs):\n        # optimize layout by preventing looking at the same attribute in a loop\n        selfpos = self.pos\n        selfsize = self.size\n        orientation = self.orientation.split('-')\n        padding_left = self.padding[0]\n        padding_top = self.padding[1]\n        padding_right = self.padding[2]\n        padding_bottom = self.padding[3]\n\n        padding_x = padding_left + padding_right\n        padding_y = padding_top + padding_bottom\n        spacing_x, spacing_y = self.spacing\n\n        lc = []\n\n        # Determine which direction and in what order to place the widgets\n        posattr = [0] * 2\n        posdelta = [0] * 2\n        posstart = [0] * 2\n        for i in (0, 1):\n            posattr[i] = 1 * (orientation[i] in ('tb', 'bt'))\n            k = posattr[i]\n            if orientation[i] == 'lr':\n                # left to right\n                posdelta[i] = 1\n                posstart[i] = selfpos[k] + padding_left\n            elif orientation[i] == 'bt':\n                # bottom to top\n                posdelta[i] = 1\n                posstart[i] = selfpos[k] + padding_bottom\n            elif orientation[i] == 'rl':\n                # right to left\n                posdelta[i] = -1\n                posstart[i] = selfpos[k] + selfsize[k] - padding_right\n            else:\n                # top to bottom\n                posdelta[i] = -1\n                posstart[i] = selfpos[k] + selfsize[k] - padding_top\n\n        innerattr, outerattr = posattr\n        ustart, vstart = posstart\n        deltau, deltav = posdelta\n        del posattr, posdelta, posstart\n\n        u = ustart  # inner loop position variable\n        v = vstart  # outer loop position variable\n\n        # space calculation, used for determining when a row or column is full\n\n        if orientation[0] in ('lr', 'rl'):\n            lu = self.size[innerattr] - padding_x\n            sv = padding_y  # size in v-direction, for minimum_size property\n            su = padding_x  # size in h-direction\n            spacing_u = spacing_x\n            spacing_v = spacing_y\n        else:\n            lu = self.size[innerattr] - padding_y\n            sv = padding_x  # size in v-direction, for minimum_size property\n            su = padding_y  # size in h-direction\n            spacing_u = spacing_y\n            spacing_v = spacing_x\n\n        # space calculation, row height or column width, for arranging widgets\n        lv = 0\n\n        urev = (deltau < 0)\n        vrev = (deltav < 0)\n        for c in reversed(self.children):\n            # Issue#823: ReferenceListProperty doesn't allow changing\n            # individual properties.\n            # when the above issue is fixed we can remove csize from below and\n            # access c.size[i] directly\n            csize = c.size[:]  # we need to update the whole tuple at once.\n            if c.size_hint[0]:\n                # calculate width\n                csize[0] = c.size_hint[0] * (selfsize[0] - padding_x)\n            if c.size_hint[1]:\n                # calculate height\n                csize[1] = c.size_hint[1] * (selfsize[1] - padding_y)\n            c.size = tuple(csize)\n\n            # does the widget fit in the row/column?\n            if lu - c.size[innerattr] >= 0:\n                lc.append(c)\n                lu -= c.size[innerattr] + spacing_u\n                lv = max(lv, c.size[outerattr])\n                continue\n\n            # push the line\n            sv += lv + spacing_v\n            for c2 in lc:\n                if urev:\n                    u -= c2.size[innerattr] + spacing_u\n                p = [0, 0]  # issue #823\n                p[innerattr] = u\n                p[outerattr] = v\n                if vrev:\n                    # v position is actually the top/right side of the widget\n                    # when going from high to low coordinate values,\n                    # we need to subtract the height/width from the position.\n                    p[outerattr] -= c2.size[outerattr]\n                c2.pos = tuple(p)  # issue #823\n                if not urev:\n                    u += c2.size[innerattr] + spacing_u\n\n            v += deltav * lv\n            v += deltav * spacing_v\n            lc = [c]\n            lv = c.size[outerattr]\n            lu = selfsize[innerattr] - su - c.size[innerattr] - spacing_u\n            u = ustart\n\n        if lc:\n            # push the last (incomplete) line\n            sv += lv + spacing_v\n            for c2 in lc:\n                if urev:\n                    u -= c2.size[innerattr] + spacing_u\n                p = [0, 0]  # issue #823\n                p[innerattr] = u\n                p[outerattr] = v\n                if vrev:\n                    p[outerattr] -= c2.size[outerattr]\n                c2.pos = tuple(p)  # issue #823\n                if not urev:\n                    u += c2.size[innerattr] + spacing_u\n\n        minsize = self.minimum_size[:]  # issue #823\n        minsize[outerattr] = sv\n        self.minimum_size = tuple(minsize)\n", "path": "kivy/uix/stacklayout.py"}], "after_files": [{"content": "'''\nStack Layout\n============\n\n.. only:: html\n\n    .. image:: images/stacklayout.gif\n        :align: right\n\n.. only:: latex\n\n    .. image:: images/stacklayout.png\n        :align: right\n\n.. versionadded:: 1.0.5\n\n:class:`StackLayout` arranges children vertically or horizontally, as many\nas the layout can fit.\n\n\n.. warning:\n\n    This is experimental and subject to change as long as this warning notice is\n    present.\n\n'''\n\n__all__ = ('StackLayout', )\n\nfrom kivy.uix.layout import Layout\nfrom kivy.properties import NumericProperty, OptionProperty, \\\n    ReferenceListProperty, VariableListProperty\n\n\nclass StackLayout(Layout):\n    '''Stack layout class. See module documentation for more information.\n    '''\n\n    spacing = VariableListProperty([0, 0], length=2)\n    '''Spacing between children: [spacing_horizontal, spacing_vertical].\n\n    spacing also accepts a one argument form [spacing].\n\n    :data:`spacing` is a :class:`~kivy.properties.VariableListProperty`, default to\n    [0, 0].\n    '''\n\n    padding = VariableListProperty([0, 0, 0, 0])\n    '''Padding between layout box and children: [padding_left, padding_top,\n    padding_right, padding_bottom].\n\n    padding also accepts a two argument form [padding_horizontal,\n    padding_vertical] and a one argument form [padding].\n\n    .. versionchanged:: 1.7.0\n\n    Replaced NumericProperty with VariableListProperty.\n\n    :data:`padding` is a :class:`~kivy.properties.VariableListProperty`, default to\n    [0, 0, 0, 0].\n    '''\n\n    orientation = OptionProperty('lr-tb', options=(\n        'lr-tb', 'tb-lr', 'rl-tb', 'tb-rl', 'lr-bt', 'bt-lr', 'rl-bt', 'bt-rl'))\n    '''Orientation of the layout.\n\n    :data:`orientation` is an :class:`~kivy.properties.OptionProperty`, default\n    to 'lr-tb'.\n\n    Valid orientations are: 'lr-tb', 'tb-lr', 'rl-tb', 'tb-rl', 'lr-bt',\n    'bt-lr', 'rl-bt', 'bt-rl'\n\n    .. versionchanged:: 1.5.0\n\n        :data:`orientation` now correctly handles all valid combinations of\n        'lr','rl','tb','bt'. Before this version only 'lr-tb' and\n        'tb-lr' were supported, and 'tb-lr' was misnamed and placed\n        widgets from bottom to top and from right to left (reversed compared\n        to what was expected).\n\n    .. note::\n\n        lr mean Left to Right.\n        rl mean Right to Left.\n        tb mean Top to Bottom.\n        bt mean Bottom to Top.\n    '''\n\n    minimum_width = NumericProperty(0)\n    '''Minimum width needed to contain all children.\n\n    .. versionadded:: 1.0.8\n\n    :data:`minimum_width` is a :class:`kivy.properties.NumericProperty`, default\n    to 0.\n    '''\n\n    minimum_height = NumericProperty(0)\n    '''Minimum height needed to contain all children.\n\n    .. versionadded:: 1.0.8\n\n    :data:`minimum_height` is a :class:`kivy.properties.NumericProperty`,\n    default to 0.\n    '''\n\n    minimum_size = ReferenceListProperty(minimum_width, minimum_height)\n    '''Minimum size needed to contain all children.\n\n    .. versionadded:: 1.0.8\n\n    :data:`minimum_size` is a :class:`~kivy.properties.ReferenceListProperty` of\n    (:data:`minimum_width`, :data:`minimum_height`) properties.\n    '''\n\n    def __init__(self, **kwargs):\n        super(StackLayout, self).__init__(**kwargs)\n        self.bind(\n            padding=self._trigger_layout,\n            spacing=self._trigger_layout,\n            children=self._trigger_layout,\n            orientation=self._trigger_layout,\n            size=self._trigger_layout,\n            pos=self._trigger_layout)\n\n    def do_layout(self, *largs):\n        # optimize layout by preventing looking at the same attribute in a loop\n        selfpos = self.pos\n        selfsize = self.size\n        orientation = self.orientation.split('-')\n        padding_left = self.padding[0]\n        padding_top = self.padding[1]\n        padding_right = self.padding[2]\n        padding_bottom = self.padding[3]\n\n        padding_x = padding_left + padding_right\n        padding_y = padding_top + padding_bottom\n        spacing_x, spacing_y = self.spacing\n\n        lc = []\n\n        # Determine which direction and in what order to place the widgets\n        posattr = [0] * 2\n        posdelta = [0] * 2\n        posstart = [0] * 2\n        for i in (0, 1):\n            posattr[i] = 1 * (orientation[i] in ('tb', 'bt'))\n            k = posattr[i]\n            if orientation[i] == 'lr':\n                # left to right\n                posdelta[i] = 1\n                posstart[i] = selfpos[k] + padding_left\n            elif orientation[i] == 'bt':\n                # bottom to top\n                posdelta[i] = 1\n                posstart[i] = selfpos[k] + padding_bottom\n            elif orientation[i] == 'rl':\n                # right to left\n                posdelta[i] = -1\n                posstart[i] = selfpos[k] + selfsize[k] - padding_right\n            else:\n                # top to bottom\n                posdelta[i] = -1\n                posstart[i] = selfpos[k] + selfsize[k] - padding_top\n\n        innerattr, outerattr = posattr\n        ustart, vstart = posstart\n        deltau, deltav = posdelta\n        del posattr, posdelta, posstart\n\n        u = ustart  # inner loop position variable\n        v = vstart  # outer loop position variable\n\n        # space calculation, used for determining when a row or column is full\n\n        if orientation[0] in ('lr', 'rl'):\n            lu = self.size[innerattr] - padding_x\n            sv = padding_y  # size in v-direction, for minimum_size property\n            su = padding_x  # size in h-direction\n            spacing_u = spacing_x\n            spacing_v = spacing_y\n        else:\n            lu = self.size[innerattr] - padding_y\n            sv = padding_x  # size in v-direction, for minimum_size property\n            su = padding_y  # size in h-direction\n            spacing_u = spacing_y\n            spacing_v = spacing_x\n\n        # space calculation, row height or column width, for arranging widgets\n        lv = 0\n\n        urev = (deltau < 0)\n        vrev = (deltav < 0)\n        for c in reversed(self.children):\n            # Issue#823: ReferenceListProperty doesn't allow changing\n            # individual properties.\n            # when the above issue is fixed we can remove csize from below and\n            # access c.size[i] directly\n            csize = c.size[:]  # we need to update the whole tuple at once.\n            if c.size_hint[0]:\n                # calculate width\n                csize[0] = c.size_hint[0] * (selfsize[0] - padding_x)\n            if c.size_hint[1]:\n                # calculate height\n                csize[1] = c.size_hint[1] * (selfsize[1] - padding_y)\n            c.size = tuple(csize)\n\n            # does the widget fit in the row/column?\n            if lu - c.size[innerattr] >= 0:\n                lc.append(c)\n                lu -= c.size[innerattr] + spacing_u\n                lv = max(lv, c.size[outerattr])\n                continue\n\n            # push the line\n            sv += lv + spacing_v\n            for c2 in lc:\n                if urev:\n                    u -= c2.size[innerattr]\n                p = [0, 0]  # issue #823\n                p[innerattr] = u\n                p[outerattr] = v\n                if vrev:\n                    # v position is actually the top/right side of the widget\n                    # when going from high to low coordinate values,\n                    # we need to subtract the height/width from the position.\n                    p[outerattr] -= c2.size[outerattr]\n                c2.pos = tuple(p)  # issue #823\n                if urev:\n                    u -= spacing_u\n                else:\n                    u += c2.size[innerattr] + spacing_u\n\n            v += deltav * lv\n            v += deltav * spacing_v\n            lc = [c]\n            lv = c.size[outerattr]\n            lu = selfsize[innerattr] - su - c.size[innerattr] - spacing_u\n            u = ustart\n\n        if lc:\n            # push the last (incomplete) line\n            sv += lv + spacing_v\n            for c2 in lc:\n                if urev:\n                    u -= c2.size[innerattr]\n                p = [0, 0]  # issue #823\n                p[innerattr] = u\n                p[outerattr] = v\n                if vrev:\n                    p[outerattr] -= c2.size[outerattr]\n                c2.pos = tuple(p)  # issue #823\n                if urev:\n                    u -= spacing_u\n                else:\n                    u += c2.size[innerattr] + spacing_u\n\n        minsize = self.minimum_size[:]  # issue #823\n        minsize[outerattr] = sv\n        self.minimum_size = tuple(minsize)\n", "path": "kivy/uix/stacklayout.py"}]}