Repository: zng-ui/zng (language: rust)

Issue:
Gradient stops cause panic
These `stops!` cause a panic in a linear background gradient:

```rust
color::gradient::stops![
    hex!(#ff5226), 
    hex!(#ffc926),
    (hex!(#ffc926), 95.pct()),
    (colors::BLACK, 100.pct()),
]
```




Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 790656847..9e2eafc66 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,6 @@
 # Unreleased
 
+* Fix gradient stops that mix positional stops with offset stops. 
 * Fix build in platforms without `AtomicU64`.
 * Fix `zng::env::bin` in Wasm builds.
 
diff --git a/crates/zng-color/src/gradient.rs b/crates/zng-color/src/gradient.rs
index 05382a4e6..c1aaf2ff4 100644
--- a/crates/zng-color/src/gradient.rs
+++ b/crates/zng-color/src/gradient.rs
@@ -1062,9 +1062,11 @@ impl GradientStops {
         // length that must be split between positional stops.
         let (start_offset, layout_length) = {
             // index of stop after the sequence that has a calculated offset.
-            let sequence_ender = (range.end..render_stops.len()).find(|i| !hints.contains(i)).unwrap();
+            let sequence_ender = (range.end..render_stops.len())
+                .find(|i| !hints.contains(i))
+                .unwrap_or(range.end - 1);
             // index of stop before the sequence that has a calculated offset.
-            let sequence_starter = (0..range.start).rev().find(|i| !hints.contains(i)).unwrap();
+            let sequence_starter = (0..range.start).rev().find(|i| !hints.contains(i)).unwrap_or(range.start);
 
             let start_offset = render_stops[sequence_starter].offset;
             let length = render_stops[sequence_ender].offset - start_offset;
@@ -1075,7 +1077,7 @@ impl GradientStops {
         let mut offset = start_offset;
 
         for i in range {
-            if !hints.contains(&i) {
+            if ColorStop::is_layout_positional(render_stops[i].offset) {
                 offset += d;
                 render_stops[i].offset = offset;
             }


Test patch: