DioxusDocument

Struct DioxusDocument 

Source
pub struct DioxusDocument {
    pub inner: BaseDocument,
    pub vdom: VirtualDom,
    pub vdom_state: DioxusState,
    /* private fields */
}
Expand description

Integrates BaseDocument from blitz-dom with VirtualDom from dioxus-core

§Example

use blitz_traits::shell::{Viewport, ColorScheme};
use dioxus_native_dom::{DioxusDocument, DocumentConfig};
use dioxus::prelude::*;

// Example Dioxus app
fn app() -> Element {
    rsx! {
        div { "Hello, world!" }
    }
}

fn main() {
   let vdom = VirtualDom::new(app);
   let mut doc = DioxusDocument::new(vdom, DocumentConfig {
        viewport: Some(Viewport::new(800, 600, 1.0, ColorScheme::Light)),
        ..Default::default()
   });
   doc.initial_build();
}

You can just push events into the DioxusDocument with doc.handle_ui_event(..) and then flush the changes with doc.poll(..)

Fields§

§inner: BaseDocument§vdom: VirtualDom§vdom_state: DioxusState

Implementations§

Source§

impl DioxusDocument

Source

pub fn new(vdom: VirtualDom, config: DocumentConfig) -> DioxusDocument

Create a new DioxusDocument from a VirtualDom.

Source

pub fn initial_build(&mut self)

Run an initial build of the Dioxus vdom

Methods from Deref<Target = BaseDocument>§

Source

pub fn set_net_provider(&mut self, net_provider: Arc<dyn NetProvider<Resource>>)

Set the Document’s networking provider

Source

pub fn set_navigation_provider( &mut self, navigation_provider: Arc<dyn NavigationProvider>, )

Set the Document’s navigation provider

Source

pub fn set_shell_provider(&mut self, shell_provider: Arc<dyn ShellProvider>)

Set the Document’s shell provider

Source

pub fn set_html_parser_provider( &mut self, html_parser_provider: Arc<dyn HtmlParserProvider>, )

Set the Document’s html parser provider

Source

pub fn set_base_url(&mut self, url: &str)

Set base url for resolving linked resources (stylesheets, images, fonts, etc)

Source

pub fn guard(&self) -> &SharedRwLock

Source

pub fn tree(&self) -> &Slab<Node>

Source

pub fn id(&self) -> usize

Source

pub fn get_node(&self, node_id: usize) -> Option<&Node>

Source

pub fn get_node_mut(&mut self, node_id: usize) -> Option<&mut Node>

Source

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

Source

pub fn mutate<'doc>(&'doc mut self) -> DocumentMutator<'doc>

Source

pub fn handle_dom_event<F>(&mut self, event: &mut DomEvent, dispatch_event: F)
where F: FnMut(DomEvent),

Source

pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Source

pub fn label_bound_input_element(&self, label_node_id: usize) -> Option<&Node>

Find the label’s bound input elements: the element id referenced by the “for” attribute of a given label element or the first input element which is nested in the label Note that although there should only be one bound element, we return all possibilities instead of just the first in order to allow the caller to decide which one is correct

Source

pub fn toggle_radio(&mut self, radio_set_name: String, target_radio_id: usize)

Source

pub fn set_style_property(&mut self, node_id: usize, name: &str, value: &str)

Source

pub fn remove_style_property(&mut self, node_id: usize, name: &str)

Source

pub fn root_node(&self) -> &Node

Source

pub fn root_node_mut(&mut self) -> &mut Node

Source

pub fn try_root_element(&self) -> Option<&Node>

Source

pub fn root_element(&self) -> &Node

Source

pub fn create_node(&mut self, node_data: NodeData) -> usize

Source

pub fn has_changes(&self) -> bool

Whether the document has been mutated

Source

pub fn create_text_node(&mut self, text: &str) -> usize

Source

pub fn deep_clone_node(&mut self, node_id: usize) -> usize

Source

pub fn print_tree(&self)

Source

pub fn print_subtree(&self, node_id: usize)

Source

pub fn reload_resource_by_href(&mut self, href_to_reload: &str)

Source

pub fn process_style_element(&mut self, target_id: usize)

Source

pub fn remove_user_agent_stylesheet(&mut self, contents: &str)

Source

