Skip to content

Commit d5aa4d4

Browse files
committed
Improve naming of new types in length module
1 parent 1919db7 commit d5aa4d4

4 files changed

Lines changed: 62 additions & 55 deletions

File tree

core/src/layout/flex.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ where
154154

155155
match meta.main {
156156
Length::Bounded {
157-
with: length::Fluidity::Fill(_),
157+
sizing: length::Sizing::Fill(_),
158158
bounds: length::Bounds::Min(min),
159159
}
160160
| Length::Fluid(length::Constraint::Min(min)) => {
161161
min_total += min;
162162
min_factors += fill_main_factor;
163163
}
164164
Length::Bounded {
165-
with: length::Fluidity::Fill(_),
165+
sizing: length::Sizing::Fill(_),
166166
bounds: length::Bounds::Max(_) | length::Bounds::Both { .. },
167167
}
168168
| Length::Fluid(length::Constraint::Max) => {

core/src/layout/limits.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl Limits {
6464
self.max.width = new_width;
6565
self.compression.width = false;
6666
}
67-
Length::Bounded { bounds, with } => {
67+
Length::Bounded { bounds, sizing } => {
6868
match bounds {
6969
length::Bounds::Min(min) => {
7070
self.min.width = min.min(self.max.width).max(self.min.width);
@@ -78,14 +78,14 @@ impl Limits {
7878
}
7979
}
8080

81-
match with {
82-
length::Fluidity::Shrink => {
81+
match sizing {
82+
length::Sizing::Shrink => {
8383
self.compression.width = true;
8484
}
85-
length::Fluidity::Fit => {
85+
length::Sizing::Fit => {
8686
self.compression.width = false;
8787
}
88-
length::Fluidity::Fill(_) => {}
88+
length::Sizing::Fill(_) => {}
8989
}
9090
}
9191
Length::Fill | Length::FillPortion(_) => {}
@@ -110,7 +110,7 @@ impl Limits {
110110
self.max.height = new_height;
111111
self.compression.height = false;
112112
}
113-
Length::Bounded { bounds, with } => {
113+
Length::Bounded { bounds, sizing } => {
114114
match bounds {
115115
length::Bounds::Min(min) => {
116116
self.min.height = min.min(self.max.height).max(self.min.height);
@@ -124,14 +124,14 @@ impl Limits {
124124
}
125125
}
126126

127-
match with {
128-
length::Fluidity::Shrink => {
127+
match sizing {
128+
length::Sizing::Shrink => {
129129
self.compression.height = true;
130130
}
131-
length::Fluidity::Fit => {
131+
length::Sizing::Fit => {
132132
self.compression.height = false;
133133
}
134-
length::Fluidity::Fill(_) => {}
134+
length::Sizing::Fill(_) => {}
135135
}
136136
}
137137
Length::Fill | Length::FillPortion(_) => {}
@@ -191,7 +191,7 @@ impl Limits {
191191
Length::Fill
192192
| Length::FillPortion(_)
193193
| Length::Bounded {
194-
with: length::Fluidity::Fill(_),
194+
sizing: length::Sizing::Fill(_),
195195
..
196196
} if !self.compression.width => self.max.width,
197197
Length::Fixed(amount) => amount.min(self.max.width).max(self.min.width),
@@ -205,7 +205,7 @@ impl Limits {
205205
Length::Fill
206206
| Length::FillPortion(_)
207207
| Length::Bounded {
208-
with: length::Fluidity::Fill(_),
208+
sizing: length::Sizing::Fill(_),
209209
..
210210
} if !self.compression.height => self.max.height,
211211
Length::Fixed(amount) => amount.min(self.max.height).max(self.min.height),

core/src/length.rs

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ pub enum Length {
2727
/// Fill a fixed amount of space in pixels.
2828
Fixed(f32),
2929

30-
/// Fill a certain amount of space inside the given [`Bounds`] with some [`Fluidity`].
30+
/// Fill a certain amount of space inside the given [`Bounds`] with some [`Sizing`] strategy.
3131
Bounded {
32-
/// The amount of space that can be filled.
32+
/// The [`Bounds`] of space that can be filled.
3333
bounds: Bounds,
34-
/// The strategy in which the space should be filled.
35-
with: Fluidity,
34+
/// The [`Sizing`] strategy with which the [`Bounds`] should be filled.
35+
sizing: Sizing,
3636
},
3737

38-
/// TODO
38+
/// Fill the remaining space like [`Fill`](Self::Fill), but subject to a single
39+
/// open-ended [`Constraint`].
3940
Fluid(Constraint),
4041
}
4142

@@ -98,7 +99,7 @@ impl Bounds {
9899
}
99100

100101
#[derive(Debug, Clone, Copy, PartialEq)]
101-
pub enum Fluidity {
102+
pub enum Sizing {
102103
Fit,
103104
Fill(u16),
104105
Shrink,
@@ -110,22 +111,25 @@ impl Length {
110111
let min = min.into().0;
111112

112113
let with = match self {
113-
Self::Fit | Self::Fluid(_) => Fluidity::Fit,
114-
Self::Fill => Fluidity::Fill(1),
115-
Self::FillPortion(factor) => Fluidity::Fill(factor),
116-
Self::Shrink => Fluidity::Shrink,
114+
Self::Fit | Self::Fluid(_) => Sizing::Fit,
115+
Self::Fill => Sizing::Fill(1),
116+
Self::FillPortion(factor) => Sizing::Fill(factor),
117+
Self::Shrink => Sizing::Shrink,
117118
Self::Fixed(_) => return self,
118-
Self::Bounded { bounds, with } => {
119+
Self::Bounded {
120+
bounds,
121+
sizing: with,
122+
} => {
119123
return Self::Bounded {
120124
bounds: bounds.min(min),
121-
with,
125+
sizing: with,
122126
};
123127
}
124128
};
125129

126130
Self::Bounded {
127131
bounds: Bounds::Min(min),
128-
with,
132+
sizing: with,
129133
}
130134
}
131135

@@ -134,22 +138,25 @@ impl Length {
134138
let max = max.into().0;
135139

136140
let with = match self {
137-
Self::Fit | Self::Fluid(_) => Fluidity::Fit,
138-
Self::Fill => Fluidity::Fill(1),
139-
Self::FillPortion(factor) => Fluidity::Fill(factor),
140-
Self::Shrink => Fluidity::Shrink,
141+
Self::Fit | Self::Fluid(_) => Sizing::Fit,
142+
Self::Fill => Sizing::Fill(1),
143+
Self::FillPortion(factor) => Sizing::Fill(factor),
144+
Self::Shrink => Sizing::Shrink,
141145
Self::Fixed(_) => return self,
142-
Self::Bounded { bounds, with } => {
146+
Self::Bounded {
147+
bounds,
148+
sizing: with,
149+
} => {
143150
return Self::Bounded {
144151
bounds: bounds.max(max),
145-
with,
152+
sizing: with,
146153
};
147154
}
148155
};
149156

150157
Self::Bounded {
151158
bounds: Bounds::Max(max),
152-
with,
159+
sizing: with,
153160
}
154161
}
155162

@@ -163,7 +170,7 @@ impl Length {
163170
Length::Fill => 1,
164171
Length::FillPortion(factor)
165172
| Length::Bounded {
166-
with: Fluidity::Fill(factor),
173+
sizing: Sizing::Fill(factor),
167174
..
168175
} => *factor,
169176
Length::Fluid(_) => 1,
@@ -182,19 +189,6 @@ impl Length {
182189
matches!(self, Self::Fit)
183190
}
184191

185-
/// Returns the "fluid" variant of the [`Length`].
186-
///
187-
/// Specifically:
188-
/// - [`Length::Shrink`] if [`Length::Shrink`] or [`Length::Fixed`].
189-
/// - [`Length::Fill`] otherwise.
190-
pub fn fluid(&self) -> Self {
191-
if self.fill_factor() == 0 {
192-
Self::Shrink
193-
} else {
194-
Self::Fill
195-
}
196-
}
197-
198192
/// TODO
199193
pub fn stack(self, other: Length) -> Self {
200194
self.merge_with(other, Constraint::stack)
@@ -216,34 +210,43 @@ impl Length {
216210
Length::Fluid(a),
217211
Length::Bounded {
218212
bounds,
219-
with: Fluidity::Fill(_),
213+
sizing: Sizing::Fill(_),
220214
},
221215
) => Length::Fluid(merge(a, bounds.constraint())),
222216
(Length::Fluid(constraint), _) => Length::Fluid(constraint),
223217

224218
(
225219
Length::Bounded {
226220
bounds,
227-
with: Fluidity::Fit,
221+
sizing: Sizing::Fit,
228222
},
229223
Length::Fill
230224
| Length::FillPortion(_)
231225
| Length::Bounded {
232-
with: Fluidity::Fill(_),
226+
sizing: Sizing::Fill(_),
233227
..
234228
},
235229
) => Length::Bounded {
236230
bounds,
237-
with: Fluidity::Fill(1),
231+
sizing: Sizing::Fill(1),
232+
},
233+
(
234+
Length::Bounded {
235+
bounds,
236+
sizing: with,
237+
},
238+
_,
239+
) => Length::Bounded {
240+
bounds,
241+
sizing: with,
238242
},
239-
(Length::Bounded { bounds, with }, _) => Length::Bounded { bounds, with },
240243

241244
// Fluid and bounded constraints must be propagated
242245
(
243246
_,
244247
Length::Bounded {
245248
bounds,
246-
with: Fluidity::Fill(_),
249+
sizing: Sizing::Fill(_),
247250
},
248251
) => Length::Fluid(bounds.constraint()),
249252
(_, Length::Fluid(constraint)) => Length::Fluid(constraint),

widget/src/table.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,11 @@ where
230230

231231
let limits = limits.width(self.width).height(self.height);
232232
let available = limits.max();
233-
let table_fluid = self.width.fluid();
233+
let table_fluid = if self.width.fill_factor() == 0 {
234+
Length::Shrink
235+
} else {
236+
Length::Fill
237+
};
234238

235239
let mut cells = Vec::with_capacity(self.cells.len());
236240
cells.resize(self.cells.len(), layout::Node::default());

0 commit comments

Comments
 (0)