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,
8 pub start: Pixels,
9 pub bottom: Pixels,
10 pub end: Pixels,
11}
12
13impl ScaffoldInsets {
14 pub fn resolve(self, direction: Direction) -> Edges<Pixels> {
15 let (left, right) = if direction == Direction::Rtl {
16 (self.end, self.start)
17 } else {
18 (self.start, self.end)
19 };
20 Edges {
21 top: self.top,
22 left,
23 bottom: self.bottom,
24 right,
25 }
26 }
27
28 #[cfg_attr(
29 not(any(feature = "feedback", feature = "navigation")),
30 allow(dead_code)
31 )]
32 pub(crate) fn normalized(self) -> Self {
33 let finite = |edge: Pixels| {
34 if f32::from(edge).is_finite() {
35 edge.max(px(0.))
36 } else {
37 px(0.)
38 }
39 };
40 Self {
41 top: finite(self.top),
42 start: finite(self.start),
43 bottom: finite(self.bottom),
44 end: finite(self.end),
45 }
46 }
47}