highlight active auth in dropdown list

This commit is contained in:
yggverse 2024-12-05 10:41:39 +02:00
parent 1f0ad92f11
commit ddb24c9084
3 changed files with 18 additions and 12 deletions

View File

@ -54,18 +54,21 @@ impl List {
// Downcast requirements
let list_item = this.downcast_ref::<ListItem>().unwrap();
let item = list_item.item().and_downcast::<Item>().unwrap();
let container = list_item.child().and_downcast::<Box>().unwrap();
let child = list_item.child().and_downcast::<Box>().unwrap();
// Update `title` (expected as the first child)
container
.first_child()
.unwrap()
.downcast::<Label>()
.unwrap()
.set_label(&item.title());
let title = child.first_child().unwrap().downcast::<Label>().unwrap();
if item.is_active() {
title.set_css_classes(&["success"]);
} else {
title.set_css_classes(&[]);
}
title.set_label(&item.title());
// Update `subtitle` (expected as the last child)
container
child
.last_child()
.unwrap()
.downcast::<Label>()
@ -89,10 +92,10 @@ impl List {
// Actions
/// Append new item
pub fn append(&self, value: Value, title: &str, subtitle: &str, is_selected: bool) {
let item = Item::new(value, title, subtitle);
pub fn append(&self, value: Value, title: &str, subtitle: &str, is_active: bool) {
let item = Item::new(value, title, subtitle, is_active);
self.list_store.append(&item);
if is_selected {
if is_active {
self.dropdown
.set_selected(self.list_store.find(&item).unwrap()); // @TODO panic or handle?
}

View File

@ -18,7 +18,7 @@ impl Item {
// Constructors
/// Create new `GObject`
pub fn new(value: Value, title: &str, subtitle: &str) -> Self {
pub fn new(value: Value, title: &str, subtitle: &str, is_active: bool) -> Self {
Object::builder()
.property(
"value",
@ -31,6 +31,7 @@ impl Item {
)
.property("title", title)
.property("subtitle", subtitle)
.property("is_active", is_active)
.build()
}

View File

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