1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use crate::*;
/// A null element that takes up no space.
///
/// It uses `None` as the size on both axes, meaning it will trigger collapsing in containers that
/// support it, such as a `Column` with `collapse: true`. Collapsing means that for example the gaps
/// before and after the element will be combined into one and if all elements in a container are
/// collapsed, the container itself will also have a `None` size on the relevant axis.
///
/// This element is useful for conditional layouts where you may want to
/// include an element or nothing at all based on some condition.
pub struct NoneElement;
impl Element for NoneElement {
fn first_location_usage(&self, _ctx: FirstLocationUsageCtx) -> FirstLocationUsage {
FirstLocationUsage::NoneHeight
}
fn measure(&self, _ctx: MeasureCtx) -> ElementSize {
ElementSize {
width: None,
height: None,
}
}
fn draw(&self, _ctx: DrawCtx) -> ElementSize {
ElementSize {
width: None,
height: None,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::test_utils::*;
#[test]
fn none_element() {
for output in ElementTestParams::default().run(&NoneElement) {
output.assert_size(ElementSize {
width: None,
height: None,
});
if let Some(b) = output.breakable {
b.assert_break_count(0)
.assert_extra_location_min_height(None);
}
}
}
}