kivymd / KivyMD

KivyMD is a collection of Material Design compliant widgets for use with Kivy, a framework for cross-platform, touch-enabled graphical applications. https://youtube.com/c/KivyMD https://twitter.com/KivyMD https://habr.com/ru/users/kivymd https://stackoverflow.com/tags/kivymd
https://kivymd.readthedocs.io
MIT License
2.14k stars 655 forks source link

Widget rotation button press not working properly #1626

Closed Sahil-pixel closed 4 months ago

Sahil-pixel commented 4 months ago

Description of the Bug

i have custom widget contain 4 button in a boxlayout and i want rotate 180 degree but button press not taking from right widget .

please see video and pointer to press button

Code and Logs


class TPGamePlate(RotateBehavior,MDBoxLayout,):
    question=StringProperty('')
    chack_result=ObjectProperty(None)
     #def check_result(self,obj):
     #  print(obj)

<TPGameScreen>:
    MDBoxLayout:
        orientation:'vertical'

        TPGamePlate:
            rotate_value_angle:180
            check_result:root.check_result
        Widget:

<TPGamePlate>:

    size_hint_y:None
    height:self.minimum_height
    spacing:'8dp'
    orientation:'vertical'

    MDLabel:
        theme_font_size: "Custom"
        font_size:'50sp'
        text:'3x10=?'
        #id:_question_id
        center_x: 0.5
        halign:'center'
        #size:self.texture_size
    Widget:

    MDGridLayout:
        cols:2
        size_hint:1,None
        height:self.minimum_height
        padding:['8dp',0,'8dp',0]
        pacing:['8dp']
        #pos_hint:{'center_x':0.5,'y':0.01}
        id:gid_id

        MDButton:
            style: "filled"
            theme_width: "Custom"
            height:'60dp'

            size_hint_x:0.5
            on_press:
                root.check_result(o1)

            MDButtonText:

                text: "Filled"
                id:o1
                halign:'center'
                pos_hint: {"center_x": .5, "center_y": .5}
                theme_font_size: "Custom"
                font_size:'30sp'

        MDButton:
            style: "filled"
            theme_width: "Custom"

            size_hint_x:0.5
            height:'60dp'
            on_press:root.check_result(o2)

            MDButtonText:
                id:o2

                text: "Filled"
                pos_hint: {"center_x": .5, "center_y": .5}
                theme_font_size: "Custom"
                font_size:'30sp'
        MDButton:
            style: "filled"
            theme_width: "Custom"

            size_hint_x:0.5
            height:'60dp'
            on_press:root.check_result(o3)

            MDButtonText:
                id:o3
                text: "Filled"
                halign:'center'
                pos_hint: {"center_x": .5, "center_y": .5}
                theme_font_size: "Custom"
                font_size:'30sp'

        MDButton:
            style: "filled"
            theme_width: "Custom"

            size_hint_x:0.5
            height:'60dp'
            on_press:root.check_result(o4)

            MDButtonText:
                id:o4

                text: "Filled"
                pos_hint: {"center_x": .5, "center_y": .5}
                theme_font_size: "Custom"
                font_size:'30sp'

### Screenshots

https://github.com/kivymd/KivyMD/assets/57060638/f6c66410-b893-43cf-a2a3-d3eb5399078f

### Versions

* OS: 
* Python: 3.10.
* Kivy: 2.3.0
* KivyMD: 2.0.0dev
HeaTTheatR commented 4 months ago

Attach minimal code

Sahil-pixel commented 4 months ago

button taking touch from wrong place . please run code and press button


from kivy.lang import Builder
from kivy.uix.behaviors import ButtonBehavior

from kivymd.app import MDApp
from kivymd.uix.behaviors import RotateBehavior
from kivymd.uix.boxlayout import MDBoxLayout

KV = '''
MDScreen:
    md_bg_color: app.theme_cls.surfaceColor
    RotateBox:
        size_hint: .5, .5
        pos_hint: {"center_x": .5, "center_y": .5}
        #on_release: app.change_rotate(self)
        md_bg_color: "red"
        rotate_value_angle:180
        MDButton:
            style: "elevated"
            #pos_hint: {"center_x": .5, "center_y": .5}
            on_press:print(self,1)
            MDButtonText:
                text: "Elevated"

'''

class RotateBox(RotateBehavior, MDBoxLayout,):
    pass

class Test(MDApp):
    def build(self):
        return Builder.load_string(KV)

    def change_rotate(self, instance_button: RotateBox) -> None:
        Animation(rotate_value_angle=45, d=0.3).start(instance_button)

Test().run() 
T-Dynamos commented 4 months ago

Obviously it's expected, touch is detected when touch.pos collides with widget size and postion. But rotation is just like an "effect" which does not change the position of widget.

If you really want this kind of behaviour, make your own button class, then set postion yourself and rotate the label only.

T-Dynamos commented 4 months ago

Same can be done without kivymd, with just simple kivy

Closing as it's not kivymd related issue.