Skip to content

Conversation

@task-jp
Copy link
Contributor

@task-jp task-jp commented Oct 23, 2025

Normalize conic gradient stop positions to [0,1] range using modulo wrapping, enabling support for angle ranges outside 0-360 degrees (e.g., -90deg to 270deg or 360deg to 720deg).

Key changes:

  • Separate duplicate positions with different colors to prevent flickering
  • Interpolate boundary colors between min/max stops for seamless gradients
  • Add boundary stops at 0.0 and 1.0 when needed

Tests cover negative angles, 360deg+ offsets, and full 360deg range with different start/end colors.

task-jp and others added 2 commits October 23, 2025 23:06
Normalize conic gradient stop positions to [0,1] range using modulo
wrapping, enabling support for angle ranges outside 0-360 degrees
(e.g., -90deg to 270deg or 360deg to 720deg).

Key changes:
- Separate duplicate positions with different colors to prevent flickering
- Interpolate boundary colors between min/max stops for seamless gradients
- Add boundary stops at 0.0 and 1.0 when needed

Tests cover negative angles, 360deg+ offsets, and full 360deg range
with different start/end colors.
Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the motivation behind this.

It looks like this makes Slint different from what the CSS spec says.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice that the top right image now show some green between the red and white, while the code has it after the blue.
If I test the conic-gradient(red 0deg, white 180deg, blue 360deg, green 540deg); with CSS, i get the previous image without green. Not the new one.

@task-jp
Copy link
Contributor Author

task-jp commented Oct 24, 2025

Thanks for your review.

What's the motivation behind this.

In https://snapshots.slint.dev/master/editor/index.html?load_url=https://raw.githubusercontent.com/slint-ui/slint/master/examples/speedometer/demo.slint, CarButton tries to rotate angles in @conic-gradients when it is pressed. To solve this, I thought it would be good to support any degrees.

this makes Slint different from what the CSS spec says.

Right. should we introduce the [ from [ <angle> | <zero> ] ]? for such usecase?

@ogoffart
Copy link
Member

I see. I can achieve the desired effect with

@conic-gradient( #020414 stop4 - 1turn, #ff0000 stop5 - 1turn, #000000 stop6 - 1turn, #020414 stop1, #ff0000 stop2, #020414 stop3, #020414 stop4, #ff0000 stop5, #000000 stop6);

I added stop4 to stop6 back at the beginning with a - 1turn
So when some value are more than 360deg, they don't wrap around, but the value before that wraps around.

I would prefer keeping close to the CSS spec for gradients.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants