tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definiciones

refactoring

f302b51f428d388018380baab041423984ff769e · por Adam Nemecek · (hace 6 años) · padre 270d2396a · ver el árbol en este commit

Delta semántico · 22

src/geometry.rs

src/style.rs

2 archivos · +92 −60

diff --git a/src/geometry.rs b/src/geometry.rs
index 2efad1245..f5471e4b6 100644
--- a/src/geometry.rs
+++ b/src/geometry.rs
@@ -37,16 +37,18 @@ where
     }
 
     pub(crate) fn main(&self, direction: style::FlexDirection) -> T {
-        match direction {
-            style::FlexDirection::Row | style::FlexDirection::RowReverse => self.start + self.end,
-            style::FlexDirection::Column | style::FlexDirection::ColumnReverse => self.top + self.bottom,
+        if direction.is_row() {
+            self.horizontal()
+        } else {
+            self.vertical()
         }
     }
 
     pub(crate) fn cross(&self, direction: style::FlexDirection) -> T {
-        match direction {
-            style::FlexDirection::Row | style::FlexDirection::RowReverse => self.top + self.bottom,
-            style::FlexDirection::Column | style::FlexDirection::ColumnReverse => self.start + self.end,
+        if direction.is_row() {
+            self.vertical()
+        } else {
+            self.horizontal()
         }
     }
 }
@@ -56,30 +58,34 @@ where
     T: Copy + Clone,
 {
     pub(crate) fn main_start(&self, direction: style::FlexDirection) -> T {
-        match direction {
-            style::FlexDirection::Row | style::FlexDirection::RowReverse => self.start,
-            style::FlexDirection::Column | style::FlexDirection::ColumnReverse => self.top,
+        if direction.is_row() {
+            self.start
+        } else {
+            self.top
         }
     }
 
     pub(crate) fn main_end(&self, direction: style::FlexDirection) -> T {
-        match direction {
-            style::FlexDirection::Row | style::FlexDirection::RowReverse => self.end,
-            style::FlexDirection::Column | style::FlexDirection::ColumnReverse => self.bottom,
+        if direction.is_row() {
+            self.end
+        } else {
+            self.bottom
         }
     }
 
     pub(crate) fn cross_start(&self, direction: style::FlexDirection) -> T {
-        match direction {
-            style::FlexDirection::Row | style::FlexDirection::RowReverse => self.top,
-            style::FlexDirection::Column | style::FlexDirection::ColumnReverse => self.start,
+        if direction.is_row() {
+            self.top
+        } else {
+            self.start
         }
     }
 
     pub(crate) fn cross_end(&self, direction: style::FlexDirection) -> T {
-        match direction {
-            style::FlexDirection::Row | style::FlexDirection::RowReverse => self.bottom,
-            style::FlexDirection::Column | style::FlexDirection::ColumnReverse => self.end,
+        if direction.is_row() {
+            self.bottom
+        } else {
+            self.end
         }
     }
 }
@@ -109,30 +115,34 @@ impl<T> Size<T> {
     }
 
     pub(crate) fn set_main(&mut self, direction: style::FlexDirection, value: T) {
-        match direction {
-            style::FlexDirection::Row | style::FlexDirection::RowReverse => self.width = value,
-            style::FlexDirection::Column | style::FlexDirection::ColumnReverse => self.height = value,
+        if direction.is_row() {
+            self.width = value
+        } else {
+            self.height = value
         }
     }
 
     pub(crate) fn set_cross(&mut self, direction: style::FlexDirection, value: T) {
-        match direction {
-            style::FlexDirection::Row | style::FlexDirection::RowReverse => self.height = value,
-            style::FlexDirection::Column | style::FlexDirection::ColumnReverse => self.width = value,
+        if direction.is_row() {
+            self.height = value
+        } else {
+            self.width = value
         }
     }
 
     pub(crate) fn main(self, direction: style::FlexDirection) -> T {
-        match direction {
-            style::FlexDirection::Row | style::FlexDirection::RowReverse => self.width,
-            style::FlexDirection::Column | style::FlexDirection::ColumnReverse => self.height,
+        if direction.is_row() {
+            self.width
+        } else {
+            self.height
         }
     }
 
     pub(crate) fn cross(self, direction: style::FlexDirection) -> T {
-        match direction {
-            style::FlexDirection::Row | style::FlexDirection::RowReverse => self.height,
-            style::FlexDirection::Column | style::FlexDirection::ColumnReverse => self.width,
+        if direction.is_row() {
+            self.height
+        } else {
+            self.width
         }
     }
 }
diff --git a/src/style.rs b/src/style.rs
index 212c1e1c4..511fd55be 100644
--- a/src/style.rs
+++ b/src/style.rs
@@ -110,16 +110,29 @@ impl Default for FlexDirection {
 }
 
 impl FlexDirection {
+
+    #[inline]
     pub(crate) fn is_row(self) -> bool {
-        self == FlexDirection::Row || self == FlexDirection::RowReverse
+        match self {
+            Self::Row | Self::RowReverse => true,
+            _ => false,
+        }
     }
 
+    #[inline]
     pub(crate) fn is_column(self) -> bool {
-        self == FlexDirection::Column || self == FlexDirection::ColumnReverse
+        match self {
+            Self::Column | Self::ColumnReverse => true,
+            _ => false,
+        }
     }
 
+    #[inline]
     pub(crate) fn is_reverse(self) -> bool {
-        self == FlexDirection::RowReverse || self == FlexDirection::ColumnReverse
+        match self {
+            Self::RowReverse | Self::ColumnReverse => true,
+            _ => false,
+        }
     }
 }
 
@@ -295,65 +308,74 @@ impl Default for Style {
 
 impl Style {
     pub(crate) fn min_main_size(&self, direction: FlexDirection) -> Dimension {
-        match direction {
-            FlexDirection::Row | FlexDirection::RowReverse => self.min_size.width,
-            FlexDirection::Column | FlexDirection::ColumnReverse => self.min_size.height,
+        if direction.is_row() {
+            self.min_size.width
+        } else {
+            self.min_size.height
         }
     }
 
     pub(crate) fn max_main_size(&self, direction: FlexDirection) -> Dimension {
-        match direction {
-            FlexDirection::Row | FlexDirection::RowReverse => self.max_size.width,
-            FlexDirection::Column | FlexDirection::ColumnReverse => self.max_size.height,
+        if direction.is_row() {
+            self.max_size.width
+        } else {
+            self.max_size.height
         }
     }
 
     pub(crate) fn main_margin_start(&self, direction: FlexDirection) -> Dimension {
-        match direction {
-            FlexDirection::Row | FlexDirection::RowReverse => self.margin.start,
-            FlexDirection::Column | FlexDirection::ColumnReverse => self.margin.top,
+        if direction.is_row() {
+            self.margin.start
+        } else {
+            self.margin.top
         }
     }
 
     pub(crate) fn main_margin_end(&self, direction: FlexDirection) -> Dimension {
-        match direction {
-            FlexDirection::Row | FlexDirection::RowReverse => self.margin.end,
-            FlexDirection::Column | FlexDirection::ColumnReverse => self.margin.bottom,
+        if direction.is_row() {
+            self.margin.end
+        } else {
+            self.margin.bottom
         }
     }
 
     pub(crate) fn cross_size(&self, direction: FlexDirection) -> Dimension {
-        match direction {
-            FlexDirection::Row | FlexDirection::RowReverse => self.size.height,
-            FlexDirection::Column | FlexDirection::ColumnReverse => self.size.width,
+        if direction.is_row() {
+            self.size.height
+        } else {
+            self.size.width
         }
     }
 
     pub(crate) fn min_cross_size(&self, direction: FlexDirection) -> Dimension {
-        match direction {
-            FlexDirection::Row | FlexDirection::RowReverse => self.min_size.height,
-            FlexDirection::Column | FlexDirection::ColumnReverse => self.min_size.width,
+        if direction.is_row() {
+            self.min_size.height
+        } else {
+            self.min_size.width
         }
     }
 
     pub(crate) fn max_cross_size(&self, direction: FlexDirection) -> Dimension {
-        match direction {
-            FlexDirection::Row | FlexDirection::RowReverse => self.max_size.height,
-            FlexDirection::Column | FlexDirection::ColumnReverse => self.max_size.width,
+        if direction.is_row() {
+            self.max_size.height
+        } else {
+            self.max_size.width
         }
     }
 
     pub(crate) fn cross_margin_start(&self, direction: FlexDirection) -> Dimension {
-        match direction {
-            FlexDirection::Row | FlexDirection::RowReverse => self.margin.top,
-            FlexDirection::Column | FlexDirection::ColumnReverse => self.margin.start,
+        if direction.is_row() {
+            self.margin.top
+        } else {
+            self.margin.start
         }
     }
 
     pub(crate) fn cross_margin_end(&self, direction: FlexDirection) -> Dimension {
-        match direction {
-            FlexDirection::Row | FlexDirection::RowReverse => self.margin.bottom,
-            FlexDirection::Column | FlexDirection::ColumnReverse => self.margin.end,
+        if direction.is_row() {
+            self.margin.bottom
+        } else {
+            self.margin.end
         }
     }