why button in float layout not getiing touch

25 views
Skip to first unread message

Degenerate Tech

unread,
Jun 27, 2024, 10:37:49 AM (6 days ago) Jun 27
to Kivy users support
This is  an reels video view application like intsagram , i have used scrollview to scroll video widget . problem is when i am pressing buttons in MDFloatLayout buttons not getting always touch .
see codes of in videocard.py

<VideoCard>:
    md_bg_color: [0, 0, 0, 1]
    size_hint_y: None
    video_state: 'stop'
    MDFloatLayout:
        Video:
            source: root.data['source']
            state: root.video_state
            pos_hint: {'center_x':.5, 'top':1}
            id:vid
       
        MDIconButton:
            icon:'play' if vid.state=='stop' else 'pause'
            theme_font_size:'Custom'
            theme_icon_color:'Custom'
            icon_color:'white'
            font_size:'50sp'
            pos_hint:{'center_x':0.5,'center_y':0.5}
            on_release:
                root._callback(vid)
        MDIconButton:
            icon:'magnify'
            pos_hint:{'center_x':0.5,'y':0.3}
            theme_font_size:'Custom'
            theme_icon_color:'Custom'
            icon_color:'white'
            font_size:'100sp'
        Button:
            size_hint:None,None
            size:'50dp','50dp'
            text:'Play'
            pos_hint:{'center_x':0.5,'center_y':0.8}
            on_press:print('Hello')


snapscroll.py
videocard.py
main.py
ui11.kv

ELLIOT GARBUS

unread,
Jun 28, 2024, 11:35:29 AM (4 days ago) Jun 28
to kivy-...@googlegroups.com
I see two issues.
  1. The button is covered by a BoxLayout.  Use the inspector to see it.
  2. The button is in a scroll view.  Set a shorter scroll_timeout value for a more responsive button.

From: kivy-...@googlegroups.com <kivy-...@googlegroups.com> on behalf of Degenerate Tech <sksah...@gmail.com>
Sent: Thursday, June 27, 2024 7:37 AM
To: Kivy users support <kivy-...@googlegroups.com>
Subject: [kivy-users] why button in float layout not getiing touch
 
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/592e0a73-1ea2-4391-83b1-71b158060b4dn%40googlegroups.com.

Degenerate Tech

unread,
Jun 28, 2024, 12:38:34 PM (4 days ago) Jun 28
to Kivy users support
solved .
from kivy.lang.builder import Builder
from kivy.uix.scrollview import ScrollView
from kivy.properties import ObjectProperty
from kivy.metrics import dp
Builder.load_string(
"""
<SnapScroll>:
    scroll_distance: dp(500) # helps prevent kivy detecting multiple scroll in one drag.
    bar_width: 0
    scroll_wheel_distance: 0 # disable mouse scrolling
"""
)

class SnapScroll(ScrollView):
    layout = ObjectProperty() # The adaptive layout inside the scrollview; where widgets are added to

    def on_scroll_start(self, touch, check_children=True):
        touch.ud['pos'] = self.to_local(*touch.pos) # saving the touch pos clicked by the user.
        for widget in self.layout.children: # Looping through all widget to get the clicked widget
            if widget != self:
                if widget.collide_point(*touch.ud['pos']):
                    touch.ud['widget'] = widget # saving the widget that recieved the touch
                    touch.ud['index'] = self.layout.children.index(widget) # and its index

        return super().on_scroll_start(touch, check_children=check_children) # Make sure you return this

    def on_scroll_stop(self, touch, check_children=True):
        self._touch = None # cancel touch
        local_touch = self.to_local(*touch.pos)

        if local_touch[1] > touch.ud['pos'][1]: # Comparing current touch pos with the one we saved.
                                                # to know the direction the user is scrolling.
            if touch.ud['index'] != 0: # If widget is not the first, scroll up
                self.scroll_to(self.layout.children[touch.ud['index']-1], padding=0)
                self.layout.children[touch.ud['index']-1].video_state = 'play' # play next video
                self.layout.children[touch.ud['index']].video_state = 'pause' # pause current video
            touch.ud.pop('pos')
            return True

        elif local_touch[1] < touch.ud['pos'][1]:
            if touch.ud['index'] < len(self.layout.children)-1: # If widget is not the last, scroll down
                self.scroll_to(self.layout.children[touch.ud['index']+1], padding=0)

                self.layout.children[touch.ud['index']+1].video_state = 'play' # play prev video
                self.layout.children[touch.ud['index']].video_state = 'pause' # pause current video
            touch.ud.pop('pos')
            return True

         # we are done with the pos we save so we clear it
        return  super().on_scroll_stop(touch, check_children=check_children)
Reply all
Reply to author
Forward
0 new messages