diff --git a/doc/sources/images/boxshadow_spread_radius.svg b/doc/sources/images/boxshadow_spread_radius.svg
index fa9670992..b7504c829 100644
--- a/doc/sources/images/boxshadow_spread_radius.svg
+++ b/doc/sources/images/boxshadow_spread_radius.svg
@@ -25,9 +25,9 @@
inkscape:deskcolor="#505050"
inkscape:document-units="px"
showgrid="false"
- inkscape:zoom="0.9549199"
- inkscape:cx="467.57848"
- inkscape:cy="235.09825"
+ inkscape:zoom="1.3360827"
+ inkscape:cx="486.87106"
+ inkscape:cy="150.06556"
inkscape:window-width="1920"
inkscape:window-height="991"
inkscape:window-x="-9"
@@ -188,19 +188,19 @@
width="87.997459"
height="78.908112"
x="1875.7562"
- y="-206.03146" />spread_radius: [30.0, 30.0]30px30px30px30pxspread_radius: 30.0spread_radius: 0.0spread_radius: [0.0, 0.0]spread_radius: -30.0spread_radius: [0.0, -30.0]Padrão2022-06-22
diff --git a/doc/sources/images/boxshadow_spread_radius_inset.svg b/doc/sources/images/boxshadow_spread_radius_inset.svg
index 5194e8841..f40c06d7c 100644
--- a/doc/sources/images/boxshadow_spread_radius_inset.svg
+++ b/doc/sources/images/boxshadow_spread_radius_inset.svg
@@ -25,9 +25,9 @@
inkscape:deskcolor="#505050"
inkscape:document-units="px"
showgrid="false"
- inkscape:zoom="1.3504605"
- inkscape:cx="397.27189"
- inkscape:cy="176.60642"
+ inkscape:zoom="1.3812695"
+ inkscape:cx="470.94358"
+ inkscape:cy="149.50015"
inkscape:window-width="1920"
inkscape:window-height="991"
inkscape:window-x="-9"
@@ -217,7 +217,15 @@
width="52.916664"
height="39.687496"
x="1772.6295"
- y="-94.129494" />spread_radius: 10.0spread_radius: 0.0spread_radius: [0.0, 0.0]spread_radius: -10.0spread_radius: [10.0, -25]Padrão2022-06-22
+ y="-190.98524" />spread_radius: [10.0, 10.0]Padrão2022-06-22
diff --git a/kivy/graphics/boxshadow.pxd b/kivy/graphics/boxshadow.pxd
index 91db692fe..027eb2bda 100644
--- a/kivy/graphics/boxshadow.pxd
+++ b/kivy/graphics/boxshadow.pxd
@@ -6,12 +6,12 @@ from kivy.graphics.vertex_instructions cimport VertexInstruction
cdef class BoxShadow(Fbo):
cdef bint _inset
+ cdef float _blur_radius
cdef tuple _pos
cdef tuple _size
cdef tuple _offset
cdef tuple _border_radius
- cdef float _blur_radius
- cdef float _spread_radius
+ cdef tuple _spread_radius
cdef VertexInstruction _fbo_rect
cdef VertexInstruction _texture_container
cdef Scale _fbo_scale
diff --git a/kivy/graphics/boxshadow.pyx b/kivy/graphics/boxshadow.pyx
index b2253cf82..efe9f8c6d 100644
--- a/kivy/graphics/boxshadow.pyx
+++ b/kivy/graphics/boxshadow.pyx
@@ -49,7 +49,7 @@ Example:
pos: self.pos
size: self.size
offset: 0, -10
- spread_radius: -20
+ spread_radius: -20, -20
border_radius: 10, 10, 10, 10
blur_radius: 80 if self.state == "normal" else 50
@@ -78,7 +78,7 @@ uniform sampler2D texture0;
uniform int inset;
uniform float blur_radius;
uniform vec4 border_radius;
-uniform float spread_radius;
+uniform vec2 spread_radius;
uniform vec2 size;
uniform vec2 offset;
@@ -159,7 +159,7 @@ cdef class BoxShadow(Fbo):
The negative ones indicate that the shadow should move to the left and/or down.
`blur_radius`: float, defaults to ``15.0``.
Define the shadow blur radius. Controls shadow expansion and softness.
- `spread_radius`: float, defaults to ``0.0``.
+ `spread_radius`: list | tuple, defaults to ``(0.0, 0.0)``.
Define the shrink/expansion of the shadow.
`border_radius`: list | tuple, defaults to ``(0.0, 0.0, 0.0, 0.0)``.
Specifies the radii used for the rounded corners clockwise:
@@ -173,7 +173,7 @@ cdef class BoxShadow(Fbo):
size = kwargs.get("size", (100.0, 100.0))
offset = kwargs.get("offset", (0.0, 0.0))
blur_radius = kwargs.get("blur_radius", 15.0)
- spread_radius = kwargs.get("spread_radius", 0.0)
+ spread_radius = kwargs.get("spread_radius", (0.0, 0.0))
border_radius = kwargs.get("border_radius", (0.0, 0.0, 0.0, 0.0))
self._inset = self._check_bool(inset)
@@ -187,7 +187,7 @@ cdef class BoxShadow(Fbo):
self._check_float("blur_radius", blur_radius),
min_value=0.0
)
- self._spread_radius = self._check_float("spread_radius", spread_radius)
+ self._spread_radius = self._check_iter("spread_radius", spread_radius)
self._border_radius = self._bounded_value(
self._check_iter("border_radius", border_radius, components=4),
min_value=1.0,
@@ -249,8 +249,8 @@ cdef class BoxShadow(Fbo):
# The position should be adjusted according to the size expansion,
# with half the size used in the _adjusted_size method
if not self.inset:
- x -= self.blur_radius * 1.5 + self.spread_radius - self.offset[0]
- y -= self.blur_radius * 1.5 + self.spread_radius - self.offset[1]
+ x -= self.blur_radius * 1.5 + self.spread_radius[0] - self.offset[0]
+ y -= self.blur_radius * 1.5 + self.spread_radius[1] - self.offset[1]
return (x, y)
@@ -264,8 +264,8 @@ cdef class BoxShadow(Fbo):
# size expansion
if not self.inset and w > 0.0 and h > 0.0:
- w += self.blur_radius * 3 + self.spread_radius * 2
- h += self.blur_radius * 3 + self.spread_radius * 2
+ w += self.blur_radius * 3 + self.spread_radius[0] * 2
+ h += self.blur_radius * 3 + self.spread_radius[1] * 2
w = max(0.0, w)
h = max(0.0, h)
@@ -408,20 +408,20 @@ cdef class BoxShadow(Fbo):
@property
def spread_radius(self):
- '''Define the shrink/expansion of the shadow.
+ '''Define the shrink/expansion of the shadow in `[horizontal, vertical]` format.
- Defaults to ``0.0``.
+ Defaults to ``(0.0, 0.0)``.
This property is especially useful for cases where you want to achieve
- a softer shadow around the element, by setting a negative value for
+ a softer shadow around the element, by setting negative values for
:attr:`spread_radius` and a larger value for :attr:`blur_radius` as
in the :ref:`example `.
- :attr:`inset` **OFF**:
In the image below, the target element has a raw size of ``200 x 150px``.
- Positive changes to the :attr:`spread_radius` value will cause the raw
- :attr:`size` of the shadow to increase in both horizontal and vertical
- directions, while negative values will cause the shadow to shrink.
+ Positive changes to the :attr:`spread_radius` values will cause the raw
+ :attr:`size` of the shadow to increase, while negative values will cause
+ the shadow to shrink.
.. image:: images/boxshadow_spread_radius.svg
:align: center
@@ -440,7 +440,7 @@ cdef class BoxShadow(Fbo):
@spread_radius.setter
def spread_radius(self, value):
- self._spread_radius = self._check_float("spread_radius", value)
+ self._spread_radius = self._check_iter("spread_radius", value)
self._update_shadow()
@property
@@ -559,7 +559,7 @@ cdef class BoxShadow(Fbo):
size: self.size
offset: 0, -10
blur_radius: 25
- spread_radius: -10
+ spread_radius: -10, -10
border_radius: 10, 10, 10, 10
canvas:
@@ -606,7 +606,7 @@ cdef class BoxShadow(Fbo):
size: self.size
offset: 0, -10
blur_radius: 25
- spread_radius: -10
+ spread_radius: -10, -10
border_radius: 10, 10, 10, 10
|
diff --git a/kivy/tests/test_graphics.py b/kivy/tests/test_graphics.py
index d10afe3fd..3a0e87dbb 100644
--- a/kivy/tests/test_graphics.py
+++ b/kivy/tests/test_graphics.py
@@ -28,7 +28,7 @@ class BoxShadowTest(GraphicUnitTest):
pos=(50, 50),
size=(150, 150),
offset=(0, 10),
- spread_radius=10,
+ spread_radius=(10, -10),
border_radius=(10, 10, 10, 10),
blur_radius=80,
)
@@ -42,7 +42,7 @@ class BoxShadowTest(GraphicUnitTest):
pos=(50, 50),
size=(150, 150),
offset=(0, 10),
- spread_radius=10,
+ spread_radius=(10, -10),
border_radius=(10, 10, 10, 10),
blur_radius=80,
)
@@ -57,7 +57,7 @@ class BoxShadowTest(GraphicUnitTest):
bs.pos = [50, 50]
bs.size = [150, 150]
bs.offset = [0, 10]
- bs.spread_radius = 10
+ bs.spread_radius = [10, -10]
bs.border_radius = [10, 10, 10, 10]
bs.blur_radius = 40
r(wid)
@@ -71,7 +71,7 @@ class BoxShadowTest(GraphicUnitTest):
bs.pos = 50, 50
bs.size = raw_size
bs.blur_radius = 80
- bs.spread_radius = 10
+ bs.spread_radius = -10, 10
# The size of the rectangle containing the FBO texture (shadow) needs
# to be adjusted according to the size of the shadow, otherwise there
@@ -79,11 +79,11 @@ class BoxShadowTest(GraphicUnitTest):
adjusted_size = (
max(
0,
- raw_size[0] + bs.blur_radius * 3 + bs.spread_radius * 2,
+ raw_size[0] + bs.blur_radius * 3 + bs.spread_radius[0] * 2,
),
max(
0,
- raw_size[1] + bs.blur_radius * 3 + bs.spread_radius * 2,
+ raw_size[1] + bs.blur_radius * 3 + bs.spread_radius[1] * 2,
),
)
@@ -104,16 +104,16 @@ class BoxShadowTest(GraphicUnitTest):
pos=(50, 50),
size=raw_size,
blur_radius=80,
- spread_radius=10
+ spread_radius=(10, -10)
)
adjusted_size = (
max(
0,
- raw_size[0] + bs.blur_radius * 3 + bs.spread_radius * 2,
+ raw_size[0] + bs.blur_radius * 3 + bs.spread_radius[0] * 2,
),
max(
0,
- raw_size[1] + bs.blur_radius * 3 + bs.spread_radius * 2,
+ raw_size[1] + bs.blur_radius * 3 + bs.spread_radius[1] * 2,
),
)
@@ -140,18 +140,18 @@ class BoxShadowTest(GraphicUnitTest):
bs.size = raw_size
bs.offset = offset
bs.blur_radius = 80
- bs.spread_radius = 10
+ bs.spread_radius = -10, 10
# If the size of the rectangle containing the FBO texture (shadow)
# changes, its position will need to be adjusted.
adjusted_pos = (
raw_pos[0]
- bs.blur_radius * 1.5
- - bs.spread_radius
+ - bs.spread_radius[0]
+ bs.offset[0],
raw_pos[0]
- bs.blur_radius * 1.5
- - bs.spread_radius
+ - bs.spread_radius[1]
+ bs.offset[1],
)
@@ -173,16 +173,16 @@ class BoxShadowTest(GraphicUnitTest):
size=raw_size,
offset=offset,
blur_radius=80,
- spread_radius=10
+ spread_radius=(10, -10)
)
adjusted_pos = (
raw_pos[0]
- bs.blur_radius * 1.5
- - bs.spread_radius
+ - bs.spread_radius[0]
+ bs.offset[0],
raw_pos[0]
- bs.blur_radius * 1.5
- - bs.spread_radius
+ - bs.spread_radius[1]
+ bs.offset[1],
)
@@ -205,7 +205,7 @@ class BoxShadowTest(GraphicUnitTest):
bs.size = 150, 150
bs.offset = 10, -100
bs.blur_radius = -80
- bs.spread_radius = -200
+ bs.spread_radius = -200, -100
bs.border_radius = 0, 0, 100, 0
assert bs.size == (0, 0)
@@ -226,7 +226,7 @@ class BoxShadowTest(GraphicUnitTest):
size=(150, 150),
offset=(10, -100),
blur_radius=-80,
- spread_radius=-200,
+ spread_radius=(-200, -100),
border_radius=(0, 0, 100, 0),
)