本文へスキップ

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