Skip to content

Commit

Permalink
Moved function to sync
Browse files Browse the repository at this point in the history
  • Loading branch information
jaytaph committed Dec 24, 2024
1 parent 0dc2c39 commit 9c53aca
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion crates/gosub_interface/src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub trait TreeDrawer<C: HasDrawComponents> {
layouter: C::Layouter,
// Debug flag
debug: bool,
) -> impl Future<Output = gosub_shared::types::Result<Self>>
) -> gosub_shared::types::Result<Self>
where
Self: Sized;

Expand Down
7 changes: 4 additions & 3 deletions crates/gosub_renderer/src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::debug::scale::px_scale;
use crate::draw::img::request_img;
use crate::draw::img_cache::ImageCache;
use crate::draw::testing::{test_add_element, test_restyle_element};
use crate::render_tree::{load_html_rendertree, load_html_rendertree_fetcher};
use crate::render_tree::{load_html_rendertree, load_html_rendertree_fetcher, load_html_rendertree_source};
use anyhow::anyhow;
use gosub_interface::config::{HasDrawComponents, HasHtmlParser};
use gosub_interface::css3::{CssProperty, CssPropertyMap, CssValue};
Expand Down Expand Up @@ -217,8 +217,9 @@ where
Ok(Self::new(rt, layouter, fetcher, debug))
}

async fn from_source(url: Url, source_html: &str, layouter: C::Layouter, debug: bool) -> Result<Self> {
let (rt, fetcher) = load_html_rendertree::<C>(url, Some(source_html)).await?;
fn from_source(url: Url, source_html: &str, layouter: C::Layouter, debug: bool) -> Result<Self> {
let fetcher = Fetcher::new(url.clone());
let rt = load_html_rendertree_source::<C>(url, source_html)?;

Ok(Self::new(rt, layouter, fetcher, debug))
}
Expand Down
9 changes: 6 additions & 3 deletions crates/gosub_renderer/src/render_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ pub(crate) async fn load_html_rendertree<
let fetcher = Fetcher::new(url.clone());

let rt = match source {
Some(source) => load_html_rendertree_source::<C>(url, source).await?,
Some(source) => load_html_rendertree_source::<C>(url, source)?,
None => load_html_rendertree_fetcher::<C>(url, &fetcher).await?,
};

Ok((rt, fetcher))
}

pub(crate) async fn load_html_rendertree_source<
// Generate a render tree from the given source HTML. THe URL is needed to resolve relative URLs
// and also to set the base URL for the document.
pub(crate) fn load_html_rendertree_source<
C: HasRenderTree<LayoutTree = RenderTree<C>, RenderTree = RenderTree<C>> + HasHtmlParser,
>(
url: Url,
Expand All @@ -53,6 +55,7 @@ pub(crate) async fn load_html_rendertree_source<
generate_render_tree(DocumentHandle::clone(&doc_handle))
}

/// Generates a render tree from the given URL. The complete HTML source is fetched from the URL async.
pub(crate) async fn load_html_rendertree_fetcher<
C: HasRenderTree<LayoutTree = RenderTree<C>, RenderTree = RenderTree<C>> + HasHtmlParser,
>(
Expand All @@ -73,5 +76,5 @@ pub(crate) async fn load_html_rendertree_fetcher<
bail!("Unsupported url scheme: {}", url.scheme());
};

load_html_rendertree_source(url, &html).await
load_html_rendertree_source(url, &html)
}

0 comments on commit 9c53aca

Please sign in to comment.