pub fn add_user_agent_stylesheet(&mut self, css: &str)

Source

pub fn make_stylesheet( &self, css: impl AsRef<str>, origin: Origin, ) -> DocumentStyleSheet

Source

pub fn upsert_stylesheet_for_node(&mut self, node_id: usize)

Source

pub fn add_stylesheet_for_node( &mut self, stylesheet: DocumentStyleSheet, node_id: usize, )

Source

pub fn load_resource(&mut self, resource: Resource)

Source

pub fn snapshot_node(&mut self, node_id: usize)

Source

pub fn snapshot_node_and(&mut self, node_id: usize, cb: impl FnOnce(&mut Node))

Source

pub fn resolve(&mut self, current_time_for_animations: f64)

Restyle the tree and then relayout it

Source

pub fn hit(&self, x: f32, y: f32) -> Option<HitResult>

Source

pub fn focus_next_node(&mut self) -> Option<usize>

Source

pub fn clear_focus(&mut self)

Clear the focussed node

Source

pub fn set_mousedown_node_id(&mut self, node_id: Option<usize>)

Source

pub fn set_focus_to(&mut self, focus_node_id: usize) -> bool

Source

pub fn active_node(&mut self) -> bool

Source

pub fn unactive_node(&mut self) -> bool

Source

pub fn set_hover_to(&mut self, x: f32, y: f32) -> bool

Source

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

Source

pub fn set_viewport(&mut self, viewport: Viewport)

Source

pub fn viewport(&self) -> &Viewport

Source

pub fn viewport_mut(&mut self) -> ViewportMut<'_>

Source

pub fn zoom_by(&mut self, increment: f32)

Source

pub fn zoom_to(&mut self, zoom: f32)

Source

pub fn get_viewport(&self) -> Viewport

Source

pub fn devtools(&self) -> &DevtoolSettings

Source

pub fn devtools_mut(&mut self) -> &mut DevtoolSettings

Source

pub fn is_animating(&self) -> bool

Source

pub fn set_stylist_device(&mut self, device: Device)

Update the device and reset the stylist to process the new size

Source

pub fn stylist_device(&mut self) -> &Device

Source

pub fn resolve_layout_children(&mut self)

Ensure that the layout_children field is populated for all nodes

Source

pub fn resolve_deferred_tasks(&mut self)

Source

pub fn resolve_layout(&mut self)

Walk the nodes now that they’re properly styled and transfer their styles to the taffy style system

TODO: update taffy to use an associated type instead of slab key TODO: update taffy to support traited styles so we don’t even need to rely on taffy for storage

Source

pub fn get_cursor(&self) -> Option<CursorIcon>

Source

pub fn scroll_node_by(&mut self, node_id: usize, x: f64, y: f64)

Source

pub fn scroll_node_by_has_changed( &mut self, node_id: usize, x: f64, y: f64, ) -> bool

Scroll a node by given x and y Will bubble scrolling up to parent node once it can no longer scroll further If we’re already at the root node, bubbles scrolling up to the viewport

Source

pub fn scroll_viewport_by(&mut self, x: f64, y: f64)

Source

pub fn scroll_viewport_by_has_changed(&mut self, x: f64, y: f64) -> bool

Scroll the viewport by the given values

Source

pub fn viewport_scroll(&self) -> Point<f64>

Source

pub fn set_viewport_scroll(&mut self, scroll: Point<f64>)

Source

pub fn find_title_node(&self) -> Option<&Node>

Source

pub fn print_taffy_tree(&self)

Source

pub fn debug_log_node(&self, node_id: usize)

Source

pub fn reset_form_owner(&mut self, node_id: usize)

Resets the form owner for a given node by either using an explicit form attribute or finding the nearest ancestor form element

§Arguments
  • node_id - The ID of the node whose form owner needs to be reset

https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#reset-the-form-owner

Source

pub fn submit_form(&self, node_id: usize, submitter_id: usize)

Submits a form with the given form node ID and submitter node ID

§Arguments
  • node_id - The ID of the form node to submit
  • submitter_id - The ID of the node that triggered the submission

https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#form-submission-algorithm

Source

pub fn flush_styles_to_layout(&mut self, node_id: usize)

Walk the whole tree, converting styles to layout

Source

pub fn get_element_by_id(&self, id: &str) -> Option<usize>

