diff --git a/crates/gosub_css3/src/matcher/styling.rs b/crates/gosub_css3/src/matcher/styling.rs index f4b95666..0bd1bbfd 100644 --- a/crates/gosub_css3/src/matcher/styling.rs +++ b/crates/gosub_css3/src/matcher/styling.rs @@ -597,9 +597,17 @@ impl gosub_shared::traits::css3::CssProperty for CssProperty { } } - fn as_list(&self) -> Option> { + fn as_list(&self) -> Option<&[Self::Value]> { if let CssValue::List(list) = &self.actual { - Some(list.to_vec()) + Some(list) + } else { + None + } + } + + fn as_function(&self) -> Option<(&str, &[Self::Value])> { + if let CssValue::Function(name, args) = &self.actual { + Some((name.as_str(), args)) } else { None } diff --git a/crates/gosub_css3/src/stylesheet.rs b/crates/gosub_css3/src/stylesheet.rs index dd21bb65..8b0f7d9f 100644 --- a/crates/gosub_css3/src/stylesheet.rs +++ b/crates/gosub_css3/src/stylesheet.rs @@ -599,9 +599,17 @@ impl gosub_shared::traits::css3::CssValue for CssValue { } } - fn as_list(&self) -> Option> { + fn as_list(&self) -> Option<&[Self]> { if let CssValue::List(list) = &self { - Some(list.to_vec()) + Some(list) + } else { + None + } + } + + fn as_function(&self) -> Option<(&str, &[Self])> { + if let CssValue::Function(name, args) = &self { + Some((name.as_str(), args)) } else { None } diff --git a/crates/gosub_renderer/src/draw.rs b/crates/gosub_renderer/src/draw.rs index 419a2cac..ef9f0fe2 100644 --- a/crates/gosub_renderer/src/draw.rs +++ b/crates/gosub_renderer/src/draw.rs @@ -16,7 +16,7 @@ use gosub_rendering::position::PositionTree; use gosub_rendering::render_tree::{RenderNodeData, RenderTree, RenderTreeNode}; use gosub_shared::async_executor::WasmNotSend; use gosub_shared::node::NodeId; -use gosub_shared::traits::css3::{CssProperty, CssPropertyMap, CssSystem}; +use gosub_shared::traits::css3::{CssProperty, CssPropertyMap, CssSystem, CssValue}; use gosub_shared::traits::document::Document; use gosub_shared::traits::html5::Html5Parser; use gosub_shared::traits::render_tree; @@ -720,28 +720,40 @@ fn render_bg(fetcher.clone(), svg.clone(), url, size, img_cache, el) { - Ok(img) => img, - Err(e) => { - eprintln!("Error loading image: {:?}", e); - return (border_radius, None); + #[allow(clippy::collapsible_match)] + if let Some((function, args)) = background_image { + #[allow(clippy::single_match)] + match function { + "url" => { + if let Some(url) = args.first().and_then(|url| url.as_string()) { + let size = node.layout.size_or().map(|x| x.u32()); + + let img = match request_img::(fetcher.clone(), svg.clone(), url, size, img_cache, el) { + Ok(img) => img, + Err(e) => { + eprintln!("Error loading image: {:?}", e); + return (border_radius, None); + } + }; + + if size.is_none() { + img_size = Some(img.size()); + } + + let _ = + render_image::(img, *pos, node.layout.size(), border_radius, "fill", scene).map_err(|e| { + eprintln!("Error rendering image: {:?}", e); + }); + } } - }; - if size.is_none() { - img_size = Some(img.size()); + _ => {} } - - let _ = render_image::(img, *pos, node.layout.size(), border_radius, "fill", scene).map_err(|e| { - eprintln!("Error rendering image: {:?}", e); - }); } (border_radius, img_size) diff --git a/crates/gosub_shared/src/traits/css3.rs b/crates/gosub_shared/src/traits/css3.rs index a575082c..743b6e32 100644 --- a/crates/gosub_shared/src/traits/css3.rs +++ b/crates/gosub_shared/src/traits/css3.rs @@ -87,7 +87,9 @@ pub trait CssProperty: Debug + Sized + From { fn parse_color(&self) -> Option<(f32, f32, f32, f32)>; fn as_number(&self) -> Option; - fn as_list(&self) -> Option>; + fn as_list(&self) -> Option<&[Self::Value]>; + + fn as_function(&self) -> Option<(&str, &[Self::Value])>; fn is_none(&self) -> bool; } @@ -107,7 +109,9 @@ pub trait CssValue: Sized { fn as_unit(&self) -> Option<(f32, &str)>; fn as_color(&self) -> Option<(f32, f32, f32, f32)>; fn as_number(&self) -> Option; - fn as_list(&self) -> Option>; + fn as_list(&self) -> Option<&[Self]>; + + fn as_function(&self) -> Option<(&str, &[Self])>; fn is_comma(&self) -> bool; diff --git a/crates/gosub_taffy/src/compute/inline.rs b/crates/gosub_taffy/src/compute/inline.rs index f48a808b..2f15445c 100644 --- a/crates/gosub_taffy/src/compute/inline.rs +++ b/crates/gosub_taffy/src/compute/inline.rs @@ -612,12 +612,10 @@ fn parse_font_axes(n: &mut impl Node) -> Vec { }; // we don't need to care about things other than a list, since you always need two values for a variation - let Some(vars) = s.as_list() else { + let Some(mut slice) = s.as_list() else { return Vec::new(); }; - let mut slice = vars.as_slice(); - let mut vars = Vec::with_capacity((slice.len() as f32 / 3.0).ceil() as usize); loop {