gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1117HTML 1044Markdown 12TOML 94797 Definiciones

Add `BoxGenerationMode` style

82574827f92c71f4d371f8c4effcd4f5b839daab · por Nico Burns · (hace 3 años) · padre b8e23949f · ver el árbol en este commit

Delta semántico · 6

src/style/mod.rs

1 archivos · +40 −8

diff --git a/src/style/mod.rs b/src/style/mod.rs
index fbaa7561b..bcc4a436e 100644
--- a/src/style/mod.rs
+++ b/src/style/mod.rs
@@ -35,8 +35,11 @@ use crate::util::sys::GridTrackVec;
 /// but this is a just a convenience to save on boilerplate for styles that your implementation doesn't support. You will need
 /// to override the default implementation for each style property that your style type actually supports.
 pub trait CoreStyle {
-    /// What layout strategy should be used?
-    // fn display(&self);
+    /// Which box generation mode should be used
+    #[inline(always)]
+    fn box_generation_mode(&self) -> BoxGenerationMode {
+        BoxGenerationMode::DEFAULT
+    }
 
     // Overflow properties
     /// How children overflowing their container should affect layout
@@ -118,28 +121,34 @@ pub enum Display {
     /// The children will follow the CSS Grid layout algorithm
     #[cfg(feature = "grid")]
     Grid,
-    /// The children will not be laid out, and will follow absolute positioning
+    /// The node is hidden, and it's children will also be hidden
     None,
 }
 
 impl Display {
-    /// The default of Display.
+    /// The default Display mode
     #[cfg(feature = "flexbox")]
     pub const DEFAULT: Display = Display::Flex;
 
-    /// The default of Display.
+    /// The default Display mode
     #[cfg(all(feature = "grid", not(feature = "flexbox")))]
     pub const DEFAULT: Display = Display::Grid;
 
-    /// The default of Display.
+    /// The default Display mode
     #[cfg(all(feature = "block_layout", not(feature = "flexbox"), not(feature = "grid")))]
     pub const DEFAULT: Display = Display::Block;
 
-    /// The default of Display.
+    /// The default Display mode
     #[cfg(all(not(feature = "flexbox"), not(feature = "grid"), not(feature = "block_layout")))]
     pub const DEFAULT: Display = Display::None;
 }
 
+impl Default for Display {
+    fn default() -> Self {
+        Self::DEFAULT
+    }
+}
+
 impl core::fmt::Display for Display {
     fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
         match self {
@@ -154,7 +163,23 @@ impl core::fmt::Display for Display {
     }
 }
 
-impl Default for Display {
+/// An abstracted version of the CSS `display` property where any value other than "none" is represented by "normal"
+/// See: <https://www.w3.org/TR/css-display-3/#box-generation>
+#[derive(Copy, Clone, PartialEq, Eq, Debug)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+pub enum BoxGenerationMode {
+    /// The node generates a box in the regular way
+    Normal,
+    /// The node and it's descendants generate no boxes (they are hidden)
+    None,
+}
+
+impl BoxGenerationMode {
+    /// The default of BoxGenerationMode
+    pub const DEFAULT: BoxGenerationMode = BoxGenerationMode::Normal;
+}
+
+impl Default for BoxGenerationMode {
     fn default() -> Self {
         Self::DEFAULT
     }
@@ -442,6 +467,13 @@ impl Default for Style {
 }
 
 impl CoreStyle for Style {
+    #[inline(always)]
+    fn box_generation_mode(&self) -> BoxGenerationMode {
+        match self.display {
+            Display::None => BoxGenerationMode::None,
+            _ => BoxGenerationMode::Normal,
+        }
+    }
     #[inline(always)]
     fn overflow(&self) -> Point<Overflow> {
         self.overflow