Struct Element

Source
pub struct Element { /* private fields */ }
Expand description

DOM element wrapper. See the module-level documentation also.

Implementations§

Source§

impl Element

Source

pub fn create(tag: &str) -> Result<Element>

Create a new element, it is disconnected initially from the DOM.

Source

pub fn with_parent(tag: &str, parent: &mut Element) -> Result<Element>

Create new element as child of parent.

Source

pub fn create_at(tag: &str, parent: &mut Element) -> Result<Element>

👎Deprecated since 0.5.0: please use Element::with_parent() instead.

Create new element as child of parent. Deprecated.

Source

pub fn with_text(tag: &str, text: &str) -> Result<Element>

Create new element with specified text, it is disconnected initially from the DOM.

Source

pub fn with_type(tag: &str, el_type: &str) -> Result<Element>

Create new element with specified type, which is useful for controls and widgets (initially disconnected).

Source

pub fn from_window(hwnd: HWINDOW) -> Result<Element>

Get the root DOM element of the Sciter document.

If there is no document loaded, this function will return an error.

Source

pub fn from_focus(hwnd: HWINDOW) -> Result<Element>

Get focus DOM element of the Sciter document.

If there is no such element, this function will return an error.

Source

pub fn from_highlighted(hwnd: HWINDOW) -> Result<Element>

Get highlighted element.

If there is no such element, this function will return an error.

Source

pub fn from_point(hwnd: HWINDOW, pt: POINT) -> Result<Element>

Find DOM element of the Sciter document by coordinates.

If there is no such element, this function will return an error.

Source

pub fn from_uid(hwnd: HWINDOW, uid: u32) -> Result<Element>

Get element handle by its UID.

If there is no such element, this function will return an error.

Source

pub fn as_ptr(&self) -> HELEMENT

Access element pointer.

Source

pub fn get_uid(&self) -> u32

Get element UID - identifier suitable for storage.

Source

pub fn get_tag(&self) -> String

Return element tag as string (e.g. ‘div’, ‘body’).

Source

pub fn get_text(&self) -> String

Get inner text of the element as string.

Source

pub fn set_text(&mut self, text: &str) -> Result<()>

Set inner text of the element.

Source

pub fn get_html(&self, with_outer_html: bool) -> Vec<u8>

Get html representation of the element as utf-8 bytes.

Source

pub fn set_html( &mut self, html: &[u8], how: Option<SET_ELEMENT_HTML>, ) -> Result<()>

Set inner or outer html of the element.

Source

pub fn get_value(&self) -> Value

Get value of the element.

Source

pub fn set_value<T: Into<Value>>(&mut self, val: T) -> Result<()>

Set value of the element.

Source

pub fn get_state(&self) -> ELEMENT_STATE_BITS

Checks if particular UI state bits are set in the element.

Source

pub fn set_state( &mut self, set: ELEMENT_STATE_BITS, clear: Option<ELEMENT_STATE_BITS>, update: bool, ) -> Result<()>

Set UI state of the element with optional view update.

Source

pub fn get_hwnd(&self, for_root: bool) -> HWINDOW

Get HWINDOW of containing window.

Source

pub fn attach_hwnd(&mut self, child: HWINDOW) -> Result<()>

Attach a native window to the element as a child.

Source

pub fn detach_hwnd(&mut self) -> Result<()>

Detach a child native window (if any) from the element.

Source

pub fn get_location(&self, kind: u32) -> Result<RECT>

Get bounding rectangle of the element. See the ELEMENT_AREAS enum for kind flags.

Source

pub fn request_data( &self, url: &str, data_type: RESOURCE_TYPE, initiator: Option<HELEMENT>, ) -> Result<()>

Request data download for this element.

Source

pub fn request_html(&self, url: &str, initiator: Option<HELEMENT>) -> Result<()>

Request HTML data download for this element.

Source

pub fn send_get_request(&self, url: &str) -> Result<()>

Send an asynchronous HTTP GET request for the element.

The contents of this element is replaced with the HTTP response (in text or html form).

Source

pub fn send_request( &self, url: &str, params: Option<&[(&str, &str)]>, method: Option<REQUEST_TYPE>, data_type: Option<RESOURCE_TYPE>, ) -> Result<()>

