diff --git a/examples/widgets/scrollview.py b/examples/widgets/scrollview.py index 27140b18f..66e4c2b7e 100644 --- a/examples/widgets/scrollview.py +++ b/examples/widgets/scrollview.py @@ -1,3 +1,6 @@ +import kivy +kivy.require('1.0.8') + from kivy.app import App from kivy.core.window import Window from kivy.uix.button import Button @@ -8,13 +11,24 @@ from kivy.uix.gridlayout import GridLayout class ScrollViewApp(App): def build(self): + + # create a default grid layout with custom width/height layout = GridLayout(cols=1, spacing=10, size_hint=(None, None), width=500) + + # when we add children to the grid layout, its size doesn't change at + # all. we need to ensure that the height will be the minimum required to + # contain all the childs. (otherwise, we'll child outside the bounding + # box of the childs) + layout.bind(minimum_height=layout.setter('height')) + + # add button into that grid for i in range(30): btn = Button(text=str(i), size=(480, 40), size_hint=(None, None)) layout.add_widget(btn) + # create a scroll view, with a size < size of the grid root = ScrollView(size_hint=(None, None)) root.size = (480, 320) root.center = Window.center @@ -23,4 +37,5 @@ class ScrollViewApp(App): return root if __name__ == '__main__': + ScrollViewApp().run() diff --git a/kivy/uix/gridlayout.py b/kivy/uix/gridlayout.py index 165b92cc3..d241043ac 100644 --- a/kivy/uix/gridlayout.py +++ b/kivy/uix/gridlayout.py @@ -80,7 +80,7 @@ from kivy.clock import Clock from kivy.logger import Logger from kivy.uix.layout import Layout from kivy.properties import NumericProperty, BooleanProperty, DictProperty, \ - BoundedNumericProperty + BoundedNumericProperty, ReferenceListProperty from math import ceil @@ -184,10 +184,36 @@ class GridLayout(Layout): to {} ''' + minimum_width = NumericProperty(0) + '''Minimum width needed to contain all childrens. + + .. versionadded:: 1.0.8 + + :data:`minimum_width` is a :class:`kivy.properties.NumericProperty`, default + to 0. + ''' + + minimum_height = NumericProperty(0) + '''Minimum height needed to contain all childrens. + + .. versionadded:: 1.0.8 + + :data:`minimum_height` is a :class:`kivy.properties.NumericProperty`, default + to 0. + ''' + + minimum_size = ReferenceListProperty(minimum_width, minimum_height) + '''Minimum size needed to contain all childrens. + + .. versionadded:: 1.0.8 + + :data:`minimum_size` is a :class:`~kivy.properties.ReferenceListProperty` of + (:data:`minimum_width`, :data:`minimum_height`) properties. + ''' + def __init__(self, **kwargs): self._cols = self._rows = None self._trigger_layout = Clock.create_trigger(self.do_layout, -1) - self._minimum_size = [0, 0] super(GridLayout, self).__init__(**kwargs) self.bind( @@ -311,7 +337,7 @@ class GridLayout(Layout): self._rows_sh = rows_sh # finally, set the minimum size - self._minimum_size = (width, height) + self.minimum_size = (width, height) def do_layout(self, *largs): self.update_minimum_size() @@ -341,7 +367,7 @@ class GridLayout(Layout): cols = self._cols[:] cols_sh = self._cols_sh cols_weigth = sum([x for x in cols_sh if x]) - strech_w = max(0, selfw - self._minimum_size[0]) + strech_w = max(0, selfw - self.minimum_width) for index in xrange(len(cols)): # if the col don't have strech information, nothing to do col_stretch = cols_sh[index] @@ -362,7 +388,7 @@ class GridLayout(Layout): rows = self._rows[:] rows_sh = self._rows_sh rows_weigth = sum([x for x in rows_sh if x]) - strech_h = max(0, selfh - self._minimum_size[1]) + strech_h = max(0, selfh - self.minimum_height) for index in xrange(len(rows)): # if the row don't have strech information, nothing to do row_stretch = rows_sh[index] diff --git a/kivy/uix/stacklayout.py b/kivy/uix/stacklayout.py index ea8c1f3cc..42c4b7556 100644 --- a/kivy/uix/stacklayout.py +++ b/kivy/uix/stacklayout.py @@ -4,7 +4,7 @@ Stack Layout .. versionadded:: 1.0.5 -:class:`StackLayout` arranges children vertically or horizontally, as many +:class:`StackLayout` arranges children vertically or horizontally, as many as the layout can fit. .. warning: @@ -55,6 +55,8 @@ class StackLayout(Layout): minimum_width = NumericProperty(0) '''Minimum width needed to contain all childrens. + .. versionadded:: 1.0.8 + :data:`minimum_width` is a :class:`kivy.properties.NumericProperty`, default to 0. ''' @@ -62,13 +64,17 @@ class StackLayout(Layout): minimum_height = NumericProperty(0) '''Minimum height needed to contain all childrens. - :data:`minimum_height` is a :class:`kivy.properties.NumericProperty`, default - to 0. + .. versionadded:: 1.0.8 + + :data:`minimum_height` is a :class:`kivy.properties.NumericProperty`, + default to 0. ''' minimum_size = ReferenceListProperty(minimum_width, minimum_height) '''Minimum size needed to contain all childrens. + .. versionadded:: 1.0.8 + :data:`minimum_size` is a :class:`~kivy.properties.ReferenceListProperty` of (:data:`minimum_width`, :data:`minimum_height`) properties. '''