Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. from kivy.app import App
  2. from kivy.uix.scrollview import ScrollView
  3. from kivy.lang import Builder
  4. from kivy.properties import ObjectProperty
  5.  
  6. Builder.load_string("""
  7. <ScrollView>:
  8.    bar_width: 40
  9.    scroll_type: ['bars', 'content']
  10.  
  11. <Button>:
  12.    text: 'test'
  13.    size_hint_y: None
  14.    height: 100
  15.  
  16. <ScrollWrapper>:
  17.    mask: scroller
  18.    do_scroll_x: False
  19.    GridLayout:
  20.        padding: 40
  21.        cols: 1
  22.        size_hint: 1, None
  23.        height: self.minimum_height
  24.        Button:
  25.        ScrollView:
  26.            id: scroller
  27.            size_hint: 1, None
  28.            height: self.width
  29.            do_scroll_x: True
  30.            do_scroll_y: True
  31.            Label:
  32.                font_size: 500
  33.                size_hint: None, None
  34.                size: 1000, 1000
  35.                text: 'test'
  36.        Button:
  37. """)
  38.  
  39. class ScrollWrapper(ScrollView):
  40.     mask = ObjectProperty(allownone=True)
  41.     def on_touch_down(self, touch):
  42.         if self.mask:
  43.             coords = self.mask.to_parent(*self.mask.to_widget(*touch.pos))
  44.             collide = self.mask.collide_point(*coords)
  45.             if collide:
  46.                 touch.apply_transform_2d(self.mask.to_widget)
  47.                 touch.apply_transform_2d(self.mask.to_parent)
  48.                 self.mask.on_touch_down(touch)
  49.                 return True
  50.         super(ScrollWrapper, self).on_touch_down(touch)
  51.  
  52. class Test(App):
  53.     def build(self):
  54.         return ScrollWrapper()
  55.  
  56. if __name__ == '__main__':
  57.     Test().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement