Class Avatar

All Implemented Interfaces:
PointerInterface

public class Avatar extends Widget
A widget displaying an image, with a generated fallback.

<picture>
<source srcset="avatar-dark.png" media="(prefers-color-scheme: dark)">
<img src="avatar.png" alt="avatar">
</picture>

`AdwAvatar` is a widget that shows a round avatar.

`AdwAvatar` generates an avatar with the initials of the
[property@Avatar:text] on top of a colored background.

The color is picked based on the hash of the [property@Avatar:text].

If [property@Avatar:show-initials] is set to `FALSE`,
[property@Avatar:icon-name] or `avatar-default-symbolic` is shown instead of
the initials.

Use [property@Avatar:custom-image] to set a custom image.

## CSS nodes

`AdwAvatar` has a single CSS node with name `avatar`.

https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.Avatar.html

  • Constructor Details

    • Avatar

      public Avatar(PointerContainer pointer)
    • Avatar

      public Avatar(int size, @Nullable Str text, boolean show_initials)
      Creates a new `AdwAvatar`.
      Parameters:
      size - The size of the avatar
      text - the text used to get the initials and color
      show_initials - whether to use initials instead of an icon as fallback
    • Avatar

      public Avatar(int size, String text, boolean show_initials)
      Creates a new `AdwAvatar`.
      Parameters:
      size - The size of the avatar
      text - the text used to get the initials and color
      show_initials - whether to use initials instead of an icon as fallback
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • drawToTexture

      public Texture drawToTexture(int scale_factor)
      Renders @self into a [class@Gdk.Texture] at @scale_factor.

      This can be used to export the fallback avatar.
      Parameters:
      scale_factor - The scale factor
      Returns:
      the texture
    • getCustomImage

      public Paintable getCustomImage()
      Gets the custom image paintable.
      Returns:
      the custom image
    • getIconName

      public Str getIconName()
      Gets the name of an icon to use as a fallback.
      Returns:
      the icon name
    • getShowInitials

      public boolean getShowInitials()
      Gets whether initials are used instead of an icon on the fallback avatar.
      Returns:
      whether initials are used instead of an icon as fallback
    • getSize

      public int getSize()
      Gets the size of the avatar.
      Returns:
      the size of the avatar
    • getText

      public Str getText()
      Gets the text used to generate the fallback initials and color.
      Returns:
      the text used to generate the fallback initials and color
    • setCustomImage

      public void setCustomImage(@Nullable Paintable custom_image)
      Sets the custom image paintable.

      Custom image is displayed instead of initials or icon.
      Parameters:
      custom_image - a custom image
    • setIconName

      public void setIconName(@Nullable Str icon_name)
      Sets the name of an icon to use as a fallback.

      If no name is set, `avatar-default-symbolic` will be used.
      Parameters:
      icon_name - the icon name
    • setIconName

      public void setIconName(String icon_name)
      Sets the name of an icon to use as a fallback.

      If no name is set, `avatar-default-symbolic` will be used.
      Parameters:
      icon_name - the icon name
    • setShowInitials

      public void setShowInitials(boolean show_initials)
      Sets whether to use initials instead of an icon on the fallback avatar.

      See [property@Avatar:icon-name] for how to change the fallback icon.
      Parameters:
      show_initials - whether to use initials instead of an icon as fallback
    • setSize

      public void setSize(int size)
      Sets the size of the avatar.
      Parameters:
      size - The size of the avatar
    • setText

      public void setText(@Nullable Str text)
      Sets the text used to generate the fallback initials and color.

      It's only used to generate the color if [property@Avatar:show-initials] is
      `FALSE`.
      Parameters:
      text - the text used to get the initials and color
    • setText

      public void setText(String text)
      Sets the text used to generate the fallback initials and color.

      It's only used to generate the color if [property@Avatar:show-initials] is
      `FALSE`.
      Parameters:
      text - the text used to get the initials and color
    • asAccessible

      public Accessible asAccessible()
      Implements interface Accessible. Call this to get access to interface functions.
      Overrides:
      asAccessible in class Widget
      Returns:
      Accessible
    • asBuildable

      public Buildable asBuildable()
      Implements interface Buildable. Call this to get access to interface functions.
      Overrides:
      asBuildable in class Widget
      Returns:
      Buildable
    • asConstraintTarget

      public ConstraintTarget asConstraintTarget()
      Implements interface ConstraintTarget. Call this to get access to interface functions.
      Overrides:
      asConstraintTarget in class Widget
      Returns:
      ConstraintTarget
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()