Skip to content

Commit 63dd8b6

Browse files
authored
ColorStop constructor functions (#20066)
# Objective Add `px` and `percent` constructor functions for `ColorStop`.
1 parent 83305af commit 63dd8b6

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

crates/bevy_ui/src/gradients.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,24 @@ impl ColorStop {
4444
}
4545
}
4646

47+
/// A color stop with its position in logical pixels.
48+
pub fn px(color: impl Into<Color>, px: f32) -> Self {
49+
Self {
50+
color: color.into(),
51+
point: Val::Px(px),
52+
hint: 0.5,
53+
}
54+
}
55+
56+
/// A color stop with a percentage position.
57+
pub fn percent(color: impl Into<Color>, percent: f32) -> Self {
58+
Self {
59+
color: color.into(),
60+
point: Val::Percent(percent),
61+
hint: 0.5,
62+
}
63+
}
64+
4765
// Set the interpolation midpoint between this and the following stop
4866
pub fn with_hint(mut self, hint: f32) -> Self {
4967
self.hint = hint;

0 commit comments

Comments
 (0)