KivyMD icon indicating copy to clipboard operation
KivyMD copied to clipboard

MDButton animation incomplete when changing screens.

Open RobertFlatt opened this issue 4 months ago • 3 comments

Description of the Bug

When a button is used to switch screens, on returning to the first screen the button is seen as still elevated.

Seems to me like this is the expected behavior of Kivy (because the button is no longer visible it does not see the change in elevation event) but not of KivyMD.

It is possible this is an enhancement request. Since only the programmer knows the use of a button, the resolution may be to provide an api to allow the programmer to immediately reset the button elevation. A programmer might for example call this api on_release. Simply setting button.elevation = 0 from on_release does not have any effect.

In the example below, moving the cursor resets the elevation (presumably related to hover). This is not always the case, for example in tabs content, however this stickiness may be related to #1663 .

Code and Logs

from kivymd.app import MDApp
from kivy.lang import Builder

from kivymd.uix.screen import MDScreen
from kivymd.uix.screenmanager import MDScreenManager

Builder.load_string("""
<Screen1>:
    md_bg_color: self.theme_cls.backgroundColor
    MDBoxLayout:
        orientation:'vertical'
        MDLabel:
            text: 'Press "Go to Screen 2" Button'
            halign: "center"
        MDButton:
            on_release: root.manager.current = 'Two'
            pos_hint: {"center_x": .5, "center_y": .5}
            size_hint_y:0.5
            MDButtonText
                text: 'Go to Screen 2'
        MDLabel:

<Screen2>:
    md_bg_color: self.theme_cls.backgroundColor
    MDBoxLayout:
        orientation:'vertical'
        MDLabel:
            text: 'Press "Go to Screen 1" Button\\nThen look at the elevation of the Button in Screen 1\\nBEFORE moving the cursor,\\nTHEN move the cursor.'
            halign: "center"
        MDButton:
            style: "elevated"
            pos_hint: {"center_x": .5, "center_y": .5}
            on_release: root.manager.current = 'One'
            MDButtonText
                text: 'Go to Screen 1'
        MDLabel:
            size_hint_y:0.2
""")

class Screen1(MDScreen):
    pass

class Screen2(MDScreen):
    pass

class TestApp(MDApp):

    def build(self):
        sm = MDScreenManager()
        sm.add_widget(Screen1(name='One'))
        sm.add_widget(Screen2(name='Two'))
        return sm

TestApp().run()

Screenshots

Versions

  • OS: Windows 11
  • Python: 3.11.1
  • Kivy: 2.3.0
  • KivyMD: 2.0.1.dev0

RobertFlatt avatar Apr 11 '24 01:04 RobertFlatt