gpui_material_components/
insets.rs1use gpui::{Edges, Pixels, px};
2use gpui_material_theme::Direction;
3
4#[derive(Clone, Copy, Debug, Default, PartialEq)]
6pub struct ScaffoldInsets {
7 pub top: Pixels,
9 pub start: Pixels,
11 pub bottom: Pixels,
13 pub end: Pixels,
15}
16
17impl ScaffoldInsets {
18 pub fn resolve(self, direction: Direction) -> Edges<Pixels> {
20 let (left, right) = if direction == Direction::Rtl {
21 (self.end, self.start)
22 } else {
23 (self.start, self.end)
24 };
25 Edges {
26 top: self.top,
27 left,
28 bottom: self.bottom,
29 right,
30 }
31 }
32
33 #[cfg_attr(
34 not(any(feature = "feedback", feature = "navigation")),
35 allow(dead_code)
36 )]
37 pub(crate) fn normalized(self) -> Self {
38 let finite = |edge: Pixels| {
39 if f32::from(edge).is_finite() {
40 edge.max(px(0.))
41 } else {
42 px(0.)
43 }
44 };
45 Self {
46 top: finite(self.top),
47 start: finite(self.start),
48 bottom: finite(self.bottom),
49 end: finite(self.end),
50 }
51 }
52}