Skip to main content

FloatContext

Struct FloatContext 

Source
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

Source

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.
Source

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)
  1. Float cannot be placed above cursor_y (the top of its generating box).
  2. Float cannot be placed above any previously placed float.
  3. Left float is placed as far left as possible, right float as far right as possible.
  4. If float doesn’t fit horizontally at current y, move down until it fits.
Source

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.
Source

pub fn clear(&self, clear: Clear) -> f32

Get the y position that clears floats according to the clear property.

§Arguments
  • clear - The clear value (Left, Right, Both, or None).
§Returns

The y position below the relevant floats, or 0.0 for Clear::None.

Source

pub fn clear_all(&self) -> f32

Get the y position below all floats (both left and right).

§Returns

The maximum bottom edge of all floats, or 0.0 if no floats exist.

Trait Implementations§

Source§

impl Clone for FloatContext

Source§

fn clone(&self) -> FloatContext

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FloatContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.