From b47f6e89011bb3f1b1439e8e31dcb83efebe71f9 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Mon, 14 Jul 2025 22:27:43 +0100 Subject: [PATCH] Constify `gradients` helper functions (#20098) # Objective Constify some of the helper functions in the UI's `gradients` module. --- crates/bevy_ui/src/gradients.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/bevy_ui/src/gradients.rs b/crates/bevy_ui/src/gradients.rs index 87b7afc581..daed73f628 100644 --- a/crates/bevy_ui/src/gradients.rs +++ b/crates/bevy_ui/src/gradients.rs @@ -63,7 +63,7 @@ impl ColorStop { } // Set the interpolation midpoint between this and the following stop - pub fn with_hint(mut self, hint: f32) -> Self { + pub const fn with_hint(mut self, hint: f32) -> Self { self.hint = hint; self } @@ -175,7 +175,7 @@ impl AngularColorStop { } // Set the interpolation midpoint between this and the following stop - pub fn with_hint(mut self, hint: f32) -> Self { + pub const fn with_hint(mut self, hint: f32) -> Self { self.hint = hint; self } @@ -387,7 +387,7 @@ impl RadialGradient { } } - pub fn in_color_space(mut self, color_space: InterpolationColorSpace) -> Self { + pub const fn in_color_space(mut self, color_space: InterpolationColorSpace) -> Self { self.color_space = color_space; self } @@ -437,18 +437,18 @@ impl ConicGradient { } /// Sets the starting angle of the gradient in radians - pub fn with_start(mut self, start: f32) -> Self { + pub const fn with_start(mut self, start: f32) -> Self { self.start = start; self } /// Sets the position of the gradient - pub fn with_position(mut self, position: UiPosition) -> Self { + pub const fn with_position(mut self, position: UiPosition) -> Self { self.position = position; self } - pub fn in_color_space(mut self, color_space: InterpolationColorSpace) -> Self { + pub const fn in_color_space(mut self, color_space: InterpolationColorSpace) -> Self { self.color_space = color_space; self } @@ -478,7 +478,7 @@ pub enum Gradient { impl Gradient { /// Returns true if the gradient has no stops. - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { match self { Gradient::Linear(gradient) => gradient.stops.is_empty(), Gradient::Radial(gradient) => gradient.stops.is_empty(), @@ -578,19 +578,19 @@ pub enum RadialGradientShape { Ellipse(Val, Val), } -fn close_side(p: f32, h: f32) -> f32 { +const fn close_side(p: f32, h: f32) -> f32 { (-h - p).abs().min((h - p).abs()) } -fn far_side(p: f32, h: f32) -> f32 { +const fn far_side(p: f32, h: f32) -> f32 { (-h - p).abs().max((h - p).abs()) } -fn close_side2(p: Vec2, h: Vec2) -> f32 { +const fn close_side2(p: Vec2, h: Vec2) -> f32 { close_side(p.x, h.x).min(close_side(p.y, h.y)) } -fn far_side2(p: Vec2, h: Vec2) -> f32 { +const fn far_side2(p: Vec2, h: Vec2) -> f32 { far_side(p.x, h.x).max(far_side(p.y, h.y)) }