pub struct FloatContext { /* private fields */ }Expand description
Tracks placed floats and provides exclusion zone queries.
FloatContext maintains separate lists of left and right floats and computes available space for content that flows around them.
Implementations§
Source§impl FloatContext
impl FloatContext
Sourcepub fn new(containing_width: f32) -> Self
pub fn new(containing_width: f32) -> Self
Create a new float context for a containing block.
§Arguments
containing_width- The width of the containing block in pixels.
Sourcepub fn place_float(
&mut self,
fragment: Fragment,
float_type: Float,
cursor_y: f32,
) -> Fragment
pub fn place_float( &mut self, fragment: Fragment, float_type: Float, cursor_y: f32, ) -> Fragment
Place a float left or right, below any existing floats that would overlap.
§Arguments
fragment- The fragment to float (will be mutated with position).float_type- Whether to float left or right.cursor_y- The vertical position of the generating box (float cannot be placed above this).
§Returns
The fragment with its position field updated to the final placement.
§Algorithm (per CSS 2.1 §9.5.1)
- Float cannot be placed above cursor_y (the top of its generating box).
- Float cannot be placed above any previously placed float.
- Left float is placed as far left as possible, right float as far right as possible.
- If float doesn’t fit horizontally at current y, move down until it fits.
Sourcepub fn available_width_at(&self, y: f32, height: f32) -> (f32, f32)
pub fn available_width_at(&self, y: f32, height: f32) -> (f32, f32)
Get available width at a vertical position accounting for float exclusions.
§Arguments
y- Vertical position to query.height- Height of the content being placed (to check overlap).
§Returns
A tuple of (left_offset, available_width):
left_offset: The x-coordinate where content can start.available_width: The width available for content.
Trait Implementations§
Source§impl Clone for FloatContext
impl Clone for FloatContext
Source§fn clone(&self) -> FloatContext
fn clone(&self) -> FloatContext
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for FloatContext
impl RefUnwindSafe for FloatContext
impl Send for FloatContext
impl Sync for FloatContext
impl Unpin for FloatContext
impl UnwindSafe for FloatContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more