KivyMD
KivyMD copied to clipboard
✓ KivyMD. Development - Bounty program
Hello everyone who helps the KivyMD library to develop!
If you have the desire and free time to fix bugs and introduce new functions to the KivyMD library, then you can do it for a monetary reward.
- [ ] Find a solution and fix the elevation behavior shader - $100
The problem is as follows:
We have already solved several problems related to elevation shaders. But it was a temporary solution, and as practice has shown, this solution is not too good and does not solve all problems. I see that there are real problems with the elevation shader that the contributors and I are trying to solve, but our solutions are more like crutches :)
It is quite obvious that the shader does not take into account the position of the parent widget and when using canvas instructions such as Rotation, Scale, the following happens:
Scale Bug
from kivymd.app import MDApp
from kivymd.uix.behaviors import ScaleBehavior
from kivymd.uix.relativelayout import MDRelativeLayout
KV = """
<RaisedButton@MDRaisedButton>
shadow_offset: 0, 2
shadow_softness: 8
shadow_radius: 4
elevation: 3
MDScreen:
ScaleBox:
id: box
md_bg_color: "lightgrey"
size_hint: .5, .5
pos_hint: {"center_x": .5, "center_y": .5}
RaisedButton:
text: "RaisedButton"
pos_hint: {"center_x": .5, "center_y": .5}
RaisedButton:
pos_hint: {"center_x": .5}
y: "36dp"
text: "Do Scale"
on_release: app.do_scale()
"""
class ScaleBox(MDRelativeLayout, ScaleBehavior):
pass
class Example(MDApp):
def do_scale(self):
Animation(
scale_value_x=0.8, scale_value_y=0.8, d=0.5
).start(self.root.ids.box)
def build(self):
# self.fps_monitor_start()
return Builder.load_string(KV)
Example().run()
https://user-images.githubusercontent.com/16930280/190712048-2185f908-1765-49d9-bec8-6adfda696186.mov
I tried to bind to the scale_value_x property a call to the on_size method in the CommonElevationBehavior class and change the size of the canvas on which the shader is running in this label. This solves the problem only for the widget itself. But if a widget with elevation behavior is inside, for example, a more complex widget, then this does not work. We need to build a widget tree of the root layout, search in this tree for the widget itself with the elevation behavior and it also looks like crutches...
Rotate Bug
from kivymd.app import MDApp
from kivymd.uix.behaviors import RotateBehavior, CommonElevationBehavior
from kivymd.uix.relativelayout import MDRelativeLayout
KV = """
<RaisedButton@MDRaisedButton>
shadow_offset: 0, 2
shadow_softness: 8
shadow_radius: 4
elevation: 3
MDScreen:
RotateBox:
id: box
md_bg_color: "lightgrey"
size_hint: .5, .5
pos_hint: {"center_x": .5, "center_y": .5}
elevation: 3
shadow_radius: 8
radius: 8
RaisedButton:
pos_hint: {"center_x": .5}
y: "36dp"
text: "Do Scale"
on_release: app.do_scale()
"""
class RotateBox(MDRelativeLayout, CommonElevationBehavior, RotateBehavior):
pass
class Example(MDApp):
def do_scale(self):
Animation(rotate_value_angle=45).start(self.root.ids.box)
def build(self):
# self.fps_monitor_start()
return Builder.load_string(KV)
Example().run()
https://user-images.githubusercontent.com/16930280/190712874-4d513cae-cf10-45d3-b8f7-f6d064d6eca6.mov
If you look at how many PRs related to the introduction of elevation, you will see that these are temporary solutions that do not actually solve the problem: