[gnome-maps] placeBubble: Use HdyAvatar for contact bubbles



commit 0976198ca944782431c2ec978148c4b3a7429ab9
Author: James Westman <james flyingpimonster net>
Date:   Wed Aug 5 21:09:40 2020 -0500

    placeBubble: Use HdyAvatar for contact bubbles
    
    HdyAvatar has a number of benefits, like circular icons (to match the rest of
    the system) and a nice-looking fallback with the person's initials.

 data/ui/place-bubble.ui | 18 +++++++++++++++---
 src/placeBubble.js      | 30 ++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 3 deletions(-)
---
diff --git a/data/ui/place-bubble.ui b/data/ui/place-bubble.ui
index ccb899fe..7dce2836 100644
--- a/data/ui/place-bubble.ui
+++ b/data/ui/place-bubble.ui
@@ -15,6 +15,18 @@
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="column-spacing">5</property>
+        <child>
+          <object class="HdyAvatar" id="contact-avatar">
+            <property name="visible">False</property>
+            <property name="can_focus">False</property>
+            <property name="show_initials">True</property>
+            <property name="size">32</property>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">0</property>
+          </packing>
+        </child>
         <child>
           <object class="GtkBox">
             <property name="visible">True</property>
@@ -54,7 +66,7 @@
             </child>
           </object>
           <packing>
-            <property name="left-attach">0</property>
+            <property name="left-attach">1</property>
             <property name="top-attach">0</property>
           </packing>
         </child>
@@ -68,7 +80,7 @@
             </style>
           </object>
           <packing>
-            <property name="left-attach">0</property>
+            <property name="left-attach">1</property>
             <property name="top-attach">1</property>
           </packing>
         </child>
@@ -93,7 +105,7 @@
             </child>
           </object>
           <packing>
-            <property name="left-attach">0</property>
+            <property name="left-attach">1</property>
             <property name="top-attach">2</property>
           </packing>
         </child>
diff --git a/src/placeBubble.js b/src/placeBubble.js
index 645cf66b..4e604ca2 100644
--- a/src/placeBubble.js
+++ b/src/placeBubble.js
@@ -56,6 +56,7 @@ var PlaceBubble = GObject.registerClass({
         let ui = Utils.getUIObject('place-bubble', [ 'stack',
                                                      'box-content',
                                                      'grid-content',
+                                                     'contact-avatar',
                                                      'label-title',
                                                      'expand-button',
                                                      'expanded-content',
@@ -78,6 +79,15 @@ var PlaceBubble = GObject.registerClass({
         this._expandButton = ui.expandButton;
         this._expandedContent = ui.expandedContent;
         this._revealer = ui.contentRevealer;
+        this._contactAvatar = ui.contactAvatar;
+
+        /* Set up contact avatar */
+        if (this.place instanceof ContactPlace.ContactPlace) {
+            this._contactAvatar.visible = true;
+            Utils.load_icon(this.place.icon, 32, (pixbuf) => {
+                this._contactAvatar.set_image_load_func(this._avatarImageLoadFunc.bind(this, pixbuf));
+            });
+        }
 
         let overpass = new Overpass.Overpass();
 
@@ -252,6 +262,8 @@ var PlaceBubble = GObject.registerClass({
 
         this._attachContent(content, expandedContent);
 
+        this._contactAvatar.text = formatter.title;
+
         let title = GLib.markup_escape_text(formatter.title, -1);
         if (place.website) {
             let uri = GLib.markup_escape_text(place.website, -1);
@@ -309,4 +321,22 @@ var PlaceBubble = GObject.registerClass({
             this._revealer.reveal_child = !this._revealer.child_revealed;
         }).bind(this));
     }
+
+    // Loads the HdyAvatar image for contact places
+    _avatarImageLoadFunc(pixbuf, size) {
+        let width = pixbuf.get_width();
+        let height = pixbuf.get_height();
+        let croppedThumbnail;
+
+        if (width > height) {
+            let x = (width - height) / 2;
+            croppedThumbnail = pixbuf.new_subpixbuf(x, 0, height, height);
+        } else {
+            let y = (height - width) / 2;
+            croppedThumbnail = pixbuf.new_subpixbuf(0, y, width, width);
+        }
+
+        return croppedThumbnail.scale_simple(size, size, GdkPixbuf.InterpType.BILINEAR);
+    }
+
 });


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]