Skip to content

Commit

Permalink
Fix elevation properties
Browse files Browse the repository at this point in the history
  • Loading branch information
HeaTTheatR committed Jan 28, 2024
1 parent 1ba39eb commit b34b07f
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 71 deletions.
14 changes: 10 additions & 4 deletions kivymd/uix/behaviors/elevation.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,7 @@ def build(self):
size: self.size
offset: root.shadow_offset
spread_radius: -(root.shadow_softness), -(root.shadow_softness)
blur_radius: root.elevation_levels[root.elevation_level] * 2.5
# blur_radius: root.elevation * 10
blur_radius: root.elevation_levels[root.elevation_level]
border_radius:
(root.radius if hasattr(self, "radius") and root.radius else [0, 0, 0, 0]) \
if root.shadow_radius == [0.0, 0.0, 0.0, 0.0] else \
Expand Down Expand Up @@ -425,7 +424,14 @@ class documentation.
"""

elevation_levels = DictProperty(
{0: 0, 1: dp(1.5), 2: dp(3), 3: dp(6), 4: dp(8), 5: dp(12)}
{
0: 0,
1: dp(8),
2: dp(12),
3: dp(16),
4: dp(20),
5: dp(24),
}
)
"""
Elevation is measured as the distance between components along the z-axis
Expand All @@ -434,7 +440,7 @@ class documentation.
.. versionadded:: 1.2.0
:attr:`elevation_levels` is an :class:`~kivy.properties.DictProperty`
and defaults to `{0: dp(0), 1: dp(1), 2: dp(3), 3: dp(6), 4: dp(8), 5: dp(12)}`.
and defaults to `{0: dp(0), 1: dp(8), 2: dp(3), 3: dp(6), 4: dp(8), 5: dp(12)}`.
"""

elevation = BoundedNumericProperty(0, min=0, errorvalue=0)
Expand Down
28 changes: 11 additions & 17 deletions kivymd/uix/button/button.kv
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,20 @@
}[self.style]
shadow_radius:
{ \
"standard": [dp(12), ], \
"small": [dp(8), ], \
"large": [dp(24), ], \
"standard": [dp(14), ], \
"small": [dp(10), ], \
"large": [dp(26), ], \
}[self.style]
shadow_offset: 0, -1
shadow_softness:
{ \
"standard": 2, \
"small": 2, \
"large": 2, \
}[self.style]
elevation_level:
{ \
"standard": 2, \
"small": 2, \
"large": 2, \
"standard": 1, \
"small": 1, \
"large": 1, \
}[self.style]
shadow_color:
( \
self.theme_cls.shadowColor \
self.theme_cls.shadowColor[:-1] + [.5] \
if self.theme_shadow_color == "Primary" else \
self.shadow_color \
) \
Expand Down Expand Up @@ -131,10 +125,10 @@
size_hint: None, None
size: "56dp", "56dp"
radius: [dp(16), ]
shadow_radius: [dp(12), ]
shadow_radius: [dp(14), ]
shadow_offset: 0, -1
shadow_softness: 2
elevation_level: 2
# shadow_softness: 2
elevation_level: 1
shadow_color:
( \
self.theme_cls.shadowColor \
Expand Down Expand Up @@ -289,7 +283,7 @@
shadow_color:
( \
( \
self.theme_cls.shadowColor \
self.theme_cls.shadowColor[:-1] + [.5] \
if self.theme_shadow_color == "Primary" else \
self.shadow_color \
) \
Expand Down
148 changes: 113 additions & 35 deletions kivymd/uix/button/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ def build(self):
NumericProperty,
OptionProperty,
VariableListProperty,
ObjectProperty,
ObjectProperty, DictProperty,
)
from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.relativelayout import RelativeLayout
Expand Down Expand Up @@ -718,6 +718,26 @@ class BaseFabButton:
.. versionadded:: 2.0.0
"""

