-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Remove Val::Undefined
#7485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Val::Undefined
#7485
Changes from 16 commits
ea7bc05
5573ea6
26eeca7
78fe6ad
b274e9e
9cffde9
8ed613f
9bdf85e
54f68ce
ce52876
abdef25
5e814cf
2087be6
99b93f8
5ab3ffd
eb88a97
6113911
cc8d6d4
82273ec
431d97e
a38647f
c8f200e
f3f02d8
5e3e7cf
d1c7e33
6215dc6
e72dca8
29db012
5cca520
51bd6df
9369aa1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ use std::ops::{Div, DivAssign, Mul, MulAssign}; | |
/// ``` | ||
/// | ||
/// If you define opposite sides of the position, the size of the UI element will automatically be calculated | ||
/// if not explicitly specified. This means that if you have a [`Size`] that uses [`Val::Undefined`](crate::Val::Undefined) | ||
/// if not explicitly specified. This means that if you have a [`Size`] that uses [`Val::Auto`](crate::Val::Auto) | ||
/// as a width and height, the size would be determined by the window size and the values specified in the position. | ||
/// | ||
/// ``` | ||
|
@@ -65,16 +65,14 @@ use std::ops::{Div, DivAssign, Mul, MulAssign}; | |
/// right values of the position because the size of the UI element is already explicitly specified. | ||
/// | ||
/// ``` | ||
/// # use bevy_ui::{UiRect, Size, Val, Style}; | ||
/// # use bevy_ui::{Size, Val, Style}; | ||
/// # use bevy_utils::default; | ||
/// # | ||
/// let style = Style { | ||
/// position: UiRect { // Defining all four sides | ||
/// left: Val::Px(100.0), | ||
/// right: Val::Px(200.0), | ||
/// top: Val::Px(300.0), | ||
/// bottom: Val::Px(400.0), | ||
/// }, | ||
/// left: Val::Px(100.0), | ||
/// right: Val::Px(200.0), | ||
/// top: Val::Px(300.0), | ||
/// bottom: Val::Px(400.0), | ||
/// size: Size::new(Val::Percent(100.0), Val::Percent(50.0)), // but also explicitly specifying a size | ||
/// ..default() | ||
/// }; | ||
|
@@ -134,10 +132,10 @@ pub struct UiRect { | |
|
||
impl UiRect { | ||
pub const DEFAULT: Self = Self { | ||
left: Val::DEFAULT, | ||
right: Val::DEFAULT, | ||
top: Val::DEFAULT, | ||
bottom: Val::DEFAULT, | ||
left: Val::Px(0.), | ||
right: Val::Px(0.), | ||
top: Val::Px(0.), | ||
bottom: Val::Px(0.), | ||
}; | ||
|
||
/// Creates a new [`UiRect`] from the values specified. | ||
|
@@ -202,8 +200,8 @@ impl UiRect { | |
/// | ||
/// assert_eq!(ui_rect.left, Val::Px(10.0)); | ||
/// assert_eq!(ui_rect.right, Val::Px(10.0)); | ||
/// assert_eq!(ui_rect.top, Val::Undefined); | ||
/// assert_eq!(ui_rect.bottom, Val::Undefined); | ||
/// assert_eq!(ui_rect.top, Val::Px(0.)); | ||
/// assert_eq!(ui_rect.bottom, Val::Px(0.)); | ||
/// ``` | ||
pub fn horizontal(value: Val) -> Self { | ||
UiRect { | ||
|
@@ -222,8 +220,8 @@ impl UiRect { | |
/// # | ||
/// let ui_rect = UiRect::vertical(Val::Px(10.0)); | ||
/// | ||
/// assert_eq!(ui_rect.left, Val::Undefined); | ||
/// assert_eq!(ui_rect.right, Val::Undefined); | ||
/// assert_eq!(ui_rect.left, Val::Px(0.)); | ||
/// assert_eq!(ui_rect.right, Val::Px(0.)); | ||
/// assert_eq!(ui_rect.top, Val::Px(10.0)); | ||
/// assert_eq!(ui_rect.bottom, Val::Px(10.0)); | ||
/// ``` | ||
|
@@ -245,9 +243,9 @@ impl UiRect { | |
/// let ui_rect = UiRect::left(Val::Px(10.0)); | ||
/// | ||
/// assert_eq!(ui_rect.left, Val::Px(10.0)); | ||
/// assert_eq!(ui_rect.right, Val::Undefined); | ||
/// assert_eq!(ui_rect.top, Val::Undefined); | ||
/// assert_eq!(ui_rect.bottom, Val::Undefined); | ||
/// assert_eq!(ui_rect.right, Val::Px(0.)); | ||
/// assert_eq!(ui_rect.top, Val::Px(0.)); | ||
/// assert_eq!(ui_rect.bottom, Val::Px(0.)); | ||
/// ``` | ||
pub fn left(value: Val) -> Self { | ||
UiRect { | ||
|
@@ -265,10 +263,10 @@ impl UiRect { | |
/// # | ||
/// let ui_rect = UiRect::right(Val::Px(10.0)); | ||
/// | ||
/// assert_eq!(ui_rect.left, Val::Undefined); | ||
/// assert_eq!(ui_rect.left, Val::Px(0.)); | ||
/// assert_eq!(ui_rect.right, Val::Px(10.0)); | ||
/// assert_eq!(ui_rect.top, Val::Undefined); | ||
/// assert_eq!(ui_rect.bottom, Val::Undefined); | ||
/// assert_eq!(ui_rect.top, Val::Px(0.)); | ||
/// assert_eq!(ui_rect.bottom, Val::Px(0.)); | ||
/// ``` | ||
pub fn right(value: Val) -> Self { | ||
UiRect { | ||
|
@@ -286,10 +284,10 @@ impl UiRect { | |
/// # | ||
/// let ui_rect = UiRect::top(Val::Px(10.0)); | ||
/// | ||
/// assert_eq!(ui_rect.left, Val::Undefined); | ||
/// assert_eq!(ui_rect.right, Val::Undefined); | ||
/// assert_eq!(ui_rect.left, Val::Px(0.)); | ||
/// assert_eq!(ui_rect.right, Val::Px(0.)); | ||
/// assert_eq!(ui_rect.top, Val::Px(10.0)); | ||
/// assert_eq!(ui_rect.bottom, Val::Undefined); | ||
/// assert_eq!(ui_rect.bottom, Val::Px(0.)); | ||
/// ``` | ||
pub fn top(value: Val) -> Self { | ||
UiRect { | ||
|
@@ -307,9 +305,9 @@ impl UiRect { | |
/// # | ||
/// let ui_rect = UiRect::bottom(Val::Px(10.0)); | ||
/// | ||
/// assert_eq!(ui_rect.left, Val::Undefined); | ||
/// assert_eq!(ui_rect.right, Val::Undefined); | ||
/// assert_eq!(ui_rect.top, Val::Undefined); | ||
/// assert_eq!(ui_rect.left, Val::Px(0.)); | ||
/// assert_eq!(ui_rect.right, Val::Px(0.)); | ||
/// assert_eq!(ui_rect.top, Val::Px(0.)); | ||
Comment on lines
+243
to
+245
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GitHub won't comment me there directly, but can we maybe add a line to the documentation to make it explicit that all other values will be zero? So something like:
And then for the other methods (e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that makes sense and the same should be done for the |
||
/// assert_eq!(ui_rect.bottom, Val::Px(10.0)); | ||
/// ``` | ||
pub fn bottom(value: Val) -> Self { | ||
|
@@ -383,9 +381,6 @@ impl Size { | |
|
||
/// Creates a Size where both values are [`Val::Auto`]. | ||
pub const AUTO: Self = Self::all(Val::Auto); | ||
|
||
/// Creates a Size where both values are [`Val::Undefined`]. | ||
pub const UNDEFINED: Self = Self::all(Val::Undefined); | ||
} | ||
|
||
impl Default for Size { | ||
|
@@ -443,6 +438,11 @@ impl DivAssign<f32> for Size { | |
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn uirect_default_equals_const_default() { | ||
assert_eq!(UiRect::default(), UiRect::DEFAULT); | ||
} | ||
|
||
#[test] | ||
fn test_size_from() { | ||
let size: Size = (Val::Px(20.), Val::Px(30.)).into(); | ||
|
@@ -476,4 +476,48 @@ mod tests { | |
size /= 2.; | ||
assert_eq!(size, Size::new(Val::Px(10.), Val::Px(10.))); | ||
} | ||
|
||
#[test] | ||
fn test_size_all() { | ||
let length = Val::Px(10.); | ||
|
||
assert_eq!( | ||
Size::all(length), | ||
Size { | ||
width: length, | ||
height: length | ||
} | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_size_width() { | ||
let width = Val::Px(10.); | ||
|
||
assert_eq!( | ||
Size::width(width), | ||
Size { | ||
width, | ||
..Default::default() | ||
} | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_size_height() { | ||
let height = Val::Px(7.); | ||
|
||
assert_eq!( | ||
Size::height(height), | ||
Size { | ||
height, | ||
..Default::default() | ||
} | ||
); | ||
} | ||
|
||
#[test] | ||
fn size_default_equals_const_default() { | ||
assert_eq!(Size::default(), Size::DEFAULT); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.