Skip to content

Avatar

Shows an image with a fallback that appears when the image is unavailable.

Loading interactive demo…

#Import

Import avatar from quickgui.

use quickgui::*;

#Usage

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

#Anatomy

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

#API reference

Expand an entry for its description and complete signature. A dash means no declaration default is documented.

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
View source
labelpub fn label(&self) -> &Arc<str>—

Configures label for this part.

pub fn label(&self) -> &Arc<str>
View source
image_idpub fn image_id(&self) -> ElementId—

Configures image id for this part.

pub fn image_id(&self) -> ElementId
View source
fallback_idpub fn fallback_id(&self) -> ElementId—

Configures fallback id for this part.

pub fn fallback_id(&self) -> ElementId
View source
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
View source
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)
View source

Avatar::root_with

View source
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

View source
pub fn root(&self) -> Element

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

Avatar::image_with

View source
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

View source
pub fn image(&self) -> Element

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

Avatar::fallback_with

View source
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

View source
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())`.