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

View file

@ -18,7 +18,7 @@ impl Item {
// Constructors // Constructors
/// Create new `GObject` /// 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() Object::builder()
.property( .property(
"value", "value",
@ -31,6 +31,7 @@ impl Item {
) )
.property("title", title) .property("title", title)
.property("subtitle", subtitle) .property("subtitle", subtitle)
.property("is_active", is_active)
.build() .build()
} }

View file

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