C++ part of element_ids

Simplify a bit the llr generation so that there is less code duplication
between Rust and C++
This commit is contained in:
Olivier Goffart 2024-05-06 17:44:20 +02:00 committed by Simon Hausmann
parent 8add2e4ebd
commit 43a336b534
8 changed files with 95 additions and 39 deletions

View file

@ -43,6 +43,23 @@ public:
return result;
}
/// Find all elements matching the given element_id.
template<typename T>
static SharedVector<ElementHandle> find_by_element_id(const ComponentHandle<T> &component,
std::string_view element_id)
{
cbindgen_private::Slice<uint8_t> element_id_view {
const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(element_id.data())),
element_id.size()
};
auto vrc = component.into_dyn();
SharedVector<ElementHandle> result;
cbindgen_private::slint_testing_element_find_by_element_id(
&vrc, &element_id_view,
reinterpret_cast<SharedVector<cbindgen_private::ItemWeak> *>(&result));
return result;
}
/// Returns true if the underlying element still exists; false otherwise.
bool is_valid() const { return private_api::upgrade_item_weak(inner).has_value(); }