gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5364Rust 86Markdown 12TOML 91841 Definiciones

Add Size::new_with_cross utility method (#609)

* Add Size::new_with_cross utility method

Signed-off-by: Taym <haddadi.taym@gmail.com>

* Rename to from_cross and add flexbox feature

Signed-off-by: Taym <haddadi.taym@gmail.com>

---------

Signed-off-by: Taym <haddadi.taym@gmail.com>

7825ae4072b21b802188269d577eaa2757033f8b · por Taym Haddadi · (hace 2 años) · padre f55d55115 · ver el árbol en este commit

Delta semántico · 2

src/compute/flexbox.rs

src/geometry.rs

2 archivos · +13 −1

diff --git a/src/compute/flexbox.rs b/src/compute/flexbox.rs
index eb67fc144..aebbd75b4 100644
--- a/src/compute/flexbox.rs
+++ b/src/compute/flexbox.rs
@@ -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);
diff --git a/src/geometry.rs b/src/geometry.rs
index 7d620adc0..497989ff0 100644
--- a/src/geometry.rs
+++ b/src/geometry.rs
@@ -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