Skip to content

Commit 39bf45c

Browse files
committed
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.
1 parent 14a7689 commit 39bf45c

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

crates/bevy_ui/src/geometry.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,22 +358,55 @@ impl Size {
358358
}
359359

360360
/// Creates a new [`Size`] where both sides take the given value.
361+
///
362+
/// # Example
363+
///
364+
/// ```
365+
/// # use bevy_ui::{Size, Val};
366+
/// #
367+
/// let size = Size::all(Val::Px(10.));
368+
///
369+
/// assert_eq!(size.width, Val::Px(10.0));
370+
/// assert_eq!(size.height, Val::Px(10.0));
371+
/// ```
361372
pub const fn all(value: Val) -> Self {
362373
Self {
363374
width: value,
364375
height: value,
365376
}
366377
}
367378

368-
/// Creates a new [`Size`] where `width` takes the given value.
379+
/// Creates a new [`Size`] where `width` takes the given value and its `height` is `Val::Auto`.
380+
///
381+
/// # Example
382+
///
383+
/// ```
384+
/// # use bevy_ui::{Size, Val};
385+
/// #
386+
/// let size = Size::width(Val::Px(10.));
387+
///
388+
/// assert_eq!(size.width, Val::Px(10.0));
389+
/// assert_eq!(size.height, Val::Auto);
390+
/// ```
369391
pub const fn width(width: Val) -> Self {
370392
Self {
371393
width,
372394
height: Val::Auto,
373395
}
374396
}
375397

376-
/// Creates a new [`Size`] where `height` takes the given value.
398+
/// Creates a new [`Size`] where `height` takes the given value and its `width` is `Val::Auto`.
399+
///
400+
/// # Example
401+
///
402+
/// ```
403+
/// # use bevy_ui::{Size, Val};
404+
/// #
405+
/// let size = Size::height(Val::Px(10.));
406+
///
407+
/// assert_eq!(size.width, Val::Auto);
408+
/// assert_eq!(size.height, Val::Px(10.));
409+
/// ```
377410
pub const fn height(height: Val) -> Self {
378411
Self {
379412
width: Val::Auto,

0 commit comments

Comments
 (0)