ColorStop constructor functions (#20066)

# Objective

Add `px` and `percent` constructor functions for `ColorStop`.
This commit is contained in:
ickshonpe 2025-07-11 06:02:15 +01:00 committed by GitHub
parent 83305afa66
commit 63dd8b6652
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -44,6 +44,24 @@ impl ColorStop {
}
}
/// A color stop with its position in logical pixels.
pub fn px(color: impl Into<Color>, px: f32) -> Self {
Self {
color: color.into(),
point: Val::Px(px),
hint: 0.5,
}
}
/// A color stop with a percentage position.
pub fn percent(color: impl Into<Color>, percent: f32) -> Self {
Self {
color: color.into(),
point: Val::Percent(percent),
hint: 0.5,
}
}
// Set the interpolation midpoint between this and the following stop
pub fn with_hint(mut self, hint: f32) -> Self {
self.hint = hint;