Send an HTTP GET or POST request for the element.

GET params (if any) are appended to the url to form the request.
HTTP POST params are serialized as Content-Type: application/x-www-form-urlencoded;charset=utf-8;.

Source

pub fn send_event( &self, code: BEHAVIOR_EVENTS, reason: Option<CLICK_REASON>, source: Option<HELEMENT>, ) -> Result<bool>

Sends sinking/bubbling event to the child/parent chain of the element.

Source

pub fn post_event( &self, code: BEHAVIOR_EVENTS, reason: Option<CLICK_REASON>, source: Option<HELEMENT>, ) -> Result<()>

Post asynchronously a sinking/bubbling event to the child/parent chain of the element.

Source

pub fn fire_event( &self, code: BEHAVIOR_EVENTS, reason: Option<CLICK_REASON>, source: Option<HELEMENT>, post: bool, data: Option<Value>, ) -> Result<bool>

Send or posts event to the child/parent chain of the element.

Source

pub fn fire_event_params( evt: &BEHAVIOR_EVENT_PARAMS, post: bool, ) -> Result<bool>

Send or posts event with specified params to the child/parent chain of the element.

Source

pub fn broadcast_event( &self, name: &str, post: bool, data: Option<Value>, ) -> Result<bool>

Broadcast a custom named event to all windows.

Source

pub fn eval_script(&self, script: &str) -> Result<Value>

Evaluate the given script in context of the element.

Source

pub fn call_function(&self, name: &str, args: &[Value]) -> Result<Value>

Call scripting function defined in the namespace of the element (a.k.a. global function).

You can use the make_args!(args...) macro which helps you to construct script arguments from Rust types.

Source

pub fn call_method(&self, name: &str, args: &[Value]) -> Result<Value>

Call scripting method defined for the element.

You can use the make_args!(args...) macro which helps you to construct script arguments from Rust types.

Source