Find the node with the specified id attribute (if one exists)

Source

pub fn query_selector<'input>( &self, selector: &'input str, ) -> Result<Option<usize>, ParseError<'input, StyleParseErrorKind<'input>>>

Find the first node that matches the selector specified as a string Returns:

  • Err(_) if parsing the selector fails
  • Ok(None) if nothing matches
  • Ok(Some(node_id)) with the first node ID that matches if one is found
Source

pub fn query_selector_raw( &self, selector_list: &SelectorList<SelectorImpl>, ) -> Option<usize>

Find the first node that matches the selector(s) specified in selector_list

Source

pub fn query_selector_all<'input>( &self, selector: &'input str, ) -> Result<SmallVec<[usize; 32]>, ParseError<'input, StyleParseErrorKind<'input>>>

Find all nodes that match the selector specified as a string Returns:

  • Err(_) if parsing the selector fails
  • Ok(SmallVec<usize>) with all matching nodes otherwise
Source

pub fn query_selector_all_raw( &self, selector_list: &SelectorList<SelectorImpl>, ) -> SmallVec<[usize; 32]>

Find all nodes that match the selector(s) specified in selector_list

Source

pub fn try_parse_selector_list<'input>( &self, input: &'input str, ) -> Result<SelectorList<SelectorImpl>, ParseError<'input, StyleParseErrorKind<'input>>>

Source

pub fn resolve_stylist(&mut self, now: f64)

Source

pub fn node_chain(&self, node_id: usize) -> Vec<usize>

Collect the nodes into a chain by traversing upwards

Source

pub fn visit<F>(&self, visit: F)
where F: FnMut(usize, &Node),

Source

pub fn non_anon_ancestor_if_anon(&self, node_id: usize) -> usize

If the node is non-anonymous then returns the node’s id Else find’s the first non-anonymous ancester of the node

Source

pub fn iter_children_mut( &mut self, node_id: usize, cb: impl FnMut(usize, &mut BaseDocument), )

Source

pub fn iter_subtree_mut( &mut self, node_id: usize, cb: impl FnMut(usize, &mut BaseDocument), )

Source

pub fn iter_children_and_pseudos_mut( &mut self, node_id: usize, cb: impl FnMut(usize, &mut BaseDocument), )

Source

pub fn next_node( &self, start: &Node, filter: impl FnMut(&Node) -> bool, ) -> Option<usize>

Source

pub fn node_layout_ancestors(&self, node_id: usize) -> Vec<usize>

Source

pub fn maybe_node_layout_ancestors(&self, node_id: Option<usize>) -> Vec<usize>

Source

pub fn build_accessibility_tree(&self) -> TreeUpdate

Trait Implementations§

Source§

impl Deref for DioxusDocument

Source§

type Target = BaseDocument

The resulting type after dereferencing.
Source§

fn deref(&self) -> &BaseDocument

Dereferences the value.
Source§

impl DerefMut for DioxusDocument

Source§

fn deref_mut(&mut self) -> &mut <DioxusDocument as Deref>::Target

Mutably dereferences the value.
Source§

impl Document for DioxusDocument

Source§

fn id(&self) -> usize

Get the Document’s id
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Source§

fn poll(&mut self, cx: Option<Context<'_>>) -> bool

Poll any pending async operations, and flush changes to the underlying BaseDocument
Source§

fn handle_ui_event(&mut self, event: UiEvent)

Update the Document in response to a UiEvent (click, keypress, etc)
Source§

impl From<DioxusDocument> for BaseDocument

Source§

fn from(doc: DioxusDocument) -> BaseDocument

Converts to this type from the input type.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> InitializeFromFunction<T> for T

Source§

fn initialize_from_function(f: fn() -> T) -> T

Create an instance of this type from an initialization function
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> MaybeBoxed<Box<T>> for T

Source§

fn maybe_boxed(self) -> Box<T>

Convert
Source§

impl<T> MaybeBoxed<T> for T

Source§

fn maybe_boxed(self) -> T

Convert
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<Ret> SpawnIfAsync<(), Ret> for Ret

Source§

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
Source§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

Source§

fn super_from(input: T) -> O

Convert from a type to another type.
Source§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

Source§

fn super_into(self) -> O

Convert from a type to another type.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,