KivyMD icon indicating copy to clipboard operation
KivyMD copied to clipboard

Ripplebehavior redraws the canvas unexpectedly

Open neo-mashiro opened this issue 3 years ago • 10 comments

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

  • OS: Ubuntu 16.04
  • Python: v3.6.2
  • Kivy: v1.11.1
  • KivyMD: v0.104.1

neo-mashiro avatar Sep 15 '20 23:09 neo-mashiro

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

podraco avatar Sep 16 '20 04:09 podraco

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.

neo-mashiro avatar Sep 16 '20 07:09 neo-mashiro

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 avatar Sep 16 '20 07:09 podraco

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

podraco avatar Sep 16 '20 07:09 podraco

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 avatar Sep 16 '20 07:09 podraco

FloatLayout:
        canvas:
            Color:
                rgba:1,1,1,1
            Rectangle:
                pos: self.pos
                size: self.size
                source: '../assets/table.png'

podraco avatar Sep 16 '20 07:09 podraco

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

neo-mashiro avatar Sep 16 '20 07:09 neo-mashiro

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

podraco avatar Sep 16 '20 08:09 podraco

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

podraco avatar Sep 26 '20 17:09 podraco

@podraco done

neo-mashiro avatar Sep 26 '20 21:09 neo-mashiro