Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new descendants api as well as deeper element queries to ElementHandle #5433

Merged
merged 5 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions examples/todo/rust/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,13 @@ impl SerializedState {
#[test]
fn press_add_adds_one_todo() {
i_slint_backend_testing::init_no_event_loop();
use i_slint_backend_testing::ElementHandle;
use i_slint_backend_testing::{ElementHandle, ElementQuery};
let state = init();
state.todo_model.set_vec(vec![TodoItem { checked: false, title: "first".into() }]);
let line_edit = ElementHandle::visit_elements(&state.main_window, |element| {
if element.accessible_placeholder_text().as_deref() == Some("What needs to be done?") {
std::ops::ControlFlow::Break(element)
} else {
std::ops::ControlFlow::Continue(())
}
})
.unwrap();
let line_edit = ElementQuery::from_root(&state.main_window)
.match_id("MainWindow::text-edit")
.find_first()
.unwrap();
assert_eq!(line_edit.accessible_value().unwrap(), "");
line_edit.set_accessible_value("second");

Expand Down
15 changes: 6 additions & 9 deletions internal/backends/testing/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

use crate::{ElementHandle, ElementRoot};
use core::ops::ControlFlow;
use i_slint_core::item_tree::ItemTreeRc;
use i_slint_core::slice::Slice;
use i_slint_core::{SharedString, SharedVector};
Expand All @@ -29,14 +28,12 @@ pub unsafe extern "C" fn slint_testing_element_visit_elements(
user_data: *mut c_void,
visitor: unsafe extern "C" fn(*mut c_void, &ElementHandle) -> bool,
) -> bool {
ElementHandle::visit_elements(&RootWrapper(root), |element| {
if visitor(user_data, &element) {
ControlFlow::Break(())
} else {
ControlFlow::Continue(())
}
})
.is_some()
RootWrapper(root)
.root_element()
.query_descendants()
.match_predicate(move |element| visitor(user_data, &element))
.find_first()
.is_some()
}

#[no_mangle]
Expand Down
Loading
Loading