Closed BC-clegras closed 1 year ago
Gradient shader from UI is different from the one in Painting. Its constructors don't have "rotation", but they have matrix4 transformation. We can do rotation through matrix. Let's call this issue a bug.
Added rotation
to sweep gradient.
Result:
Code:
import math
import flet as ft
import flet.canvas as cv
def main(page: ft.Page):
cp = cv.Canvas(
[
cv.Rect(
10,
10,
100,
100,
5,
ft.Paint(
gradient=ft.PaintLinearGradient(
(0, 10),
(100, 50),
colors=[ft.colors.BLUE, ft.colors.YELLOW],
# rotation=math.pi / 2,
),
style=ft.PaintingStyle.FILL,
),
),
cv.Circle(
60,
170,
50,
ft.Paint(
gradient=ft.PaintRadialGradient(
(60, 170), 50, colors=[ft.colors.YELLOW, ft.colors.BLUE]
),
style=ft.PaintingStyle.FILL,
),
),
cv.Path(
[cv.Path.Arc(10, 230, 100, 100, 3 * math.pi / 4, 3 * math.pi / 2)],
ft.Paint(
gradient=ft.PaintSweepGradient(
(60, 280),
colors=[ft.colors.YELLOW, ft.colors.PURPLE],
color_stops=[0.0, 1.0],
start_angle=0,
end_angle=math.pi * 2,
rotation=3 * math.pi / 4,
),
stroke_width=15,
stroke_join=ft.StrokeJoin.ROUND,
style=ft.PaintingStyle.STROKE,
),
),
],
width=float("inf"),
expand=True,
)
page.add(cp)
ft.app(main)
Awesome, thanks a lot for getting it done so quickly! How can I get this running on my machine currently? I assume the package isn't pushed to pip instantly, but can I just copy over the files changed in the commit to my computer?
That will be merged later today and be available as "dev" package.
You can try it with https://pypi.org/project/flet/0.8.0.dev1590/
Description
The Flet canvas documentation mentions the rotation property for
PaintLinearGradient
,PaintRadialGradient
, andPaintSweepGradient
. However, when trying to use that property, the code errors out with an unexpected keyboard error for rotation.Code example to reproduce the issue:
Describe the results you received:
Describe the results you expected:
I am trying to make a gauge with a gradient with part of the arc missing. The arc looks like this:
As you can see, the gradient abruptly stops at
2 * pi
and continues as the initial color for the rest of the arc. In flutter, I know you can make the gradient'send_angle
greater than2 * pi
to solve this issue (source), or usetransform: GradientRotation()
(source), but neither of those work currently work in Flet.I want the gradient to go all the way to the end of my gauge (pictured at what it's maximum value would be) instead of the abrupt stop I currently have. I was hoping to use the rotation property to rotate the gradient and solve my issue.
Additional information you deem important (e.g. issue happens only occasionally):
Flet version (
pip show flet
):Operating system:
Windows 10 22H2 Additional environment details: Running the application from VS Code 1.79.2