跳到正文

Avatar

显示图像;图像不可用时显示后备内容。

正在加载交互演示…

#导入

从 quickgui 导入 avatar。

use quickgui::*;

#用法

avatar("user", "Ada Lovelace").size(40.0, 40.0).rounded(20.0)

#结构

  • avatar::root
  • avatar::image
  • avatar::fallback

#API 参考

展开条目查看说明和完整签名。短横线表示声明中未记录默认值。

pub fn new(root_id: impl Into<ElementId>, label: impl Into<Arc<str>>) -> Self

Declare an avatar with the accessible name assistive technology announces.

root_idpub fn root_id(&self) -> ElementId—

Configures root id for this part.

pub fn root_id(&self) -> ElementId
查看源码
labelpub fn label(&self) -> &Arc<str>—

Configures label for this part.

pub fn label(&self) -> &Arc<str>
查看源码
image_idpub fn image_id(&self) -> ElementId—

Configures image id for this part.

pub fn image_id(&self) -> ElementId
查看源码
fallback_idpub fn fallback_id(&self) -> ElementId—

Configures fallback id for this part.

pub fn fallback_id(&self) -> ElementId
查看源码
apply_loading_statuspub fn apply_loading_status<V: 'static>( view: &mut V, cx: &mut EventContext, access: &StateAccessor<V, AvatarState>, status: AvatarLoadingStatus, now: Instant, on_loading_status_change: impl FnOnce(&mut V, AvatarLoadingStatus, &mut EventContext), ) -> bool—

Apply a load status reported by the application and notify the owner exactly once. QuickGUI decodes images on a worker pool without a per-element completion event, so the application reports the status it already knows — from its own `cx.spawn` load, an [`crate::ImageResource`] loader, or a hosted renderer — and this is the `onLoadingStatusChange` counterpart: the retained status changes, the exact fallback deadline is re-armed, and `on_loading_status_change` runs only for a real transition. Returns whether the retained state changed.

pub fn apply_loading_status<V: 'static>( view: &mut V, cx: &mut EventContext, access: &StateAccessor<V, AvatarState>, status: AvatarLoadingStatus, now: Instant, on_loading_status_change: impl FnOnce(&mut V, AvatarLoadingStatus, &mut EventContext), ) -> bool
查看源码
schedulepub fn schedule<V: 'static>(cx: &mut ViewContext<'_, V>, state: &AvatarState)—

Ask for the one repaint an armed fallback deadline needs. Call this while rendering. A settled avatar requests nothing, so the window stays asleep.

pub fn schedule<V: 'static>(cx: &mut ViewContext<'_, V>, state: &AvatarState)
查看源码

Avatar::root_with

查看源码
pub fn root_with(&self, root: Element) -> Element

Decorate an application-owned root without adding layout or appearance. The root carries the whole avatar's Image role and accessible name, so swapping between the image and the fallback never changes what is announced.

Avatar::root

查看源码
pub fn root(&self) -> Element

Create the unstyled root part. Use [`Self::root_with`] to supply an existing element.

Avatar::image_with

查看源码
pub fn image_with(&self, image: Element) -> Element

Decorate the application-owned image without adding appearance. Pass a [`crate::img`] built from the caller's own source. Mount it only while [`AvatarState::shows_image`] is true; the part is hidden from assistive technology because the root already names the avatar.

Avatar::image

查看源码
pub fn image(&self) -> Element

Create the unstyled image part. Use [`Self::image_with`] to supply an existing element.

Avatar::fallback_with

查看源码
pub fn fallback_with(&self, fallback: Element) -> Element

Decorate the application-owned fallback without adding appearance. Mount it only while [`AvatarState::shows_fallback`] is true.

Avatar::fallback

查看源码
pub fn fallback(&self) -> Element

Create the unstyled fallback part. Use [`Self::fallback_with`] to supply an existing element.

pub fn avatar(id: impl Into<ElementId>, label: impl Into<Arc<str>>) -> Element

Create an unstyled avatar root. This shorthand is equivalent to `Avatar::new(id, label).root_with(div())`.