cranpose_ui/modifier/
resolved_modifiers.rs1use cranpose_ui_layout::{Alignment, HorizontalAlignment, IntrinsicSize, VerticalAlignment};
2
3use super::{Color, EdgeInsets, Point, RoundedCornerShape};
4
5#[derive(Clone, Copy, Debug, PartialEq)]
7pub struct ResolvedBackground {
8 pub(super) color: Color,
9 pub(super) shape: Option<RoundedCornerShape>,
10}
11
12impl ResolvedBackground {
13 pub fn new(color: Color, shape: Option<RoundedCornerShape>) -> Self {
16 Self { color, shape }
17 }
18
19 pub fn color(&self) -> Color {
21 self.color
22 }
23
24 pub fn shape(&self) -> Option<RoundedCornerShape> {
26 self.shape
27 }
28
29 pub fn set_shape(&mut self, shape: Option<RoundedCornerShape>) {
31 self.shape = shape;
32 }
33}
34
35#[derive(Clone, Copy, Debug, PartialEq, Default)]
37pub struct ResolvedModifiers {
38 pub(super) padding: EdgeInsets,
39 pub(super) layout: LayoutProperties,
40 pub(super) offset: Point,
41}
42
43impl ResolvedModifiers {
44 pub fn padding(&self) -> EdgeInsets {
46 self.padding
47 }
48
49 pub fn layout_properties(&self) -> LayoutProperties {
51 self.layout
52 }
53
54 pub fn offset(&self) -> Point {
56 self.offset
57 }
58
59 pub(crate) fn set_padding(&mut self, padding: EdgeInsets) {
60 self.padding = padding;
61 }
62
63 pub(crate) fn set_layout_properties(&mut self, layout: LayoutProperties) {
64 self.layout = layout;
65 }
66
67 pub(crate) fn set_offset(&mut self, offset: Point) {
68 self.offset = offset;
69 }
70}
71
72#[derive(Clone, Copy, Debug, Default, PartialEq)]
73pub enum DimensionConstraint {
74 #[default]
75 Unspecified,
76 Points(f32),
77 Fraction(f32),
78 Intrinsic(IntrinsicSize),
79}
80
81#[derive(Clone, Copy, Debug, Default, PartialEq)]
82pub struct LayoutWeight {
83 pub weight: f32,
84 pub fill: bool,
85}
86
87#[derive(Clone, Copy, Debug, Default, PartialEq)]
88pub struct LayoutProperties {
89 pub(super) padding: EdgeInsets,
90 pub(super) width: DimensionConstraint,
91 pub(super) height: DimensionConstraint,
92 pub(super) min_width: Option<f32>,
93 pub(super) min_height: Option<f32>,
94 pub(super) max_width: Option<f32>,
95 pub(super) max_height: Option<f32>,
96 pub(super) weight: Option<LayoutWeight>,
97 pub(super) box_alignment: Option<Alignment>,
98 pub(super) column_alignment: Option<HorizontalAlignment>,
99 pub(super) row_alignment: Option<VerticalAlignment>,
100 pub(super) row_baseline: bool,
101}
102
103impl LayoutProperties {
104 pub fn padding(&self) -> EdgeInsets {
105 self.padding
106 }
107
108 pub fn width(&self) -> DimensionConstraint {
109 self.width
110 }
111
112 pub fn height(&self) -> DimensionConstraint {
113 self.height
114 }
115
116 pub fn min_width(&self) -> Option<f32> {
117 self.min_width
118 }
119
120 pub fn min_height(&self) -> Option<f32> {
121 self.min_height
122 }
123
124 pub fn max_width(&self) -> Option<f32> {
125 self.max_width
126 }
127
128 pub fn max_height(&self) -> Option<f32> {
129 self.max_height
130 }
131
132 pub fn weight(&self) -> Option<LayoutWeight> {
133 self.weight
134 }
135
136 pub fn box_alignment(&self) -> Option<Alignment> {
137 self.box_alignment
138 }
139
140 pub fn column_alignment(&self) -> Option<HorizontalAlignment> {
141 self.column_alignment
142 }
143
144 pub fn row_alignment(&self) -> Option<VerticalAlignment> {
145 self.row_alignment
146 }
147
148 pub fn row_baseline(&self) -> bool {
150 self.row_baseline
151 }
152}