Avatar
显示图像;图像不可用时显示后备内容。
正在加载交互演示…
avatar("user", "Ada Lovelace").size(40.0, 40.0).rounded(20.0)#导入
从 quickgui 导入 avatar。
use quickgui::*;#用法
avatar("user", "Ada Lovelace").size(40.0, 40.0).rounded(20.0)#结构
avatar::rootavatar::imageavatar::fallback
#API 参考
展开条目查看说明和完整签名。短横线表示声明中未记录默认值。
Avatar
查看源码pub fn new(root_id: impl Into<ElementId>, label: impl Into<Arc<str>>) -> SelfDeclare an avatar with the accessible name assistive technology announces.
root_idpub fn root_id(&self) -> ElementId—
labelpub fn label(&self) -> &Arc<str>—
image_idpub fn image_id(&self) -> ElementId—
fallback_idpub 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) -> ElementDecorate 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) -> ElementCreate the unstyled root part. Use [`Self::root_with`] to supply an existing element.
Avatar::image_with
查看源码pub fn image_with(&self, image: Element) -> ElementDecorate 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) -> ElementCreate the unstyled image part. Use [`Self::image_with`] to supply an existing element.
Avatar::fallback_with
查看源码pub fn fallback_with(&self, fallback: Element) -> ElementDecorate the application-owned fallback without adding appearance. Mount it only while [`AvatarState::shows_fallback`] is true.
Avatar::fallback
查看源码pub fn fallback(&self) -> ElementCreate the unstyled fallback part. Use [`Self::fallback_with`] to supply an existing element.
avatar
查看源码pub fn avatar(id: impl Into<ElementId>, label: impl Into<Arc<str>>) -> ElementCreate an unstyled avatar root. This shorthand is equivalent to `Avatar::new(id, label).root_with(div())`.
