#[repr(C)]pub struct ElementHandle { /* private fields */ }
Expand description
ElementHandle
wraps an existing element in a Slint UI. An ElementHandle does not keep
the corresponding element in the UI alive. Use Self::is_valid()
to verify that
it is still alive.
Obtain instances of ElementHandle
by querying your application through
Self::find_by_accessible_label()
.
Implementations§
Source§impl ElementHandle
impl ElementHandle
Sourcepub fn visit_descendants<R>(
&self,
visitor: impl FnMut(ElementHandle) -> ControlFlow<R>,
) -> Option<R>
pub fn visit_descendants<R>( &self, visitor: impl FnMut(ElementHandle) -> ControlFlow<R>, ) -> Option<R>
Visit all descendants of this element and call the visitor to each of them, until the visitor returns ControlFlow::Break
.
When the visitor breaks, the function returns the value. If it doesn’t break, the function returns None.
Sourcepub fn query_descendants(&self) -> ElementQuery
pub fn query_descendants(&self) -> ElementQuery
Creates a new ElementQuery
to match any descendants of this element.
Sourcepub fn find_by_accessible_label(
component: &impl ElementRoot,
label: &str,
) -> impl Iterator<Item = Self>
pub fn find_by_accessible_label( component: &impl ElementRoot, label: &str, ) -> impl Iterator<Item = Self>
This function searches through the entire tree of elements of component
, looks for
elements that have a accessible-label
property with the provided value label
,
and returns an iterator over the found elements.
Sourcepub fn find_by_element_id(
component: &impl ElementRoot,
id: &str,
) -> impl Iterator<Item = Self>
pub fn find_by_element_id( component: &impl ElementRoot, id: &str, ) -> impl Iterator<Item = Self>
This function searches through the entire tree of elements of this window and looks for elements by their id. The id is a qualified string consisting of the name of the component and the assigned name within the component. In the following examples, the first Button has the id “MyView::submit-button” and the second button “App::close”:
component MyView {
submit-button := Button {}
}
export component App {
VerticalLayout {
close := Button {}
}
}
Sourcepub fn find_by_element_type_name(
component: &impl ElementRoot,
type_name: &str,
) -> impl Iterator<Item = Self>
pub fn find_by_element_type_name( component: &impl ElementRoot, type_name: &str, ) -> impl Iterator<Item = Self>
This function searches through the entire tree of elements of component
, looks for
elements with given type name.
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Returns true if the element still exists in the in UI and is valid to access; false otherwise.
Sourcepub fn id(&self) -> Option<SharedString>
pub fn id(&self) -> Option<SharedString>
Returns the element’s qualified id. Returns None if the element is not valid anymore or the element does not have an id. A qualified id consists of the name of the surrounding component as well as the provided local name, separate by a double colon.
slint::slint!{
component PushButton {
/* .. */
}
export component App {
mybutton := PushButton { } // known as `App::mybutton`
PushButton { } // no id
}
}
let app = App::new().unwrap();
let button = i_slint_backend_testing::ElementHandle::find_by_element_id(&app, "App::mybutton")
.next().unwrap();
assert_eq!(button.id().unwrap(), "App::mybutton");
Sourcepub fn type_name(&self) -> Option<SharedString>
pub fn type_name(&self) -> Option<SharedString>
Returns the element’s type name; None if the element is not valid anymore.
slint::slint!{
component PushButton {
/* .. */
}
export component App {
mybutton := PushButton { }
}
}
let app = App::new().unwrap();
let button = i_slint_backend_testing::ElementHandle::find_by_element_id(&app, "App::mybutton")
.next().unwrap();
assert_eq!(button.type_name().unwrap(), "PushButton");
Sourcepub fn bases(&self) -> Option<impl Iterator<Item = SharedString>>
pub fn bases(&self) -> Option<impl Iterator<Item = SharedString>>
Returns the element’s base types as an iterator; None if the element is not valid anymore.
slint::slint!{
component ButtonBase {
/* .. */
}
component PushButton inherits ButtonBase {
/* .. */
}
export component App {
mybutton := PushButton { }
}
}
let app = App::new().unwrap();
let button = i_slint_backend_testing::ElementHandle::find_by_element_id(&app, "App::mybutton")
.next().unwrap();
assert_eq!(button.type_name().unwrap(), "PushButton");
assert_eq!(button.bases().unwrap().collect::<Vec<_>>(),
["ButtonBase"]);
Sourcepub fn accessible_role(&self) -> Option<AccessibleRole>
pub fn accessible_role(&self) -> Option<AccessibleRole>
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.
Sourcepub fn invoke_accessible_default_action(&self)
pub fn invoke_accessible_default_action(&self)
Invokes the default accessible action on the element. For example a MyButton
element might declare
an accessible default action that simulates a click, as in the following example:
component MyButton {
// ...
callback clicked();
in property <string> text;
TouchArea {
clicked => { root.clicked() }
}
accessible-role: button;
accessible-label: self.text;
accessible-action-default => { self.clicked(); }
}
Sourcepub fn accessible_value(&self) -> Option<SharedString>
pub fn accessible_value(&self) -> Option<SharedString>
Returns the value of the element’s accessible-value
property, if present.
Sourcepub fn accessible_placeholder_text(&self) -> Option<SharedString>
pub fn accessible_placeholder_text(&self) -> Option<SharedString>
Returns the value of the element’s accessible-placeholder-text
property, if present.
Sourcepub fn set_accessible_value(&self, value: impl Into<SharedString>)
pub fn set_accessible_value(&self, value: impl Into<SharedString>)
Sets the value of the element’s accessible-value
property. Note that you can only set this
property if it is declared in your Slint code.
Sourcepub fn accessible_value_maximum(&self) -> Option<f32>
pub fn accessible_value_maximum(&self) -> Option<f32>
Returns the value of the element’s accessible-value-maximum
property, if present.
Sourcepub fn accessible_value_minimum(&self) -> Option<f32>
pub fn accessible_value_minimum(&self) -> Option<f32>
Returns the value of the element’s accessible-value-minimum
property, if present.
Sourcepub fn accessible_value_step(&self) -> Option<f32>
pub fn accessible_value_step(&self) -> Option<f32>
Returns the value of the element’s accessible-value-step
property, if present.
Sourcepub fn accessible_label(&self) -> Option<SharedString>
pub fn accessible_label(&self) -> Option<SharedString>
Returns the value of the accessible-label
property, if present.
Sourcepub fn accessible_enabled(&self) -> Option<bool>
pub fn accessible_enabled(&self) -> Option<bool>
Returns the value of the accessible-enabled
property, if present
Sourcepub fn accessible_description(&self) -> Option<SharedString>
pub fn accessible_description(&self) -> Option<SharedString>
Returns the value of the accessible-description
property, if present
Sourcepub fn accessible_checked(&self) -> Option<bool>
pub fn accessible_checked(&self) -> Option<bool>
Returns the value of the accessible-checked
property, if present
Sourcepub fn accessible_checkable(&self) -> Option<bool>
pub fn accessible_checkable(&self) -> Option<bool>
Returns the value of the accessible-checkable
property, if present
Sourcepub fn accessible_item_selected(&self) -> Option<bool>
pub fn accessible_item_selected(&self) -> Option<bool>
Returns the value of the accessible-item-selected
property, if present
Sourcepub fn accessible_item_selectable(&self) -> Option<bool>
pub fn accessible_item_selectable(&self) -> Option<bool>
Returns the value of the accessible-item-selectable
property, if present
Sourcepub fn accessible_item_index(&self) -> Option<usize>
pub fn accessible_item_index(&self) -> Option<usize>
Returns the value of the element’s accessible-item-index
property, if present.
Sourcepub fn accessible_item_count(&self) -> Option<usize>
pub fn accessible_item_count(&self) -> Option<usize>
Returns the value of the element’s accessible-item-count
property, if present.
Sourcepub fn size(&self) -> LogicalSize
pub fn size(&self) -> LogicalSize
Returns the size of the element in logical pixels. This corresponds to the value of the width
and
height
properties in Slint code. Returns a zero size if the element is not valid.
Sourcepub fn absolute_position(&self) -> LogicalPosition
pub fn absolute_position(&self) -> LogicalPosition
Returns the position of the element within the entire window. This corresponds to the value of the
absolute-position
property in Slint code. Returns a zero position if the element is not valid.
Sourcepub fn computed_opacity(&self) -> f32
pub fn computed_opacity(&self) -> f32
Returns the opacity that is applied when rendering this element. This is the product of the opacity property multipled with any opacity specified by parent elements. Returns zero if the element is not valid.
Sourcepub fn invoke_accessible_increment_action(&self)
pub fn invoke_accessible_increment_action(&self)
Invokes the element’s accessible-action-increment
callback, if declared. On widgets such as spinboxes, this
typically increments the value.
Sourcepub fn invoke_accessible_decrement_action(&self)
pub fn invoke_accessible_decrement_action(&self)
Invokes the element’s accessible-action-decrement
callback, if declared. On widgets such as spinboxes, this
typically decrements the value.
Sourcepub async fn single_click(&self, button: PointerEventButton)
pub async fn single_click(&self, button: PointerEventButton)
Simulates a single click (or touch tap) on the element at its center point with the specified button.
Sourcepub async fn double_click(&self, button: PointerEventButton)
pub async fn double_click(&self, button: PointerEventButton)
Simulates a double click (or touch tap) on the element at its center point.
Trait Implementations§
Source§impl Clone for ElementHandle
impl Clone for ElementHandle
Source§fn clone(&self) -> ElementHandle
fn clone(&self) -> ElementHandle
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more