How to refresh DropDown on Item property update?

I’m using custom GObject with Factory for DropDown, but after change item property (used for some Label there) - it does not apply in UI until I hover the item (e.g. on bind event)

What I forgot about, maybe some additional event listener wanted here?

Yes, every custom property added has it own event listener, so I should connect it and process according to the app implementation.

item_gobject.connect_custom_property_name(|_|{});

UPD. found alternative solution with properties bind / sync in related subject:

Not sure it’s correct, but works, here is my implementation:

// ..
factory.connect_bind(|_, this| {
    // Downcast requirements
    let list_item = this.downcast_ref::<ListItem>().unwrap();
    let item = list_item.item().and_downcast::<Item>().unwrap();
    let child = list_item.child().and_downcast::<Box>().unwrap();

    // Bind `title`
    match child.first_child().and_downcast::<Label>() {
        Some(label) => {
            // defaults
            label.set_label(&item.title());
            label.set_css_classes(if item.is_active() { &["success"] } else { &[] });

            // sync properties
            item.bind_property("title", &label, "label").build();
            item.bind_property("is-active", &label, "css-classes")
                .transform_to(|_, is_active| {
                    if is_active {
                        Some(vec!["success".to_string()])
                    } else {
                        Some(vec![])
                    }
                })
                .build();
        }
        None => todo!(),
    };

    // ..

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.