cranpose_ui/widgets/
padding_values.rs1use cranpose_ui_graphics::EdgeInsets;
4
5use crate::{
6 Modifier,
7 layout_direction::{LayoutDirection, layout_direction},
8};
9
10#[derive(Clone, Copy, Debug, Default, PartialEq)]
16pub struct PaddingValues {
17 pub start: f32,
18 pub top: f32,
19 pub end: f32,
20 pub bottom: f32,
21}
22
23impl PaddingValues {
24 pub const fn new(start: f32, top: f32, end: f32, bottom: f32) -> Self {
25 Self {
26 start,
27 top,
28 end,
29 bottom,
30 }
31 }
32
33 pub const fn all(value: f32) -> Self {
35 Self::new(value, value, value, value)
36 }
37
38 pub const fn symmetric(horizontal: f32, vertical: f32) -> Self {
41 Self::new(horizontal, vertical, horizontal, vertical)
42 }
43
44 pub fn apply_to(self, modifier: Modifier) -> Modifier {
46 self.apply_to_in(modifier, layout_direction())
47 }
48
49 pub fn apply_to_in(self, modifier: Modifier, direction: LayoutDirection) -> Modifier {
51 modifier.padding_relative_in(direction, self.start, self.top, self.end, self.bottom)
52 }
53
54 pub fn physical(self, direction: LayoutDirection) -> EdgeInsets {
56 let (left, right) = direction.resolve(self.start, self.end);
57 EdgeInsets::from_components(left, self.top, right, self.bottom)
58 }
59
60 pub fn max(self, other: Self) -> Self {
62 Self::new(
63 self.start.max(other.start),
64 self.top.max(other.top),
65 self.end.max(other.end),
66 self.bottom.max(other.bottom),
67 )
68 }
69}