From 63dd8b66526bc083b529bc9c8d562a439a69ff24 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Fri, 11 Jul 2025 06:02:15 +0100 Subject: [PATCH] `ColorStop` constructor functions (#20066) # Objective Add `px` and `percent` constructor functions for `ColorStop`. --- crates/bevy_ui/src/gradients.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/bevy_ui/src/gradients.rs b/crates/bevy_ui/src/gradients.rs index 7086b37416..87b7afc581 100644 --- a/crates/bevy_ui/src/gradients.rs +++ b/crates/bevy_ui/src/gradients.rs @@ -44,6 +44,24 @@ impl ColorStop { } } + /// A color stop with its position in logical pixels. + pub fn px(color: impl Into, 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, 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;