Class Avatar

All Implemented Interfaces:
Accessible, Buildable, ConstraintTarget, Proxy

@Generated("org.javagi.JavaGI") public final class Avatar extends Widget implements Accessible, Buildable, ConstraintTarget

A widget displaying an image, with a generated fallback.

avatar

AdwAvatar is a widget that shows a round avatar.

AdwAvatar generates an avatar with the initials of the Avatar:text on top of a colored background.

The color is picked based on the hash of the Avatar:text.

If Avatar:show-initials is set to FALSE, Avatar:icon-name or adw-avatar-default-symbolic is shown instead of the initials.

Use Avatar:custom-image to set a custom image.

CSS nodes

AdwAvatar has a single CSS node with name avatar.

Accessibility

AdwAvatar uses the Gtk.AccessibleRole.img role.

  • Constructor Details

    • Avatar

      public Avatar(MemorySegment address)
      Create a Avatar instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • Avatar

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

      public Avatar()
      Create a new Avatar.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the Avatar class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected Avatar asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class Widget
      Returns:
      the instance as if it were its parent type
    • drawToTexture

      public Texture drawToTexture(int scaleFactor)

      Renders this Avatar into a Texture at scaleFactor.

      This can be used to export the fallback avatar.

      Parameters:
      scaleFactor - The scale factor
      Returns:
      the texture
    • getCustomImage

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

      public @Nullable String 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 @Nullable String 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 customImage)

      Sets the custom image paintable.

      Custom image is displayed instead of initials or icon.

      Parameters:
      customImage - a custom image
    • setIconName

      public void setIconName(@Nullable String iconName)

      Sets the name of an icon to use as a fallback.

      If no name is set, adw-avatar-default-symbolic will be used.

      Parameters:
      iconName - the icon name
    • setShowInitials

      public void setShowInitials(boolean showInitials)

      Sets whether to use initials instead of an icon on the fallback avatar.

      See Avatar:icon-name for how to change the fallback icon.

      Parameters:
      showInitials - 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 String text)

      Sets the text used to generate the fallback initials and color.

      It's only used to generate the color if Avatar:show-initials is FALSE.

      Parameters:
      text - the text used to get the initials and color
    • builder

      public static Avatar.Builder<? extends Avatar.Builder> builder()
      A Avatar.Builder object constructs a Avatar with the specified properties. Use the various set...() methods to set properties, and finish construction with Avatar.Builder.build().
      Returns:
      the builder object