From 3c9e88c7071be3240eaa3d07a7a7ebf6b816d02b Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Mon, 29 Jan 2024 08:58:55 -0500 Subject: [PATCH] warnings --- avenger-vega/src/image/reqwest_fetcher.rs | 6 +++ avenger-vega/src/marks/group.rs | 9 ++-- avenger-wgpu/src/marks/text.rs | 11 +---- avenger/src/marks/group.rs | 50 +++++++++++++++++------ 4 files changed, 51 insertions(+), 25 deletions(-) diff --git a/avenger-vega/src/image/reqwest_fetcher.rs b/avenger-vega/src/image/reqwest_fetcher.rs index 5ea77da..83a471c 100644 --- a/avenger-vega/src/image/reqwest_fetcher.rs +++ b/avenger-vega/src/image/reqwest_fetcher.rs @@ -7,6 +7,12 @@ pub struct ReqwestImageFetcher { client: Client, } +impl Default for ReqwestImageFetcher { + fn default() -> Self { + Self::new() + } +} + impl ReqwestImageFetcher { pub fn new() -> Self { Self { diff --git a/avenger-vega/src/marks/group.rs b/avenger-vega/src/marks/group.rs index 93fe74f..4583259 100644 --- a/avenger-vega/src/marks/group.rs +++ b/avenger-vega/src/marks/group.rs @@ -1,10 +1,10 @@ use crate::error::VegaSceneGraphError; use crate::marks::mark::{VegaMark, VegaMarkItem}; +use crate::marks::values::CssColorOrGradient; use avenger::marks::group::{GroupBounds, SceneGroup}; use avenger::marks::mark::SceneMark; +use avenger::marks::value::Gradient; use serde::{Deserialize, Serialize}; -use avenger::marks::value::{Gradient}; -use crate::marks::values::CssColorOrGradient; #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct VegaGroupItem { @@ -91,7 +91,10 @@ impl VegaGroupItem { }; Ok(SceneGroup { - name: self.name.clone().unwrap_or_else(|| "group_item".to_string()), + name: self + .name + .clone() + .unwrap_or_else(|| "group_item".to_string()), bounds: GroupBounds { x: self.x, y: self.y, diff --git a/avenger-wgpu/src/marks/text.rs b/avenger-wgpu/src/marks/text.rs index 02cda36..a4cd5bc 100644 --- a/avenger-wgpu/src/marks/text.rs +++ b/avenger-wgpu/src/marks/text.rs @@ -3,7 +3,7 @@ use avenger::marks::group::GroupBounds; use avenger::marks::text::{ FontStyleSpec, FontWeightNameSpec, FontWeightSpec, TextAlignSpec, TextBaselineSpec, TextMark, }; -use glyphon::fontdb::Database; + use glyphon::{ Attrs, Buffer, Color, ColorMode, Family, FontSystem, Metrics, Resolution, Shaping, SwashCache, TextArea, TextAtlas, TextBounds, TextRenderer, Weight, @@ -23,16 +23,9 @@ lazy_static! { fn build_font_system() -> FontSystem { let mut font_system = FontSystem::new(); - let swash_cache = SwashCache::new(); - - let serif_family = Family::Serif; - let sans_serif_family = Family::SansSerif; - let cursive_family = Family::Cursive; - let fantasy_family = Family::Fantasy; - let monospace_family = Family::Monospace; // Override default families based on what system fonts are available - let mut fontdb = font_system.db_mut(); + let fontdb = font_system.db_mut(); let families: HashSet = fontdb .faces() .flat_map(|face| { diff --git a/avenger/src/marks/group.rs b/avenger/src/marks/group.rs index 481b99b..b09d2d7 100644 --- a/avenger/src/marks/group.rs +++ b/avenger/src/marks/group.rs @@ -1,7 +1,7 @@ use crate::marks::mark::SceneMark; -use serde::{Deserialize, Serialize}; use crate::marks::rect::RectMark; use crate::marks::value::{ColorOrGradient, EncodingValue, Gradient}; +use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Copy, Serialize, Deserialize)] pub struct GroupBounds { @@ -38,14 +38,16 @@ pub struct SceneGroup { impl SceneGroup { pub fn make_rect(&self) -> Option { if self.fill.is_none() && self.stroke.is_none() { - return None + return None; } - let stroke_width = self.stroke_width.unwrap_or(if self.stroke.is_some() { 1.0 } else { 0.0 }); + let stroke_width = + self.stroke_width + .unwrap_or(if self.stroke.is_some() { 1.0 } else { 0.0 }); let stroke_offset = if let Some(stroke_offset) = self.stroke_offset { stroke_offset } else { // From Vega's default stroke offset logic - if (self.stroke.is_some() && stroke_width > 0.5 && stroke_width < 1.5) { + if self.stroke.is_some() && stroke_width > 0.5 && stroke_width < 1.5 { 0.5 - (stroke_width - 1.0).abs() } else { 0.0 @@ -56,15 +58,37 @@ impl SceneGroup { clip: false, len: 1, gradients: self.gradients.clone(), - x: EncodingValue::Scalar { value: self.bounds.x + stroke_offset }, - y: EncodingValue::Scalar { value: self.bounds.y + stroke_offset }, - width: EncodingValue::Scalar { value: self.bounds.width.unwrap_or(0.0) }, - height: EncodingValue::Scalar { value: self.bounds.height.unwrap_or(0.0) }, - fill: EncodingValue::Scalar {value: self.fill.clone().unwrap_or(ColorOrGradient::Color([0.0, 0.0, 0.0, 0.0]))}, - stroke: EncodingValue::Scalar {value: self.stroke.clone().unwrap_or(ColorOrGradient::Color([0.0, 0.0, 0.0, 0.0]))}, - stroke_width: EncodingValue::Scalar { value: stroke_width }, - corner_radius: EncodingValue::Scalar { value: self.corner_radius.unwrap_or(0.0) }, + x: EncodingValue::Scalar { + value: self.bounds.x + stroke_offset, + }, + y: EncodingValue::Scalar { + value: self.bounds.y + stroke_offset, + }, + width: EncodingValue::Scalar { + value: self.bounds.width.unwrap_or(0.0), + }, + height: EncodingValue::Scalar { + value: self.bounds.height.unwrap_or(0.0), + }, + fill: EncodingValue::Scalar { + value: self + .fill + .clone() + .unwrap_or(ColorOrGradient::Color([0.0, 0.0, 0.0, 0.0])), + }, + stroke: EncodingValue::Scalar { + value: self + .stroke + .clone() + .unwrap_or(ColorOrGradient::Color([0.0, 0.0, 0.0, 0.0])), + }, + stroke_width: EncodingValue::Scalar { + value: stroke_width, + }, + corner_radius: EncodingValue::Scalar { + value: self.corner_radius.unwrap_or(0.0), + }, indices: None, }) } -} \ No newline at end of file +}