elevation_levels = DictProperty(
{
0: 0,
1: dp(4),
2: dp(8),
3: dp(12),
4: dp(16),
5: dp(18),
}
)
"""
Elevation is measured as the distance between components along the z-axis
in density-independent pixels (dps).
.. versionadded:: 1.2.0
:attr:`elevation_levels` is an :class:`~kivy.properties.DictProperty`
and defaults to `{0: dp(0), 1: dp(8), 2: dp(3), 3: dp(6), 4: dp(8), 5: dp(12)}`.
"""

color_map = OptionProperty(
"surface", options=("surface", "secondary", "tertiary")
)
Expand Down Expand Up @@ -803,6 +823,26 @@ class BaseButton(
classes documentation.
"""

elevation_levels = DictProperty(
{
0: 0,
1: dp(4),
2: dp(8),
3: dp(12),
4: dp(16),
5: dp(18),
}
)
"""
Elevation is measured as the distance between components along the z-axis
in density-independent pixels (dps).
.. versionadded:: 1.2.0
:attr:`elevation_levels` is an :class:`~kivy.properties.DictProperty`
and defaults to `{0: dp(0), 1: dp(8), 2: dp(3), 3: dp(6), 4: dp(8), 5: dp(12)}`.
"""

md_bg_color_disabled = ColorProperty(None)
"""
The background color in (r, g, b, a) or string format of the button when
Expand Down Expand Up @@ -968,34 +1008,35 @@ def set_properties_widget(self) -> None:

super().set_properties_widget()

if not self.disabled:
if self._state == self.state_hover and self.focus_behavior:
if self.style == "filled":
self.elevation_level = 1
self.shadow_softness = 0
elif self.style == "tonal":
self.elevation_level = 1
else:
self.elevation_level = 2
self.shadow_softness = 2
elif self._state == self.state_press:
if self.style == "elevated":
self.elevation_level = 2
self.shadow_softness = 2
elif self.style == "tonal":
self.elevation_level = 0
elif self.style == "filled":
self.elevation_level = 0
self.shadow_softness = 0
elif not self._state:
if self.style == "elevated":
self.elevation_level = 1
self.shadow_softness = 0
elif self.style == "tonal":
self.elevation_level = 0
elif self.style == "filled":
self.elevation_level = 0
self.shadow_softness = 0
if (
self._state == self.state_hover
and self.focus_behavior
or self._state == self.state_press
):
self._elevation_level = (
1
if self.theme_elevation_level == "Primary"
else self.elevation_level
)
self._shadow_softness = (
0
if self.theme_shadow_softness == "Primary"
else self.shadow_softness
)

if not self.disabled:
if self._state == self.state_hover and self.focus_behavior:
if self.style == "elevated":
self.elevation_level = 2
self.shadow_softness = 2
elif self._state == self.state_press:
if self.style == "elevated":
self.elevation_level = 2
self.shadow_softness = 2
elif not self._state:
if self.style == "elevated":
self.elevation_level = 1
self.shadow_softness = 0


class MDButtonText(MDLabel):
Expand Down Expand Up @@ -1102,17 +1143,34 @@ def set_properties_widget(self) -> None:

super().set_properties_widget()

if (
self._state == self.state_hover
and self.focus_behavior
or self._state == self.state_press
):
self._elevation_level = (
1
if self.theme_elevation_level == "Primary"
else self.elevation_level
)
self._shadow_softness = (
0
if self.theme_shadow_softness == "Primary"
else self.shadow_softness
)

if not self.disabled:
if (
self._state == self.state_hover
and self.focus_behavior
or not self._state
self._state == self.state_hover and self.focus_behavior
):
self.elevation_level = 1
self.shadow_softness = 0
elif self._state == self.state_press:
self.elevation_level = 2
self.shadow_softness = 2
if self._state == self.state_press:
self.elevation_level = 3
self.shadow_softness = 4
elif not self._state:
self.elevation_level = 1
self.shadow_softness = 0


class MDExtendedFabButtonIcon(MDIcon):
Expand Down Expand Up @@ -1164,6 +1222,26 @@ class MDExtendedFabButton(
Fired when the button is expanded.
"""

elevation_levels = DictProperty(
{
0: 0,
1: dp(4),
2: dp(8),
3: dp(12),
4: dp(16),
5: dp(18),
}
)
"""
Elevation is measured as the distance between components along the z-axis
in density-independent pixels (dps).
.. versionadded:: 1.2.0
:attr:`elevation_levels` is an :class:`~kivy.properties.DictProperty`
and defaults to `{0: dp(0), 1: dp(8), 2: dp(3), 3: dp(6), 4: dp(8), 5: dp(12)}`.
"""

_icon = ObjectProperty()
_label = ObjectProperty()

Expand Down
43 changes: 30 additions & 13 deletions kivymd/uix/card/card.kv
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@


<MDCard>
shadow_radius: [dp(14), ]
shadow_radius: [(self.radius[0] / 2) + dp(2), ]
shadow_color:
( \
self.theme_cls.shadowColor \
{ \
"filled": self.theme_cls.transparentColor, \
"outlined": self.theme_cls.transparentColor, \
"elevated": self.theme_cls.shadowColor \
if self.theme_shadow_color == "Primary" else \
self.shadow_color \
) \
self.shadow_color, \
}[self.style] \
if not self.disabled else \
{ \
"filled": \
self.theme_cls.shadowColor[:-1] + [.5] \
if self.theme_shadow_color == "Primary" else \
self.shadow_color[:-1] + [.5], \
"filled": self.theme_cls.transparentColor, \
"outlined": self.theme_cls.transparentColor, \
"elevated": self.theme_cls.shadowColor[:-1] + [.5] \
if self.theme_shadow_color == "Primary" else \
Expand All @@ -29,24 +28,42 @@
{ \
"filled": [0, 0], \
"outlined": [0, 0], \
"elevated": [0, -1], \
"elevated": [0, -2], \
}[self.style] \
if not self.disabled else \
{ \
"filled": [0, -1], \
"filled": [0, 0], \
"outlined": [0, 0], \
"elevated": [0, -1], \
"elevated": [0, -2], \
}[self.style] \
) \
if self.theme_shadow_offset == "Primary" else self.shadow_offset
shadow_softness:
( \
{ \
"filled": 0, \
"outlined": 0, \
"elevated": dp(4), \
}[self.style] \
if not self.disabled else \
{ \
"filled": 0, \
"outlined": 0, \
"elevated": dp(4), \
}[self.style] \
) \
if self.theme_shadow_softness == "Primary" else self.shadow_softness
elevation_level:
(
( \
( \
{ \
"filled": 0, \
"outlined": 0, \
"elevated": self.elevation_level if self.elevation_level else 1, \
}[self.style] \
) \
if self.theme_elevation_level == "Primary" else self.elevation_level \
) \
if not self.disabled else \
{ \
"filled": 1, \
Expand Down
4 changes: 2 additions & 2 deletions kivymd/uix/card/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ def set_properties_widget(self) -> None:
if self.theme_elevation_level == "Primary":
self.elevation_level = 2
if self.theme_shadow_softness == "Primary":
self.shadow_softness = 1
self.shadow_softness = dp(4)
if self.theme_shadow_offset == "Primary":
self.shadow_offset = [0, -2]
elif self._state == self.state_press:
Expand All @@ -682,7 +682,7 @@ def set_properties_widget(self) -> None:
if self.theme_shadow_softness == "Primary":
self.shadow_softness = 0
if self.theme_shadow_offset == "Primary":
self.shadow_offset = [0, -1]
self.shadow_offset = [0, -2]
self.md_bg_color = self._bg_color


Expand Down

0 comments on commit b34b07f

Please sign in to comment.