Skip to main content

yew_virtual/core/
scroll_alignment.rs

1/// Alignment behavior when programmatically scrolling to an item.
2///
3/// Controls where the target item is positioned within the viewport
4/// after a scroll-to-index operation. This mirrors the alignment
5/// options found in TanStack Virtual.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum ScrollAlignment {
8    /// Position the item at the start of the viewport.
9    Start,
10
11    /// Position the item at the center of the viewport.
12    Center,
13
14    /// Position the item at the end of the viewport.
15    End,
16
17    /// Automatically determine the minimal scroll to make the item visible.
18    ///
19    /// If the item is already fully visible, no scroll occurs. Otherwise,
20    /// the viewport scrolls the minimum amount needed to bring the item
21    /// into view.
22    Auto,
23}
24
25impl Default for ScrollAlignment {
26    /// Returns the default scroll alignment.
27    ///
28    /// # Returns
29    ///
30    /// - `ScrollAlignment::Auto`: The default alignment behavior.
31    fn default() -> Self {
32        // Default to auto alignment for minimal scroll disruption.
33        Self::Auto
34    }
35}