i_slint_backend_testing

Struct ElementHandle

Source
#[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

Source

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.

Source

pub fn query_descendants(&self) -> ElementQuery

Creates a new ElementQuery to match any descendants of this element.

Source

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.

Source

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 {}
    }
}
Source

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.

Source

pub fn is_valid(&self) -> bool

Returns true if the element still exists in the in UI and is valid to access; false otherwise.

Source

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");
Source

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");
Source

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"]);
Source

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.

Source

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(); }
}
Source

pub fn accessible_value(&self) -> Option<SharedString>

Returns the value of the element’s accessible-value property, if present.

Source

pub fn accessible_placeholder_text(&self) -> Option<SharedString>

Returns the value of the element’s accessible-placeholder-text property, if present.

Source

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.

Source

pub fn accessible_value_maximum(&self) -> Option<f32>

Returns the value of the element’s accessible-value-maximum property, if present.

Source

pub fn accessible_value_minimum(&self) -> Option<f32>

Returns the value of the element’s accessible-value-minimum property, if present.

Source

pub fn accessible_value_step(&self) -> Option<f32>

Returns the value of the element’s accessible-value-step property, if present.

Source

pub fn accessible_label(&self) -> Option<SharedString>

Returns the value of the accessible-label property, if present.

Source

pub fn accessible_enabled(&self) -> Option<bool>

Returns the value of the accessible-enabled property, if present

Source

pub fn accessible_description(&self) -> Option<SharedString>

Returns the value of the accessible-description property, if present

Source

pub fn accessible_checked(&self) -> Option<bool>

Returns the value of the accessible-checked property, if present

Source

pub fn accessible_checkable(&self) -> Option<bool>

Returns the value of the accessible-checkable property, if present

Source

pub fn accessible_item_selected(&self) -> Option<bool>

Returns the value of the accessible-item-selected property, if present

Source

pub fn accessible_item_selectable(&self) -> Option<bool>

Returns the value of the accessible-item-selectable property, if present

Source

pub fn accessible_item_index(&self) -> Option<usize>

Returns the value of the element’s accessible-item-index property, if present.

Source

pub fn accessible_item_count(&self) -> Option<usize>

Returns the value of the element’s accessible-item-count property, if present.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> ElementHandle

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.