pub struct Floating;Expand description
The core engine for calculating floating positions.
Floating provides methods to compute the coordinates of elements
based on their size, the trigger position, and the boundaries of
the scrollable container.
Implementations§
Source§impl Floating
impl Floating
Sourcepub async fn generate_scroll_state_from_mounted(
&self,
data: Rc<MountedData>,
) -> ScrollState
pub async fn generate_scroll_state_from_mounted( &self, data: Rc<MountedData>, ) -> ScrollState
Asynchronously captures the initial ScrollState from a mounted element.
This method is usually called once when the [ScrollableView] is first mounted or when its underlying DOM element changes. It performs multiple async JS calls to measure the layout.
Returns a default state (zeros) if the element is no longer accessible.
Sourcepub fn generate_scroll_state(&self, evt: ScrollEvent) -> ScrollState
pub fn generate_scroll_state(&self, evt: ScrollEvent) -> ScrollState
Synchronously generates a new ScrollState from a ScrollEvent.
This is a high-performance method designed to be called within the onscroll
event handler. It extracts data directly from the event without additional
JS roundtrips.
§Example
let floating = use_floating();
let mut scroll_state = use_signal(|| None);
div {
onscroll: move |evt: ScrollEvent| {
let new_state = floating.generate_scroll_state(evt);
scroll_state.set(Some(new_state));
}
}Sourcepub async fn placement_on_point(
&self,
scroll_state: ScrollState,
scrollable_ref: Rc<MountedData>,
element_ref: Rc<MountedData>,
trigger: ClientPoint,
options: FloatingOptions,
) -> (f64, f64)
pub async fn placement_on_point( &self, scroll_state: ScrollState, scrollable_ref: Rc<MountedData>, element_ref: Rc<MountedData>, trigger: ClientPoint, options: FloatingOptions, ) -> (f64, f64)
Calculates the optimal position for a floating element anchored to a specific point (e.g., a mouse click).
This method treats the input ClientPoint as a 1x1 pixel trigger. It is ideal for context menus where the anchor position is dynamic and precise.
The returned coordinates (X, Y) are relative to the viewport and are ready
for use with position: fixed and transform: translate3d.
Sourcepub async fn placement_on_trigger(
&self,
scroll_state: ScrollState,
scrollable_ref: Rc<MountedData>,
element_ref: Rc<MountedData>,
trigger_ref: Rc<MountedData>,
options: FloatingOptions,
) -> (f64, f64)
pub async fn placement_on_trigger( &self, scroll_state: ScrollState, scrollable_ref: Rc<MountedData>, element_ref: Rc<MountedData>, trigger_ref: Rc<MountedData>, options: FloatingOptions, ) -> (f64, f64)
Calculates the optimal position for a floating element anchored to another DOM element (e.g., a button).
This method measures the actual dimensions of the trigger element via get_client_rect().
It is designed for standard dropdown menus, tooltips, and popovers where
the floating element needs to align perfectly with its anchor.
The returned coordinates (X, Y) are viewport-relative.
Sourcepub fn calculate_placement(
&self,
scrollable: PixelsRect,
element: PixelsRect,
trigger: PixelsRect,
options: FloatingOptions,
) -> (f64, f64)
pub fn calculate_placement( &self, scrollable: PixelsRect, element: PixelsRect, trigger: PixelsRect, options: FloatingOptions, ) -> (f64, f64)
The main entry point for synchronous position calculation.
This method takes pre-measured rectangles and applies the full positioning pipeline: base calculation followed by middleware adjustments.
It is useful for manual calculations or when you have already obtained the necessary PixelsRect data.