Skip to content

Commit 0834734

Browse files
committed
Track whether a float context contains any floats
1 parent d2ec856 commit 0834734

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/compute/block.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ impl BlockContext<'_> {
100100
self.content_box_insets[1] = self.insets[1] + content_box_x_insets[1];
101101
}
102102

103+
/// Whether the float context contains any floats
104+
pub fn has_floats(&self) -> bool {
105+
self.bfc.float_context.has_floats()
106+
}
107+
108+
/// Whether the float context contains any floats that extend to or below min_y
109+
pub fn has_active_floats(&self, min_y: f32) -> bool {
110+
self.bfc.float_context.has_active_floats(min_y + self.y_offset)
111+
}
112+
103113
/// Position a floated box with the context
104114
pub fn place_floated_box(
105115
&mut self,

src/compute/float.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ pub struct FloatContext {
4141
/// A list of non-overlapping horizontal segments within the context.
4242
/// Each segment has the same available width for it's entire height.
4343
placer: FloatPlacer,
44+
/// Whether the float context contains any floats
45+
has_floats: bool,
4446
}
4547

4648
/// An empty "slot" that avoids floats that is suitable for non-floated content
@@ -92,9 +94,20 @@ impl FloatContext {
9294
left_floats: Vec::new(),
9395
right_floats: Vec::new(),
9496
placer: FloatPlacer::new(available_space),
97+
has_floats: false,
9598
}
9699
}
97100

101+
/// Whether the float context contains any floats
102+
pub fn has_floats(&self) -> bool {
103+
self.has_floats
104+
}
105+
106+
/// Whether the float context contains any floats that extend to or below min_y
107+
pub fn has_active_floats(&self, min_y: f32) -> bool {
108+
self.has_floats && self.placer.segment_end() > min_y
109+
}
110+
98111
/// Create a new empty `FloatContext`
99112
pub fn set_width(&mut self, available_space: AvailableSpace) {
100113
self.available_space = available_space;
@@ -136,6 +149,8 @@ impl FloatContext {
136149
// }
137150
// };
138151

152+
self.has_floats = true;
153+
139154
// Return the (x, y) coordinates of the positioned box
140155
match self.available_space {
141156
// Position won't actually be used if we're layouting under a min-content
@@ -216,13 +231,13 @@ impl Segment {
216231
struct FloatPlacer {
217232
// Calling into this
218233
bfc_width: f32,
219-
234+
/// A list of the "segments" in the float context.
220235
segments: Vec<Segment>,
221-
// Left hwm in slot 0. Right hwm in slot 1.
222-
// high_water_marks: [usize; 2],
223236
/// A closed-open range indicating which segment the last placed float
224237
/// was placed(on each side).
225238
last_placed_floats: [Range<usize>; 2],
239+
// Left hwm in slot 0. Right hwm in slot 1.
240+
// high_water_marks: [usize; 2],
226241
// left_float_high_water_mark: usize,
227242
// right_float_high_water_mark: usize,
228243
}
@@ -293,6 +308,10 @@ impl FloatPlacer {
293308
self.last_placed_floats[slot].end = self.last_placed_floats[slot].end.max(placement.end);
294309
}
295310

311+
fn segment_end(&self) -> f32 {
312+
self.segments.last().map(|seg| seg.y.end).unwrap_or(0.0)
313+
}
314+
296315
fn place_float(
297316
&mut self,
298317
min_y: f32,

0 commit comments

Comments
 (0)