show identity details as dropdown item tooltip

This commit is contained in:
yggverse 2024-12-05 12:50:49 +02:00
parent 763c59ed4f
commit cb08217ffa
4 changed files with 72 additions and 23 deletions

View file

@ -63,12 +63,10 @@ impl List {
title.set_css_classes(if item.is_active() { &["success"] } else { &[] });
// Update `subtitle` (expected as the last child)
child
.last_child()
.unwrap()
.downcast::<Label>()
.unwrap()
.set_label(&item.subtitle());
let subtitle = child.last_child().unwrap().downcast::<Label>().unwrap();
subtitle.set_label(&item.subtitle());
subtitle.set_tooltip_text(Some(&item.tooltip()));
});
// Init main `DropDown`
@ -87,9 +85,18 @@ impl List {
// Actions
/// Append new item
pub fn append(&self, value: Value, title: &str, subtitle: &str, is_active: bool) {
let item = Item::new(value, title, subtitle, is_active);
pub fn append(
&self,
value: Value,
title: &str,
subtitle: &str,
tooltip: Option<&str>,
is_active: bool,
) {
let item = Item::new(value, title, subtitle, tooltip, is_active);
self.list_store.append(&item);
if is_active {
self.dropdown
.set_selected(self.list_store.find(&item).unwrap()); // @TODO panic or handle?

View file

@ -18,7 +18,13 @@ impl Item {
// Constructors
/// Create new `GObject`
pub fn new(value: Value, title: &str, subtitle: &str, is_active: bool) -> Self {
pub fn new(
value: Value,
title: &str,
subtitle: &str,
tooltip: Option<&str>,
is_active: bool,
) -> Self {
Object::builder()
.property(
"value",
@ -31,6 +37,13 @@ impl Item {
)
.property("title", title)
.property("subtitle", subtitle)
.property(
"tooltip",
match tooltip {
Some(text) => text,
None => "", // NULL
},
)
.property("is_active", is_active)
.build()
}

View file

@ -18,6 +18,8 @@ pub struct Item {
#[property(get, set)]
subtitle: RefCell<String>,
#[property(get, set)]
tooltip: RefCell<String>,
#[property(get, set)]
is_active: Cell<bool>,
}