Skip to content

Commit dd0c5dd

Browse files
committed
Add BoxGenerationMode style
1 parent 412c075 commit dd0c5dd

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

src/style/mod.rs

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ use crate::util::sys::GridTrackVec;
3535
/// but this is a just a convenience to save on boilerplate for styles that your implementation doesn't support. You will need
3636
/// to override the default implementation for each style property that your style type actually supports.
3737
pub trait CoreStyle {
38-
/// What layout strategy should be used?
39-
// fn display(&self);
38+
/// Which box generation mode should be used
39+
#[inline(always)]
40+
fn box_generation_mode(&self) -> BoxGenerationMode {
41+
BoxGenerationMode::DEFAULT
42+
}
4043

4144
// Overflow properties
4245
/// How children overflowing their container should affect layout
@@ -118,28 +121,34 @@ pub enum Display {
118121
/// The children will follow the CSS Grid layout algorithm
119122
#[cfg(feature = "grid")]
120123
Grid,
121-
/// The children will not be laid out, and will follow absolute positioning
124+
/// The node is hidden, and it's children will also be hidden
122125
None,
123126
}
124127

125128
impl Display {
126-
/// The default of Display.
129+
/// The default Display mode
127130
#[cfg(feature = "flexbox")]
128131
pub const DEFAULT: Display = Display::Flex;
129132

130-
/// The default of Display.
133+
/// The default Display mode
131134
#[cfg(all(feature = "grid", not(feature = "flexbox")))]
132135
pub const DEFAULT: Display = Display::Grid;
133136

134-
/// The default of Display.
137+
/// The default Display mode
135138
#[cfg(all(feature = "block_layout", not(feature = "flexbox"), not(feature = "grid")))]
136139
pub const DEFAULT: Display = Display::Block;
137140

138-
/// The default of Display.
141+
/// The default Display mode
139142
#[cfg(all(not(feature = "flexbox"), not(feature = "grid"), not(feature = "block_layout")))]
140143
pub const DEFAULT: Display = Display::None;
141144
}
142145

146+
impl Default for Display {
147+
fn default() -> Self {
148+
Self::DEFAULT
149+
}
150+
}
151+
143152
impl core::fmt::Display for Display {
144153
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
145154
match self {
@@ -154,7 +163,23 @@ impl core::fmt::Display for Display {
154163
}
155164
}
156165

157-
impl Default for Display {
166+
/// An abstracted version of the CSS `display` property where any value other than "none" is represented by "normal"
167+
/// See: <https://www.w3.org/TR/css-display-3/#box-generation>
168+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
169+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
170+
pub enum BoxGenerationMode {
171+
/// The node generates a box in the regular way
172+
Normal,
173+
/// The node and it's descendants generate no boxes (they are hidden)
174+
None,
175+
}
176+
177+
impl BoxGenerationMode {
178+
/// The default of BoxGenerationMode
179+
pub const DEFAULT: BoxGenerationMode = BoxGenerationMode::Normal;
180+
}
181+
182+
impl Default for BoxGenerationMode {
158183
fn default() -> Self {
159184
Self::DEFAULT
160185
}
@@ -433,6 +458,13 @@ impl Default for Style {
433458
}
434459

435460
impl CoreStyle for Style {
461+
#[inline(always)]
462+
fn box_generation_mode(&self) -> BoxGenerationMode {
463+
match self.display {
464+
Display::None => BoxGenerationMode::None,
465+
_ => BoxGenerationMode::Normal,
466+
}
467+
}
436468
#[inline(always)]
437469
fn overflow(&self) -> Point<Overflow> {
438470
self.overflow

0 commit comments

Comments
 (0)