Skip to main content

DomElement

Struct DomElement 

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

A DOM element.

Implementations§

Source§

impl DomElement

Source

pub fn set_attribute(&self, key: &str, value: &str)

Set an attribute on the DOM element.

Source

pub fn remove_attribute(&self, key: &str)

Remove an attribute from the DOM element.

Source§

impl DomElement

Source

pub fn value<'out>( &self, out_buffer: &'out mut [u8], ) -> Result<&'out str, InputElementGetValueError>

Get the input element’s value.

Source§

impl DomElement

Source

pub fn dialog_show_modal(&self)

Open the dialog element as a modal

TODO: Consider having more type safety to reduce the likelihood of calling this on something that isn’t a dialog. One possible idea would be to have a DialogElement type and put the show_modal and close methods on the DialogElement type and then have a way to cast between types.

Source

pub fn dialog_close(&self)

Close the dialog element as a modal

Source§

impl DomElement

Source

pub fn append_child(&self, child: &impl AsDomNode)

Append a child node to this element’s list of children.

Source§

impl DomElement

Source

pub fn maybe_new( handle: i64, component_imports: ComponentImports, ) -> Option<Self>

If the handle is 0, returns None. Otherwise, returns a DomElement.

Source

pub fn temporary_way_to_get_i64(&self) -> i64

Will be deleted once we stop using it.

Source

pub fn do_not_use_this_for_new_stuff_temporary_public_way_to_create_using_existing_i64_handle( &self, element_handle: i64, ) -> Option<Self>

Adding this because some of our older components are using older patterns and this will help with migrating them towards using this afia-component crate. DO NOT use this. It was introduced in the middle of a huge PR to help avoid needing to refctor everything at once.

Source

pub fn set_text_content(&self, text: &str)

Set the text content of this element.

Source

pub fn previous_element_sibling(&self) -> Option<DomElement>

Get this element’s previous element sibling.

§MDN Documentation

https://developer.mozilla.org/en-US/docs/Web/API/Element/previousElementSibling

Source

pub fn next_element_sibling(&self) -> Option<DomElement>

Get this element’s next element sibling.

§MDN Documentation

https://developer.mozilla.org/en-US/docs/Web/API/Element/nextElementSibling

Source

pub fn tag_name(&self) -> String

Get the element’s tag name, such as “DIV” or “SPAN”.

§MDN Documentation

https://developer.mozilla.org/en-US/docs/Web/API/Element/tagName

Source

pub fn click(&self)

Simulate a click on the element.

§MDN Documentation

https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click

Source

pub fn child_nodes(&self) -> NodeList

Get the element’s child nodes.

§MDN Documentation

https://developer.mozilla.org/en-US/docs/Web/API/Node/childNodes

Source

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

Get one of the element’s attributes.

§MDN Documentation

https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute

Source

pub fn inner_text(&self) -> String

Get the DOM element’s inner text.

§MDN Documentation

https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText

Source§

impl DomElement

Source

pub fn add_event_listener_with_callback( &self, event_name: &str, context: &'static Callback, ) -> i64

Attach an event listener to this DOM element.

TODO: We are still experimenting with event handling so we currently have multiple methods in this file for adding event listeners. We can eventually figure out our patterns, document these patterns, then delete methods that do not fit within these patterns.

Source

pub fn add_event_listener_boxed( &self, event_name: &str, callback: Box<dyn FnMut()>, ) -> i64

Attach an event listener to a DOM element.

TODO: We are still experimenting with event handling so we currently have multiple methods in this file for adding event listeners. We can eventually figure out our patterns, document these patterns, then delete methods that do not fit within these patterns.

Source§

impl DomElement

Source

pub fn get_property_string<'out>( &self, key: &str, out_buffer: &'out mut [u8], ) -> Result<&'out str, DomNodeGetPropertyStringError>

Get DOM node’s property. The property is expected to have a string value, otherwise an error is returned.

Source

pub fn get_property_bool<'out>( &self, key: &str, ) -> Result<bool, DomNodeGetPropertyBoolError>

Get DOM node’s property. The property is expected to have a bool value, otherwise an error is returned.

Source

pub fn set_property_string(&self, key: &str, value: &str)

Set DOM node’s property to a string value.

Source

pub fn set_property_bool(&self, key: &str, value: bool)

Set DOM node’s property to a boolean value.

Trait Implementations§

Source§

impl AsDomNode for DomElement

Source§

fn to_dom_node(&self) -> DomNode

Convert this type into a DomNode.
Source§

fn node_type(&self) -> NodeType

Get the Node’s type.
Source§

fn parent_node(&self) -> Option<DomNode>

Get the Node’s parent.
Source§

impl Clone for DomElement

Source§

fn clone(&self) -> DomElement

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

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, 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.