Skip to content

Commit 729f83d

Browse files
femtovg: clamping sim - add a stop at 1.0 on a gradient (slint-ui#7909)
* femtovg: clamping sim - add a stop at 1.0 on a gradient to match the last stop set if last stop is not at 1.0 linear and radial adjusted * [autofix.ci] apply automated fixes * add conditional for last stop for femtovg gradients --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 5449360 commit 729f83d

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

internal/renderers/femtovg/itemrenderer.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,8 +1559,18 @@ impl<'a, R: femtovg::Renderer + TextureImporter> GLItemRenderer<'a, R> {
15591559
[path_width, path_height].into(),
15601560
);
15611561

1562-
let stops =
1563-
gradient.stops().map(|stop| (stop.position, to_femtovg_color(&stop.color)));
1562+
let mut stops: Vec<_> = gradient
1563+
.stops()
1564+
.map(|stop| (stop.position, to_femtovg_color(&stop.color)))
1565+
.collect();
1566+
1567+
// Add an extra stop at 1.0 with the same color as the last stop
1568+
if let Some(last_stop) = stops.last().cloned() {
1569+
if last_stop.0 != 1.0 {
1570+
stops.push((1.0, last_stop.1));
1571+
}
1572+
}
1573+
15641574
femtovg::Paint::linear_gradient_stops(start.x, start.y, end.x, end.y, stops)
15651575
}
15661576
Brush::RadialGradient(gradient) => {
@@ -1569,8 +1579,18 @@ impl<'a, R: femtovg::Renderer + TextureImporter> GLItemRenderer<'a, R> {
15691579
let path_width = path_bounds.width();
15701580
let path_height = path_bounds.height();
15711581

1572-
let stops =
1573-
gradient.stops().map(|stop| (stop.position, to_femtovg_color(&stop.color)));
1582+
let mut stops: Vec<_> = gradient
1583+
.stops()
1584+
.map(|stop| (stop.position, to_femtovg_color(&stop.color)))
1585+
.collect();
1586+
1587+
// Add an extra stop at 1.0 with the same color as the last stop
1588+
if let Some(last_stop) = stops.last().cloned() {
1589+
if last_stop.0 != 1.0 {
1590+
stops.push((1.0, last_stop.1));
1591+
}
1592+
}
1593+
15741594
femtovg::Paint::radial_gradient_stops(
15751595
path_width / 2.,
15761596
path_height / 2.,

0 commit comments

Comments
 (0)