Top |
GdkPixbuf * | (*HdyAvatarImageLoadFunc) () |
GtkWidget * | hdy_avatar_new () |
const gchar * | hdy_avatar_get_text () |
void | hdy_avatar_set_text () |
gboolean | hdy_avatar_get_show_initials () |
void | hdy_avatar_set_show_initials () |
void | hdy_avatar_set_image_load_func () |
gint | hdy_avatar_get_size () |
void | hdy_avatar_set_size () |
HdyAvatar is a widget to display a round avatar.
A provided image is made round before displaying, if no image is given this
widget generates a round fallback with the initials of the “text”
on top of a colord background.
The color is picked based on the hash of the “text”.
If “show-initials” is set to FALSE
, avatar-default-symbolic
is
shown in place of the initials.
Use hdy_avatar_set_image_load_func()
to set a custom image.
Create a HdyAvatarImageLoadFunc similar to this example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
static GdkPixbuf * image_load_func (gint size, gpointer user_data) { g_autoptr (GError) error = NULL; g_autoptr (GdkPixbuf) pixbuf = NULL; g_autofree gchar *file = gtk_file_chooser_get_filename ("avatar.png"); gint width, height; gdk_pixbuf_get_file_info (file, &width, &height); pixbuf = gdk_pixbuf_new_from_file_at_scale (file, (width <= height) ? size : -1, (width >= height) ? size : -1, TRUE, error); if (error != NULL) { g_critical ("Failed to create pixbuf from file: %s", error->message); return NULL; } return pixbuf; } |
GdkPixbuf * (*HdyAvatarImageLoadFunc) (gint size
,gpointer user_data
);
The returned GdkPixbuf is expected to be square with width and height set
to size
. The image is cropped to a circle without any scaling or transformation.
GtkWidget * hdy_avatar_new (gint size
,const gchar *text
,gboolean show_initials
);
Creates a new HdyAvatar.
size |
The size of the avatar |
|
text |
The text used to generate the color and initials if
|
[allow-none] |
show_initials |
whether to show the initials or the fallback icon on
top of the color generated based on |
const gchar *
hdy_avatar_get_text (HdyAvatar *self
);
Get the text used to generate the fallback initials and color
returns the text used to generate the fallback initials. This is the internal string used by the HdyAvatar, and must not be modified.
[nullable][transfer none]
void hdy_avatar_set_text (HdyAvatar *self
,const gchar *text
);
Set the text used to generate the fallback initials color
gboolean
hdy_avatar_get_show_initials (HdyAvatar *self
);
Returns whether initials are used for the fallback or the icon.
void hdy_avatar_set_show_initials (HdyAvatar *self
,gboolean show_initials
);
Sets whether the initials should be shown on the fallback avatar or the icon.
void hdy_avatar_set_image_load_func (HdyAvatar *self
,HdyAvatarImageLoadFunc load_image
,gpointer user_data
,GDestroyNotify destroy
);
A callback which is called when the custom image need to be reloaded for some reason (e.g. scale-factor changes).
“show-initials”
property“show-initials” gboolean
Whether to show the initials.
Flags: Read / Write
Default value: FALSE
“size”
property“size” gint
The avatar size of the avatar.
Flags: Read / Write
Allowed values: >= -1
Default value: -1
“text”
property“text” gchar *
The text used for the initials and for generating the color.
If “show-initials” is FALSE
it's only used to generate the color.
Flags: Read / Write
Default value: NULL