[fractal/multi-account: 14/14] Account switcher: Show hints in account entry for visible session




commit eec870fd623c8c44ee247a256f7a658d3485277e
Author: Alejandro Domínguez <adomu net-c com>
Date:   Mon Aug 16 05:41:05 2021 +0200

    Account switcher: Show hints in account entry for visible session

 data/resources/style.css                           | 10 +++++++++
 src/components/avatar_overlaid.rs                  | 24 +++++++++++++++++++++-
 src/session/sidebar/account_switcher/user_entry.rs | 24 ++++++++++++++++++++++
 3 files changed, 57 insertions(+), 1 deletion(-)
---
diff --git a/data/resources/style.css b/data/resources/style.css
index 355cf490..86a33d03 100644
--- a/data/resources/style.css
+++ b/data/resources/style.css
@@ -18,6 +18,16 @@
   background-color: alpha(@theme_bg_color, 0.2);
 }
 
+.selected-avatar avatar {
+  border: 2px solid @accent_bg_color;
+}
+
+.blue-checkmark {
+  color: @accent_bg_color;
+  border-radius: 9999px;
+  background-color: white;
+}
+
 /* Login */
 .login {
   min-width: 250px;
diff --git a/src/components/avatar_overlaid.rs b/src/components/avatar_overlaid.rs
index cf1e9257..9ed2ab22 100644
--- a/src/components/avatar_overlaid.rs
+++ b/src/components/avatar_overlaid.rs
@@ -62,13 +62,14 @@ mod imp {
 
         fn set_property(
             &self,
-            _obj: &Self::Type,
+            obj: &Self::Type,
             _id: usize,
             value: &glib::Value,
             pspec: &glib::ParamSpec,
         ) {
             match pspec.name() {
                 "size" => self.child_avatar.set_size(value.get().unwrap()),
+                "selected" => obj.set_selected(value.get().unwrap()),
                 _ => unimplemented!(),
             }
         }
@@ -96,6 +97,27 @@ impl AvatarOverlaid {
         glib::Object::new(&[]).expect("Failed to create AvatarOverlaid")
     }
 
+    pub fn set_selected(&self, selected: bool) {
+        let priv_ = imp::AvatarOverlaid::from_instance(self);
+        let checkmark = priv_.checkmark.get_or_init(|| {
+            gtk::Image::builder()
+                .halign(gtk::Align::End)
+                .valign(gtk::Align::End)
+                .icon_name("emblem-default-symbolic")
+                .pixel_size(14)
+                .css_classes(vec!["blue-checkmark".into()])
+                .build()
+        });
+
+        if selected {
+            priv_.child_avatar.add_css_class("selected-avatar");
+            priv_.checkmark_overlay.add_overlay(checkmark);
+        } else {
+            priv_.child_avatar.remove_css_class("selected-avatar");
+            priv_.checkmark_overlay.remove_overlay(checkmark);
+        }
+    }
+
     pub fn avatar(&self) -> &Avatar {
         let priv_ = imp::AvatarOverlaid::from_instance(self);
         &priv_.child_avatar
diff --git a/src/session/sidebar/account_switcher/user_entry.rs 
b/src/session/sidebar/account_switcher/user_entry.rs
index 1b477360..1331c603 100644
--- a/src/session/sidebar/account_switcher/user_entry.rs
+++ b/src/session/sidebar/account_switcher/user_entry.rs
@@ -95,6 +95,10 @@ mod imp {
                     let user_id = value.get().unwrap();
                     obj.set_user_id(user_id);
                 }
+                "active" => {
+                    let active = value.get().unwrap();
+                    obj.set_active(active);
+                }
                 _ => unimplemented!(),
             }
         }
@@ -123,6 +127,15 @@ impl UserEntryRow {
         glib::Object::new(&[]).expect("Failed to create AddAccountRow")
     }
 
+    pub fn set_active(&self, active: bool) {
+        let priv_ = imp::UserEntryRow::from_instance(self);
+
+        priv_.avatar_component.set_selected(active);
+        priv_
+            .display_name
+            .set_css_classes(if active { &["bold"] } else { &[] });
+    }
+
     pub fn set_avatar(&self, avatar_item: AvatarItem) {
         let priv_ = imp::UserEntryRow::from_instance(self);
 
@@ -147,6 +160,17 @@ impl UserEntryRow {
     pub fn bind_session_page(&self, session_page: &gtk::StackPage) {
         let priv_ = imp::UserEntryRow::from_instance(self);
 
+        let active_exp = gtk::PropertyExpression::new::<gtk::PropertyExpression>(
+            gtk::StackPage::static_type(),
+            None,
+            "visible",
+        );
+        active_exp.bind::<glib::Object>(
+            self.upcast_ref(),
+            "active",
+            Some(session_page.upcast_ref()),
+        );
+
         let session_exp = gtk::PropertyExpression::new::<gtk::PropertyExpression>(
             gtk::StackPage::static_type(),
             None,


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