@@ -35,8 +35,11 @@ use crate::util::sys::GridTrackVec;
35
35
/// but this is a just a convenience to save on boilerplate for styles that your implementation doesn't support. You will need
36
36
/// to override the default implementation for each style property that your style type actually supports.
37
37
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
+ }
40
43
41
44
// Overflow properties
42
45
/// How children overflowing their container should affect layout
@@ -118,28 +121,34 @@ pub enum Display {
118
121
/// The children will follow the CSS Grid layout algorithm
119
122
#[ cfg( feature = "grid" ) ]
120
123
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
122
125
None ,
123
126
}
124
127
125
128
impl Display {
126
- /// The default of Display.
129
+ /// The default Display mode
127
130
#[ cfg( feature = "flexbox" ) ]
128
131
pub const DEFAULT : Display = Display :: Flex ;
129
132
130
- /// The default of Display.
133
+ /// The default Display mode
131
134
#[ cfg( all( feature = "grid" , not( feature = "flexbox" ) ) ) ]
132
135
pub const DEFAULT : Display = Display :: Grid ;
133
136
134
- /// The default of Display.
137
+ /// The default Display mode
135
138
#[ cfg( all( feature = "block_layout" , not( feature = "flexbox" ) , not( feature = "grid" ) ) ) ]
136
139
pub const DEFAULT : Display = Display :: Block ;
137
140
138
- /// The default of Display.
141
+ /// The default Display mode
139
142
#[ cfg( all( not( feature = "flexbox" ) , not( feature = "grid" ) , not( feature = "block_layout" ) ) ) ]
140
143
pub const DEFAULT : Display = Display :: None ;
141
144
}
142
145
146
+ impl Default for Display {
147
+ fn default ( ) -> Self {
148
+ Self :: DEFAULT
149
+ }
150
+ }
151
+
143
152
impl core:: fmt:: Display for Display {
144
153
fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
145
154
match self {
@@ -154,7 +163,23 @@ impl core::fmt::Display for Display {
154
163
}
155
164
}
156
165
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 {
158
183
fn default ( ) -> Self {
159
184
Self :: DEFAULT
160
185
}
@@ -433,6 +458,13 @@ impl Default for Style {
433
458
}
434
459
435
460
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
+ }
436
468
#[ inline( always) ]
437
469
fn overflow ( & self ) -> Point < Overflow > {
438
470
self . overflow
0 commit comments