Skip to content

Commit

Permalink
Add Size::new_with_cross utility method (#609)
Browse files Browse the repository at this point in the history
* Add Size::new_with_cross utility method

Signed-off-by: Taym <[email protected]>

* Rename to from_cross and add flexbox feature

Signed-off-by: Taym <[email protected]>

---------

Signed-off-by: Taym <[email protected]>
  • Loading branch information
Taym95 authored Feb 12, 2024
1 parent f55d551 commit 7825ae4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compute/flexbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ fn determine_flex_base_size(

// Parent size for child sizing
let cross_axis_parent_size = constants.node_inner_size.cross(dir);
let child_parent_size = Size::NONE.with_cross(dir, cross_axis_parent_size);
let child_parent_size = Size::from_cross(dir, cross_axis_parent_size);

// Available space for child sizing
let cross_axis_margin_sum = constants.margin.cross_axis_sum(dir);
Expand Down
12 changes: 12 additions & 0 deletions src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,18 @@ impl Size<Option<f32>> {
Size { width: Some(width), height: Some(height) }
}

/// Creates a new [`Size<Option<f32>>`] with either the width or height set based on the provided `direction`
#[cfg(feature = "flexbox")]
pub fn from_cross(direction: FlexDirection, value: Option<f32>) -> Self {
let mut new = Self::NONE;
if direction.is_row() {
new.height = value
} else {
new.width = value
}
new
}

/// Applies aspect_ratio (if one is supplied) to the Size:
/// - If width is `Some` but height is `None`, then height is computed from width and aspect_ratio
/// - If height is `Some` but width is `None`, then width is computed from height and aspect_ratio
Expand Down

0 comments on commit 7825ae4

Please sign in to comment.