Add ElementHandle::accessible_role() to the C++ API (#5388)

This commit is contained in:
Simon Hausmann 2024-06-12 21:32:25 -07:00 committed by GitHub
parent f1987cd208
commit 5247b0afae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View file

@ -11,6 +11,9 @@
# ifdef SLINT_FEATURE_EXPERIMENTAL
namespace slint::testing {
using slint::cbindgen_private::AccessibleRole;
/// Init the testing backend.
/// Should be called before any other Slint function that can access the platform.
/// Then future windows will not appear on the screen anymore
@ -205,6 +208,18 @@ public:
}
}
/// Returns the value of the element's `accessible-role` property, if present. Use this property
/// to locate elements by their type/role, i.e. buttons, checkboxes, etc.
std::optional<slint::testing::AccessibleRole> accessible_role() const
{
if (inner.element_index != 0)
return std::nullopt;
if (auto item = private_api::upgrade_item_weak(inner.item)) {
return item->item_tree.vtable()->accessible_role(item->item_tree.borrow(), item->index);
}
return std::nullopt;
}
/// Returns the accessible-label of that element, if any.
std::optional<SharedString> accessible_label() const
{