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.23k stars 672 forks source link

Ripplebehavior redraws the canvas unexpectedly #525

Open neo-mashiro opened 4 years ago

neo-mashiro commented 4 years ago

Description of the Bug

I have a BoxLayout and a FloatLayout, stacked vertically. The BoxLayout has some kivyMD buttons, the FloatLayout draws a background image. All the buttons work fine except for the last one, whenever I click on the last button, it changes the canvas opacity of the FloatLayout below it and redraws the background. I don't understand why clicking the button would change things in other layouts.

Regardless of how many buttons I have, it's always the last button that misbehaves. I can replicate this with any kind of kivyMD buttons, such as MDIconButton, MDFlatButton or MDRectangleFlatButton.

Interestingly enough, if I just use the original kivy buttons "Button", this will not be observed.

A minimal example

from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.uix.boxlayout import BoxLayout

Builder.load_string('''
<Root>:
    orientation: 'vertical'

    BoxLayout:
        MDRectangleFlatButton:
            text: 'button1'
            on_press: pass

        MDRectangleFlatButton:
            text: 'button2'
            on_press: pass

        MDRectangleFlatButton:
            text: 'button3'
            on_press: pass

    FloatLayout:
        canvas:
            Rectangle:
                pos: self.pos
                size: self.size
                source: '../assets/table.png'
''')

class Root(BoxLayout):
    ...

class Game(MDApp):
    def build(self):
        return Root()

if __name__ == '__main__':
    Game().run()

Demo

demo

Versions

podraco commented 4 years ago

That's a strange behavior, but the buttons lib is being work on, check the pull request

501

neo-mashiro commented 4 years ago

I've tried the latest master version, and the bug persisted. Will try again once the PR is merged.

I'm pretty sure it's related to the button animation. That explains why the canvas background "fades away" at exactly the same pace as the button does if you look at it closely, and why the kivy original static button works fine. Just press the MDbutton, hold the press without releasing it, you will see how the button animation synchronizes with the canvas.

podraco commented 4 years ago

this is not a button problem but a ripple effect bug so far i know, the ripple effect draws in the canvas and canvas.after

podraco commented 4 years ago

it might be a good idea to use a canvas instruction group to restrict the effect in a "layer"

podraco commented 4 years ago

also, you need to add a color before the canvas instruction, othewise it will lookup for the lastes color instruction before your instruction inside the canvas

podraco commented 4 years ago
FloatLayout:
        canvas:
            Color:
                rgba:1,1,1,1
            Rectangle:
                pos: self.pos
                size: self.size
                source: '../assets/table.png'
neo-mashiro commented 4 years ago

adding the color before the canvas instruction fixed the problem, thanks!

podraco commented 4 years ago

i may say that this bug is low priority since it's mostly the order which the canvas is drawn

podraco commented 4 years ago

i would suggest you to change the tittle to:

Ripplebehavior redraws the canvas unexpectedly

since this error is mostly the canvas where ripple behavior works

neo-mashiro commented 4 years ago

@podraco done