pub fn call_behavior_method(&self, params: MethodParams<'_>) -> Result<()>

Call behavior specific method.

Source

pub fn attribute_count(&self) -> usize

Get number of the attributes.

Source

pub fn attribute_name(&self, index: usize) -> String

Get attribute name by its index.

Source

pub fn attribute(&self, index: usize) -> String

Get attribute value by its index.

Source

pub fn get_attribute(&self, name: &str) -> Option<String>

Get attribute value by its name.

Source

pub fn set_attribute(&mut self, name: &str, value: &str) -> Result<()>

Add or replace attribute.

Source

pub fn remove_attribute(&mut self, name: &str) -> Result<()>

Remove attribute.

Source

pub fn toggle_attribute( &mut self, name: &str, isset: bool, value: Option<&str>, ) -> Result<()>

Toggle attribute.

Source

pub fn clear_attributes(&mut self) -> Result<()>

Remove all attributes from the element.

Source

pub fn get_style_attribute(&self, name: &str) -> String

Get style attribute of the element by its name.

Source

pub fn set_style_attribute(&mut self, name: &str, value: &str) -> Result<()>

Source

pub fn index(&self) -> usize

Get index of this element in its parent collection.

Source

pub fn root(&self) -> Element

Get root of the element.

Source

pub fn parent(&self) -> Option<Element>

Get parent element.

Source

pub fn first_sibling(&self) -> Option<Element>

Get first sibling element.

Source

pub fn last_sibling(&self) -> Option<Element>

Get last sibling element.

Source

pub fn next_sibling(&self) -> Option<Element>

Get next sibling element.

Source

pub fn prev_sibling(&self) -> Option<Element>

Get previous sibling element.

Source

pub fn first_child(&self) -> Option<Element>

Get first child element.

Source

pub fn last_child(&self) -> Option<Element>

Get last child element.

Source

pub fn get(&self, index: usize) -> Option<Element>

Get element’s child at specified index.

Source

pub fn children(&self) -> Children<'_>

An iterator over the direct children of a DOM element.

Source

pub fn child(&self, index: usize) -> Option<Element>

Get element’s child at specified index.

Source

pub fn children_count(&self) -> usize

Get number of child elements.

Source

pub fn len(&self) -> usize

Get number of child elements.

Source

pub fn is_empty(&self) -> bool

Returns true is self has zero elements.

Source

pub fn clear(&mut self) -> Result<()>

Clear content of the element.

Source

pub fn clone_element(&self) -> Element

Create new element as copy of existing element.

The new element is a full (deep) copy of the element and is initially disconnected from the DOM. Note that Element.clone() does not clone the DOM element, just increments its reference count.

Source

pub fn insert(&mut self, index: usize, child: &Element) -> Result<()>

Insert element at index position of this element.

Note that we cannot follow Rust semantic here because the newly created Element is unusable before it will be inserted at DOM.

Source

pub fn append(&mut self, child: &Element) -> Result<()>

Append element as last child of this element.

Source

pub fn push(&mut self, element: Element)

Append element as last child of this element.

Source

pub fn pop(&mut self) -> Option<Element>

Remove the last child from this element and returns it, or None if this element is empty.

Source

pub fn detach(&mut self) -> Result<()>

Take element out of its container (and DOM tree).

Source

pub fn destroy(&mut self) -> Result<()>

Take element out of its container (and DOM tree) and force destruction of all behaviors.

Source

pub fn swap(&mut self, other: &mut Element) -> Result<()>

Swap element positions.

Source

pub fn test(&self, selector: &str) -> bool

Test this element against CSS selector(s).

Source

pub fn find_nearest_parent(&self, selector: &str) -> Result<Option<Element>>

Will find first parent element starting from this satisfying given css selector(s).

Source

pub fn find_first(&self, selector: &str) -> Result<Option<Element>>

Will find first element starting from this satisfying given css selector(s).

Source

pub fn find_all(&self, selector: &str) -> Result<Option<Vec<Element>>>

Will find all elements starting from this satisfying given css selector(s).

Source

pub fn update(&self, render_now: bool) -> Result<()>

Apply changes and refresh element area in its window.

Source

pub fn refresh(&self) -> Result<()>

Refresh element area in its window.

If the element has drawing behavior attached it will receive on_draw call after that.

Source

pub fn start_timer(&self, period_ms: u32, timer_id: u64) -> Result<()>

Start Timer for the element.

Element will receive on_timer events.

Note that timer events are not bubbling, so you need attach handler to the target element directly.

Source

pub fn stop_timer(&self, timer_id: u64) -> Result<()>

Stop Timer for the element.

Source

pub fn attach_handler<Handler: EventHandler>( &mut self, handler: Handler, ) -> Result<u64>

Attach the native event handler to this element.

Source

pub fn detach_handler<Handler: EventHandler>( &mut self, token: u64, ) -> Result<()>

Detach your handler from the element. Handlers identified by token from attach_handler() result.

Trait Implementations§

Source§

impl Clone for Element

Increment reference count of the dom element.

Source§

fn clone(&self) -> Self

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Element

Machine-like element visualization ({:?} and {:#?}).

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Element

Human element representation.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Element

Release element pointer.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl From<*mut _HELEMENT> for Element

Source§

fn from(he: HELEMENT) -> Self

Construct an Element object from an HELEMENT handle.

Source§

impl FromValue for Element

Get an Element object contained in the Value.

Source§

fn from_value(v: &Value) -> Option<Element>

Converts value to specified type.
Source§

impl<'a> IntoIterator for &'a Element

Allows for child in &el {} enumeration.

Source§

type Item = Element

The type of the elements being iterated over.
Source§

type IntoIter = Children<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Children<'a>

Creates an iterator from a value. Read more
Source§

impl PartialEq for Element

Source§

fn eq(&self, other: &Element) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<Element> for Value

Store the DOM element as a Value.

Since 4.4.3.26, perhaps.

Source§

type Error = SCDOM_RESULT

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

fn try_from(e: Element) -> Result<Value>

Performs the conversion.
Source§

impl Send for Element

sciter::Element can be transferred across thread boundaries.

Source§

impl StructuralPartialEq for Element

Source§

impl Sync for Element

It is safe to share sciter::Element between threads - underlaying API is thread-safe.

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.