From 39bf45cf5ee275d7868774133891de95f5289b20 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Mon, 13 Feb 2023 18:20:34 +0000 Subject: [PATCH] Add doc tests for the `Size` constructor functions (#7658) # Objective Add doc tests for the `Size` constructor functions. Also changed the function descriptions so they explicitly state the values that elided values are given. ## Changelog * Added doc tests for the `Size` constructor functions. --- crates/bevy_ui/src/geometry.rs | 37 ++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ui/src/geometry.rs b/crates/bevy_ui/src/geometry.rs index 76168c98e0..fd90c711c9 100644 --- a/crates/bevy_ui/src/geometry.rs +++ b/crates/bevy_ui/src/geometry.rs @@ -358,6 +358,17 @@ impl Size { } /// Creates a new [`Size`] where both sides take the given value. + /// + /// # Example + /// + /// ``` + /// # use bevy_ui::{Size, Val}; + /// # + /// let size = Size::all(Val::Px(10.)); + /// + /// assert_eq!(size.width, Val::Px(10.0)); + /// assert_eq!(size.height, Val::Px(10.0)); + /// ``` pub const fn all(value: Val) -> Self { Self { width: value, @@ -365,7 +376,18 @@ impl Size { } } - /// Creates a new [`Size`] where `width` takes the given value. + /// Creates a new [`Size`] where `width` takes the given value and its `height` is `Val::Auto`. + /// + /// # Example + /// + /// ``` + /// # use bevy_ui::{Size, Val}; + /// # + /// let size = Size::width(Val::Px(10.)); + /// + /// assert_eq!(size.width, Val::Px(10.0)); + /// assert_eq!(size.height, Val::Auto); + /// ``` pub const fn width(width: Val) -> Self { Self { width, @@ -373,7 +395,18 @@ impl Size { } } - /// Creates a new [`Size`] where `height` takes the given value. + /// Creates a new [`Size`] where `height` takes the given value and its `width` is `Val::Auto`. + /// + /// # Example + /// + /// ``` + /// # use bevy_ui::{Size, Val}; + /// # + /// let size = Size::height(Val::Px(10.)); + /// + /// assert_eq!(size.width, Val::Auto); + /// assert_eq!(size.height, Val::Px(10.)); + /// ``` pub const fn height(height: Val) -> Self { Self { width: Val::Auto,