limn
    ↑↓ ChooseEnter OpenEsc Close
    GitHub

    Components/States

    Avatar

    A round account photo, or the initial of a name where there is no photo.

    Native componentGuide source

    Preview

    CodeSource
    fn view(state: &State, palette: ComponentPalette) -> Element {
        Avatar::new(&state.account.name, palette).render()
    }

    Examples

    Each one is the library drawing it. Press, type and hover.

    Avatar2 / 3
    CodeSource
    row(vec![
        Avatar::new("Grace Hopper", palette).image(picture(2)).size(48.0).render(),
        Avatar::new("Alan Turing", palette).image(picture(0).cover()).size(48.0).render(),
    ])
    Avatar3 / 3
    CodeSource
    row(["linus", "  margaret", "東京", ""]
        .into_iter()
        .map(|name| Avatar::new(name, palette).render())
        .collect())

    Avatar

    A round account photo, or the initial of a name where there is no photo.

    Import

    use limn::{Avatar, Component};

    Usage

    An avatar takes a name and the palette. Without a photo it draws the first character of the name, in upper case, on the palette’s selected; a name that is empty or only spaces draws ?. It reports nothing.

    fn view(state: &State, palette: ComponentPalette) -> Element {
        Avatar::new(&state.account.name, palette).render()
    }

    Photo

    Avatar::new("Ada Lovelace", palette).image(photo).render()

    image takes a RasterImage and shows it in the circle in place of the initial. The host provides a square photo; one of another shape fills the circle when it is marked .cover().

    Size

    Avatar::new("Ada Lovelace", palette).size(48.0).render()

    size is the diameter, from 16 to 256; the default is 32. The initial scales with it. A size that is not finite is ignored.

    Accessibility

    An avatar is decoration: it tells the platform nothing, because it usually stands beside the person’s name, which would be said twice. Where it stands alone, give it a node of its own:

    Avatar::new("Ada Lovelace", palette)
        .render()
        .accessible(Access::new(Role::Image).id("author-avatar").name("Ada Lovelace"))

    API reference

    The guide covers composition, options and actions. Generate the complete Rust type and builder reference from the checkout:

    cargo doc -p limn --open

    Component API overview · State and actions

    The example is drawn by crates/limn-gallery/src/pages/media.rs.