changeset 241:661b9cf7b4e4

xmlui: scroll/size fixes: - VerticalContainer and TabsPanelContainer are now put in ScrollView - the height hack in TabsContainer has been removed has it is not needed anymore (minimum_height is now available) - remove the empty widget which was added at the end of main panel, it's better to have the UI taking the whole container height - fixed height for TextWidget,LabelWidget and JidWidget - better scrollbar for VerticalContainer and TabsPanelContainer
author Goffi <goffi@goffi.org>
date Thu, 03 Jan 2019 10:42:43 +0100
parents f555b10712d7
children c2503168fab7
files cagou/core/xmlui.py cagou/kv/xmlui.kv
diffstat 2 files changed, 41 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/cagou/core/xmlui.py	Sat Oct 06 09:48:52 2018 +0200
+++ b/cagou/core/xmlui.py	Thu Jan 03 10:42:43 2019 +0100
@@ -22,6 +22,7 @@
 from sat.core.log import getLogger
 log = getLogger(__name__)
 from sat_frontends.tools import xmlui
+from kivy.uix.scrollview import ScrollView
 from kivy.uix.boxlayout import BoxLayout
 from kivy.uix.gridlayout import GridLayout
 from kivy.uix.tabbedpanel import TabbedPanel, TabbedPanelItem
@@ -278,14 +279,15 @@
 ## Containers ##
 
 
-class VerticalContainer(xmlui.VerticalContainer, BoxLayout):
+class VerticalContainer(xmlui.VerticalContainer, ScrollView):
+    layout = properties.ObjectProperty(None)
 
     def __init__(self, xmlui_parent):
         self.xmlui_parent = xmlui_parent
-        BoxLayout.__init__(self, orientation="vertical")
+        ScrollView.__init__(self)
 
     def _xmluiAppend(self, widget):
-        self.add_widget(widget)
+        self.layout.add_widget(widget)
 
 
 class PairsContainer(xmlui.PairsContainer, GridLayout):
@@ -303,19 +305,16 @@
 
 
 class TabsPanelContainer(TabbedPanelItem):
+    layout = properties.ObjectProperty(None)
 
     def _xmluiAppend(self, widget):
-        self.add_widget(widget)
+        self.layout.add_widget(widget)
 
 
 class TabsContainer(xmlui.TabsContainer, TabbedPanel):
 
     def __init__(self, xmlui_parent):
         self.xmlui_parent = xmlui_parent
-        xmlui_panel = xmlui_parent
-        while not isinstance(xmlui_panel, XMLUIPanel):
-            xmlui_panel = xmlui_panel.xmlui_parent
-        xmlui_panel.addPostTreat(self._postTreat)
         TabbedPanel.__init__(self, do_default_tab=False)
 
     def _xmluiAddTab(self, label, selected):
@@ -323,17 +322,6 @@
         self.add_widget(tab)
         return tab
 
-    def _postTreat(self):
-        """bind minimum height of tabs' content so self.height is adapted"""
-        # we need to do this in postTreat because contents exists after UI construction
-        for t in self.tab_list:
-            t.content.bind(minimum_height=self._updateHeight)
-
-    def _updateHeight(self, instance, height):
-        """Called after UI is constructed (so height can be calculated)"""
-        # needed because TabbedPanel doesn't have a minimum_height property
-        self.height = max([t.content.minimum_height for t in self.tab_list]) + self.tab_height + 5
-
 
 class AdvancedListRow(GridLayout):
     global_index = 0
@@ -514,7 +502,7 @@
     widget_factory = WidgetFactory()
 
     def __init__(self, host, parsed_xml, title=None, flags=None, callback=None, ignore=None, whitelist=None, profile=C.PROF_KEY_NONE):
-        BoxLayout.__init__(self, orientation="vertical")
+        BoxLayout.__init__(self)
         self.close_cb = None
         self._post_treats = []  # list of callback to call after UI is constructed
         xmlui.XMLUIPanel.__init__(self,
@@ -569,7 +557,6 @@
             self.save_btn = FormButton(text=_(u"Save"), disabled=True)
             self.save_btn.bind(on_press=self._saveButtonCb)
             self.add_widget(self.save_btn)
-        self.add_widget(Widget())  # to have elements on the top
 
     def show(self, *args, **kwargs):
         if not self.user_action and not kwargs.get("force", False):
--- a/cagou/kv/xmlui.kv	Sat Oct 06 09:48:52 2018 +0200
+++ b/cagou/kv/xmlui.kv	Thu Jan 03 10:42:43 2019 +0100
@@ -20,13 +20,19 @@
 <Title>:
     color: 1, 1, 1, 1
 
-
-<EmptyWidget,TextWidget,LabelWidget,JidWidget,StringWidget,PasswordWidget,JidInputWidget>:
+<EmptyWidget,StringWidget,PasswordWidget,JidInputWidget>:
     size_hint: 1, None
     height: dp(common_height)
     color: 1, 1, 1, 1
 
 
+<TextWidget,LabelWidget,JidWidget>:
+    size_hint: 1, None
+    text_size: self.width, None
+    height: max(dp(common_height), self.texture_size[1])
+    color: 1, 1, 1, 1
+
+
 <StringWidget,PasswordWidget,IntWidget>:
     multiline: False
     background_normal: app.expand('atlas://data/images/defaulttheme/textinput')
@@ -92,8 +98,16 @@
 
 
 <VerticalContainer>:
-    size_hint: 1, None
-    height: self.minimum_height
+    size_hint: 1, 1
+    layout: layout
+    do_scroll_x: False
+    scroll_type: ['bars', 'content']
+    bar_width: dp(6)
+    BoxLayout:
+        id: layout
+        orientation: "vertical"
+        size_hint: 1, None
+        height: self.minimum_height
 
 
 <PairsContainer>:
@@ -103,7 +117,19 @@
 
 
 <TabsContainer>:
-    size_hint: 1, None
+    size_hint: 1, 1
+
+<TabsPanelContainer>:
+    layout: layout
+    ScrollView:
+        do_scroll_x: False
+        scroll_type: ['bars', 'content']
+        bar_width: dp(6)
+        BoxLayout:
+            id: layout
+            orientation: "vertical"
+            size_hint: 1, None
+            height: self.minimum_height
 
 <FormButton>:
     size_hint: 1, None
@@ -134,7 +160,8 @@
 
 
 <XMLUIPanel>:
-    height: self.minimum_height
+    orientation: "vertical"
+    size_hint: 1, 1
     canvas.before:
         Color:
             rgba: 0, 0, 0, 1