Repository: kivy/kivy

Issue:
Splitter doesn't respect max_size upon resize (it doesn't resize proportionally)
When you have a Splitter in e.g. a boxlayout with some maximum size that depends on another widget's size, max_size is not respected. Also, I'd be nice, if when resizing the parent, the splitter's size adjusts itself proportionally to what it was before.

To see the issue, run the following code, maximize the window, move the splitter all the way to the left, and resize the window to a smaller size. The splitter will now be larger than the specified max_size:

```
from kivy.base import runTouchApp
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder


kv = '''
<Test>:
    Label:
        text: 'left'
    Splitter:
        max_size: self.parent.width - 200
        Label:
            text: 'right'


'''
Builder.load_string(kv)

class Test(BoxLayout):
    pass

if __name__ == '__main__':
    runTouchApp(Test())
```



Discussion:
I tried your code and everything seems to work fine here, try displaying
the value on the label to get a idea. I tried the following change to your
code for more visual feedback::

```
from kivy.base import runTouchApp
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder

kv = '''
<Test>:
    Label:
        text: 'left'
    Splitter:
        id:spl
        max_size: self.parent.width - 200
        Label:
            text:
                'splitter.width: {}\\nparent.width: {}\\nmax_size: {}'\
                .format(spl.width, root.width, spl.max_size)
'''
Builder.load_string(kv)

class Test(BoxLayout):
    pass

if __name__ == '__main__':
    runTouchApp(Test())
```

Splitter adjusting proportionally to what place it was before might not be
what every one needs, maybe a option for this would be better?

On Fri, Jan 24, 2014 at 3:51 AM, matham notifications@github.com wrote:

> When you have a Splitter in e.g. a boxlayout with some maximum size that
> depends on another widget's size, max_size is not respected. Also, I'd be
> nice, if when resizing the parent, the splitter's size adjusts itself
> proportionally to what it was before.
> 
> To see the issue, run the following code, maximize the window, move the
> splitter all the way to the left, and resize the window to a smaller size.
> The splitter will now be larger than the specified max_size:
> 
> from kivy.base import runTouchApp
> from kivy.uix.boxlayout import BoxLayout
> from kivy.lang import Builder
> 
> kv = '''
> <Test>:
>     Label:
>         text: 'left'
>     Splitter:
>         max_size: self.parent.width - 200
>         Label:
>             text: 'right'
> 
> '''
> Builder.load_string(kv)
> 
> class Test(BoxLayout):
>     pass
> 
> if **name** == '**main**':
>     runTouchApp(Test())
> 
> —
> Reply to this email directly or view it on GitHubhttps://github.com/kivy/kivy/issues/1810
> .

I do see the following issue though. The splitter on resize should make sure to adjust itself so as to maintain itself withing the min/max_size.


Resolving patch:
diff --git a/kivy/uix/splitter.py b/kivy/uix/splitter.py
--- a/kivy/uix/splitter.py
+++ b/kivy/uix/splitter.py
@@ -136,6 +136,9 @@ def __init__(self, **kwargs):
         self._container = None
         self._strip = None
         super(Splitter, self).__init__(**kwargs)
+        self.bind(size=self._do_size,
+                  max_size=self._do_size,
+                  min_size=self._do_size)
 
     def on_sizable_from(self, instance, sizable_from):
         if not instance._container:
@@ -215,6 +218,12 @@ def strip_down(self, instance, touch):
     def on_press(self):
         pass
 
+    def _do_size(self, instance, value):
+        if self.sizable_from[0] in ('l', 'r'):
+            self.width = max(self.min_size, min(self.width, self.max_size))
+        else:
+            self.height = max(self.min_size, min(self.height, self.max_size))
+
     def strip_move(self, instance, touch):
         if touch.grab_current is not instance:
             return False


Test patch: