Skip to main content

Element

Trait Element 

Source
pub trait Element: Clone + Debug {
Show 13 methods // Required methods fn opaque(&self) -> OpaqueElement; fn parent(&self) -> Option<Self>; fn prev_sibling(&self) -> Option<Self>; fn next_sibling(&self) -> Option<Self>; fn first_child(&self) -> Option<Self>; fn local_name(&self) -> &str; // Provided methods fn id(&self) -> Option<&str> { ... } fn classes(&self) -> impl Iterator<Item = &str> { ... } fn attribute(&self, name: &str) -> Option<&str> { ... } fn state(&self) -> ElementState { ... } fn has_custom_state(&self, name: &str) -> bool { ... } fn is_empty(&self) -> bool { ... } fn is_root(&self) -> bool { ... }
}
Expand description

A handle to a node in the toolkit’s widget tree.

Implement this for a cheap handle type, such as &Node or an arena index paired with a reference to the arena, and the styler can match selectors against your tree. Everything except identity, tree navigation and the element name has a default that reports nothing.

Tree-structural pseudo-classes (:first-child, :nth-of-type(), :empty and friends) are answered from the navigation methods. The interactive ones come from state, and :state(name) from has_custom_state.

Required Methods§

Source

fn opaque(&self) -> OpaqueElement

A value that identifies this element and no other for as long as the tree is alive.

For a handle that is a reference, OpaqueElement::new(node) is the natural choice. For an arena index, use opaque_element_from_index.

Source

fn parent(&self) -> Option<Self>

Source

fn prev_sibling(&self) -> Option<Self>

Source

fn next_sibling(&self) -> Option<Self>

Source

fn first_child(&self) -> Option<Self>

Source

fn local_name(&self) -> &str

The name matched by a type selector, such as button.

Provided Methods§

Source

fn id(&self) -> Option<&str>

The name matched by an id selector, such as #save.

Source

fn classes(&self) -> impl Iterator<Item = &str>

The names matched by class selectors, such as .primary.

Source

fn attribute(&self, name: &str) -> Option<&str>

The value of an attribute, for [name] and [name="value"] selectors.

Source

fn state(&self) -> ElementState

Source

fn has_custom_state(&self, name: &str) -> bool

Whether the element is in the custom state name, for :state(name).

Source

fn is_empty(&self) -> bool

Whether the element matches :empty. The default is “has no children”; override it if your elements can hold text.

Source

fn is_root(&self) -> bool

Whether the element matches :root.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§