Skip to main content

ListState

Struct ListState 

Source
pub struct ListState(/* private fields */);
Expand description

重导出所有内置元素类型 列表视图必须为列表元素持有的状态。

Implementations§

Source§

impl ListState

Source

pub fn new( item_count: usize, alignment: ListAlignment, overdraw: Pixels, ) -> Self

构造一个新的列表状态,用于存储在视图上。

overdraw 参数控制可见区域上方和下方渲染的额外空间量。 此区域内的元素即使不可见也会被测量。这有助于确保 列表在滚动时不会闪烁或突然出现。

Source

pub fn measure_all(self) -> Self

设置列表在第一布局阶段测量所有项。

这对于确保滚动条大小正确(而不是仅基于已渲染元素)很有用。

Source

pub fn with_uniform_item_height(self, height: Pixels) -> Self

为每个未测量的项预填充统一的高度提示,使滚动条滑块 从第一帧开始就能正确调整大小,无需预先测量所有项。

当项实际渲染时,它们的真实高度会替换提示,因此滚动条 随时间收敛到精确大小。这是 Self::measure_all 的更廉价替代方案, 适用于项高度大致统一的列表(如表格行)。

Source

pub fn reset(&self, element_count: usize)

重置此列表状态实例。

注意这将导致滚动事件在下次绘制前被丢弃。

Source

pub fn reset_with_uniform_height(&self, element_count: usize, height: Pixels)

重置列表为 element_count 项,为每个项预填充统一的高度提示, 使滚动条滑块从第一帧开始就能正确调整大小,即使对于屏幕外的项也是如此。

Source

pub fn remeasure(&self)

重新测量所有项,同时保持比例滚动位置。

当项高度可能已更改(如字体大小更改)时使用此方法, 但项的数量和标识保持不变。

Source

pub fn remeasure_items(&self, range: Range<usize>)

range 中的项标记为需要重新测量,同时保持 当前滚动位置。与 Self::splice 不同,此方法不会 更改项的数量或清除 logical_scroll_top

当项的内容已更改且其渲染高度可能不同时使用此方法 (如流式文本、工具结果加载),但项本身仍在同一索引处。

Source

pub fn item_count(&self) -> usize

列表中的项数量。

Source

pub fn is_scrolled_to_end(&self) -> Option<bool>

列表是否已滚动到末尾,如果列表不可滚动或总内容高度尚不确定则返回 None

Source

pub fn splice(&self, old_range: Range<usize>, count: usize)

通知列表状态 old_range 中的项已被 count 个需要重新计算的新项替换。

Source

pub fn splice_focusable( &self, old_range: Range<usize>, focus_handles: impl IntoIterator<Item = Option<FocusHandle>>, )

向列表状态注册 old_range 中的项已被新项替换。 与 Self::splice 不同,此方法允许提供可选焦点句柄的迭代器 以正确集成列表中可聚焦的项。如果聚焦的项滚动到视图外, 列表将继续渲染它以允许键盘交互。

Source

pub fn set_scroll_handler( &self, handler: impl FnMut(&ListScrollEvent, &mut Window, &mut App) + 'static, )

设置列表滚动时调用的处理程序。

Source

pub fn logical_scroll_top(&self) -> ListOffset

获取当前滚动偏移量,以列表项为单位。

Source

pub fn scroll_by(&self, distance: Pixels)

按指定偏移量滚动列表

Source

pub fn scroll_to_end(&self)

将列表滚动到最末尾(超过最后一项)。

与 [scroll_to_reveal_item] 不同,此方法使用总项数作为锚点, 因此列表的布局遍历会从末尾反向进行,始终显示最后一项的底部—— 即使该项仍在增长(例如流式传输期间)。

Source

pub fn set_follow_mode(&self, mode: FollowMode)

设置列表的跟随模式。在 Tail 模式下,列表 将自动滚动到末尾,并在用户滚动回底部时重新激活。 在 Normal 模式下,不发生自动跟随。

Source

pub fn is_following_tail(&self) -> bool

返回列表当前是否正在主动跟随尾部(在每次布局时吸附到末尾)。

Source

pub fn scroll_to(&self, scroll_top: ListOffset)

将列表滚动到指定偏移量

Source

pub fn scroll_to_reveal_item(&self, ix: usize)

滚动列表以显示指定项,使其完全可见。

Source

pub fn bounds_for_item(&self, ix: usize) -> Option<Bounds<Pixels>>

获取给定项在窗口坐标中的边界(如果已渲染)。

Source

pub fn scrollbar_drag_started(&self)

当用户开始拖动滚动条时调用此方法。

这将防止报告给滚动条的高度在拖动期间发生变化, 因为 overdraw 中的项会被测量,并帮助相应地偏移滚动位置更改。

Source

pub fn scrollbar_drag_ended(&self)

当用户停止拖动滚动条时调用。

参见 scrollbar_drag_started

Source

pub fn is_scrollbar_dragging(&self) -> bool

如果滚动条当前正在被拖动则返回 true

scrollbar_drag_startedscrollbar_drag_ended 调用之间设置。 对于需要区分滚动条拖动和滚轮/触控板滚动的消费者很有用, 例如在手动定位期间抑制自动滚动行为。

Source

pub fn set_offset_from_scrollbar(&self, point: Point<Pixels>)

设置来自滚动条的偏移量

Source

pub fn max_offset_for_scrollbar(&self) -> Point<Pixels>

返回根据已测量项计算的最大滚动偏移量。 拖动期间此值保持不变,以防止滚动条意外移动。

Source

pub fn scroll_px_offset_for_scrollbar(&self) -> Point<Pixels>

返回经滚动条调整后的当前滚动偏移量。

返回的偏移量具有负 y 分量,表示 内容已滚动的距离。

Source

pub fn viewport_bounds(&self) -> Bounds<Pixels>

返回视口的像素边界。

Source

pub fn item_is_above_viewport(&self, ix: usize) -> Option<bool>

返回项是否完全在视口上方,如果列表尚未测量足够的布局则返回 None

零高度视口仍能给出确定答案:调用方可能根据此查询调整 兄弟 UI 的尺寸(可能将列表本身压缩为零高度), 因此在此情况下返回 None 会导致答案在帧间振荡。

Source

pub fn item_is_below_viewport(&self, ix: usize) -> Option<bool>

返回项是否完全在视口下方,如果列表尚未测量足够的布局则返回 None

参见 Self::item_is_above_viewport 了解为何零高度视口 仍能给出确定答案。

Trait Implementations§

Source§

impl Clone for ListState

Source§

fn clone(&self) -> ListState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ListState

Source§

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

Formats the value using the given formatter. Read more
Source§

impl ScrollbarHandle for ListState

Source§

fn offset(&self) -> Point<Pixels>

获取滚动句柄的当前偏移量。
Source§

fn set_offset(&self, offset: Point<Pixels>)

设置滚动句柄的偏移量。
Source§

fn content_size(&self) -> Size<Pixels>

内容的完整尺寸,包含内边距。
Source§

fn start_drag(&self)

开始拖动滚动条滑块时调用。
Source§

fn end_drag(&self)

结束拖动滚动条滑块时调用。

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more