[fractal/multi-account: 22/23] Account switcher: Show hints in account entry for visible session
- From: Alejandro Domínguez <aledomu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/multi-account: 22/23] Account switcher: Show hints in account entry for visible session
- Date: Mon, 23 Aug 2021 20:29:56 +0000 (UTC)
commit 02451546302e263acb4956bb39e50f0a899db360
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 +++++++
data/resources/ui/user-entry-row.ui | 5 ++++
src/components/avatar_with_selection.rs | 31 +++++++++++++++++++++-
src/session/sidebar/account_switcher/user_entry.rs | 20 ++++++++++++++
4 files changed, 65 insertions(+), 1 deletion(-)
---
diff --git a/data/resources/style.css b/data/resources/style.css
index bb55f443..d64d966b 100644
--- a/data/resources/style.css
+++ b/data/resources/style.css
@@ -55,6 +55,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/data/resources/ui/user-entry-row.ui b/data/resources/ui/user-entry-row.ui
index 551cb454..beaed5c5 100644
--- a/data/resources/ui/user-entry-row.ui
+++ b/data/resources/ui/user-entry-row.ui
@@ -1,6 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="UserEntryRow" parent="AdwBin">
+ <binding name="active">
+ <lookup name="visible" type="GtkStackPage">
+ <lookup name="session-page">UserEntryRow</lookup>
+ </lookup>
+ </binding>
<child>
<object class="GtkBox">
<property name="spacing">10</property>
diff --git a/src/components/avatar_with_selection.rs b/src/components/avatar_with_selection.rs
index 680fb3a9..ecf47dd0 100644
--- a/src/components/avatar_with_selection.rs
+++ b/src/components/avatar_with_selection.rs
@@ -55,6 +55,13 @@ mod imp {
-1,
glib::ParamFlags::READWRITE,
),
+ glib::ParamSpec::new_boolean(
+ "selected",
+ "Selected",
+ "Style helper for the inner Avatar",
+ false,
+ glib::ParamFlags::WRITABLE,
+ ),
]
});
@@ -63,7 +70,7 @@ mod imp {
fn set_property(
&self,
- _obj: &Self::Type,
+ obj: &Self::Type,
_id: usize,
value: &glib::Value,
pspec: &glib::ParamSpec,
@@ -71,6 +78,7 @@ mod imp {
match pspec.name() {
"item" => self.child_avatar.set_item(value.get().unwrap()),
"size" => self.child_avatar.set_size(value.get().unwrap()),
+ "selected" => obj.set_selected(value.get().unwrap()),
_ => unimplemented!(),
}
}
@@ -99,6 +107,27 @@ impl AvatarWithSelection {
glib::Object::new(&[]).expect("Failed to create AvatarWithSelection")
}
+ pub fn set_selected(&self, selected: bool) {
+ let priv_ = imp::AvatarWithSelection::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::AvatarWithSelection::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 a4591350..5fa5c698 100644
--- a/src/session/sidebar/account_switcher/user_entry.rs
+++ b/src/session/sidebar/account_switcher/user_entry.rs
@@ -61,6 +61,13 @@ mod imp {
Some(""),
glib::ParamFlags::READWRITE,
),
+ glib::ParamSpec::new_boolean(
+ "active",
+ "Active",
+ "Is the active user",
+ false,
+ glib::ParamFlags::WRITABLE,
+ ),
glib::ParamSpec::new_object(
"session-page",
"Session StackPage",
@@ -94,6 +101,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);
+ }
"session-page" => {
let session_page = value.get().unwrap();
self.session_page.replace(Some(session_page));
@@ -127,6 +138,15 @@ impl UserEntryRow {
glib::Object::new(&[("session-page", session_page)]).expect("Failed to create UserEntryRow")
}
+ 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]