Skip to content

Commit

Permalink
Add on_md_bg_color method
Browse files Browse the repository at this point in the history
The method animates the `md_bg_color` value for the canvas instructions
of the background color of the widgets.
  • Loading branch information
HeaTTheatR committed Aug 29, 2022
1 parent 5597afd commit 558d56e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions kivymd/uix/behaviors/backgroundcolor_behavior.py
Expand Up @@ -7,8 +7,9 @@

__all__ = ("BackgroundColorBehavior", "SpecificBackgroundColorBehavior")

from typing import List
from typing import List, Union

from kivy.animation import Animation
from kivy.lang import Builder
from kivy.properties import (
ColorProperty,
Expand Down Expand Up @@ -37,7 +38,7 @@
angle: self.angle
origin: self._background_origin
Color:
rgba: self.md_bg_color
rgba: self._md_bg_color
RoundedRectangle:
group: "Background_instruction"
size: self.size
Expand Down Expand Up @@ -156,11 +157,21 @@ class BackgroundColorBehavior(Widget):
_background_x,
_background_y,
)
_md_bg_color = ColorProperty([0, 0, 0, 0])

def __init__(self, **kwarg):
super().__init__(**kwarg)
self.bind(pos=self.update_background_origin)

def on_md_bg_color(self, instance_md_widget, color: Union[list, str]):
if (
hasattr(self, "theme_cls")
and self.theme_cls.theme_style_switch_animation
):
Animation(_md_bg_color=color, d=0.2, t="linear").start(self)
else:
self._md_bg_color = color

def update_background_origin(
self, instance_md_widget, pos: List[float]
) -> None:
Expand Down

0 comments on commit 558d56e

Please sign in to comment.