Ran cargo_fmt over changed files.
This commit is contained in:
		
							parent
							
								
									a88aae5e04
								
							
						
					
					
						commit
						5696afcadd
					
				| @ -1,8 +1,12 @@ | |||||||
| //! Display an icon.
 | //! Display an icon.
 | ||||||
| use crate::{layout, Element, Hasher, Layout, Length, Point, Rectangle, Widget}; | use crate::{ | ||||||
|  |     layout, Element, Hasher, Layout, Length, Point, Rectangle, Widget, | ||||||
|  | }; | ||||||
| 
 | 
 | ||||||
| use std::hash::Hash; | use std::{ | ||||||
| use std::path::{Path, PathBuf}; |     hash::Hash, | ||||||
|  |     path::{Path, PathBuf}, | ||||||
|  | }; | ||||||
| 
 | 
 | ||||||
| /// A simple icon_loader widget.
 | /// A simple icon_loader widget.
 | ||||||
| #[derive(Debug, Clone)] | #[derive(Debug, Clone)] | ||||||
| @ -63,10 +67,7 @@ where | |||||||
|     ) -> Renderer::Output { |     ) -> Renderer::Output { | ||||||
|         let bounds = layout.bounds(); |         let bounds = layout.bounds(); | ||||||
| 
 | 
 | ||||||
|         renderer.draw( |         renderer.draw(bounds, self.path.as_path()) | ||||||
|             bounds, |  | ||||||
|             self.path.as_path(), |  | ||||||
|         ) |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn hash_layout(&self, state: &mut Hasher) { |     fn hash_layout(&self, state: &mut Hasher) { | ||||||
| @ -86,11 +87,7 @@ pub trait Renderer: crate::Renderer { | |||||||
|     /// Draws an [`Icon`].
 |     /// Draws an [`Icon`].
 | ||||||
|     ///
 |     ///
 | ||||||
|     /// [`Icon`]: struct.Icon.html
 |     /// [`Icon`]: struct.Icon.html
 | ||||||
|     fn draw( |     fn draw(&mut self, bounds: Rectangle, path: &Path) -> Self::Output; | ||||||
|         &mut self, |  | ||||||
|         bounds: Rectangle, |  | ||||||
|         path: &Path, |  | ||||||
|     ) -> Self::Output; |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl<'a, Message, Renderer> From<Icon> for Element<'a, Message, Renderer> | impl<'a, Message, Renderer> From<Icon> for Element<'a, Message, Renderer> | ||||||
|  | |||||||
| @ -89,8 +89,8 @@ pub mod widget { | |||||||
| 
 | 
 | ||||||
|     #[doc(no_inline)] |     #[doc(no_inline)] | ||||||
|     pub use { |     pub use { | ||||||
|         button::Button, icon::Icon, image::Image, scrollable::Scrollable, slider::Slider, |         button::Button, icon::Icon, image::Image, scrollable::Scrollable, | ||||||
|         text_input::TextInput, |         slider::Slider, text_input::TextInput, | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     /// A container that distributes its contents vertically.
 |     /// A container that distributes its contents vertically.
 | ||||||
|  | |||||||
| @ -243,13 +243,11 @@ impl Renderer { | |||||||
|                     scale: [bounds.width, bounds.height], |                     scale: [bounds.width, bounds.height], | ||||||
|                 }); |                 }); | ||||||
|             } |             } | ||||||
|             Primitive::Svg { handle, bounds } => { |             Primitive::Svg { handle, bounds } => layer.svgs.push(Svg { | ||||||
|                 layer.svgs.push(Svg { |                 handle: handle.clone(), | ||||||
|                     handle: handle.clone(), |                 position: [bounds.x, bounds.y], | ||||||
|                     position: [bounds.x, bounds.y], |                 scale: [bounds.width, bounds.height], | ||||||
|                     scale: [bounds.width, bounds.height], |             }), | ||||||
|                 }) |  | ||||||
|             }, |  | ||||||
|             Primitive::Clip { |             Primitive::Clip { | ||||||
|                 bounds, |                 bounds, | ||||||
|                 offset, |                 offset, | ||||||
|  | |||||||
| @ -1,15 +1,9 @@ | |||||||
| use crate::{svg::Handle, Primitive, Renderer}; | use crate::{svg::Handle, Primitive, Renderer}; | ||||||
| use iced_native::{ | use iced_native::{icon, MouseCursor, Rectangle}; | ||||||
|     icon, MouseCursor, Rectangle, |  | ||||||
| }; |  | ||||||
| use std::path::Path; | use std::path::Path; | ||||||
| 
 | 
 | ||||||
| impl icon::Renderer for Renderer { | impl icon::Renderer for Renderer { | ||||||
|     fn draw( |     fn draw(&mut self, bounds: Rectangle, path: &Path) -> Self::Output { | ||||||
|         &mut self, |  | ||||||
|         bounds: Rectangle, |  | ||||||
|         path: &Path, |  | ||||||
|     ) -> Self::Output { |  | ||||||
|         ( |         ( | ||||||
|             Primitive::Svg { |             Primitive::Svg { | ||||||
|                 handle: Handle::from_path(path), |                 handle: Handle::from_path(path), | ||||||
|  | |||||||
| @ -12,7 +12,6 @@ use std::{ | |||||||
|     u32, |     u32, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| #[derive(Debug)] | #[derive(Debug)] | ||||||
| pub struct Pipeline { | pub struct Pipeline { | ||||||
|     cache: RefCell<Cache>, |     cache: RefCell<Cache>, | ||||||
| @ -220,10 +219,11 @@ impl Pipeline { | |||||||
|             opt.usvg.dpi = handle.dpi as f64; |             opt.usvg.dpi = handle.dpi as f64; | ||||||
|             opt.usvg.font_size = handle.font_size as f64; |             opt.usvg.font_size = handle.font_size as f64; | ||||||
| 
 | 
 | ||||||
|             let mem = match resvg::usvg::Tree::from_file(&handle.path, &opt.usvg) { |             let mem = | ||||||
|                 Ok(tree) => Memory::Host { tree }, |                 match resvg::usvg::Tree::from_file(&handle.path, &opt.usvg) { | ||||||
|                 Err(_) => Memory::Invalid |                     Ok(tree) => Memory::Host { tree }, | ||||||
|             }; |                     Err(_) => Memory::Invalid, | ||||||
|  |                 }; | ||||||
| 
 | 
 | ||||||
|             let _ = self.cache.borrow_mut().insert(&handle, mem); |             let _ = self.cache.borrow_mut().insert(&handle, mem); | ||||||
|         } |         } | ||||||
| @ -265,12 +265,14 @@ impl Pipeline { | |||||||
| 
 | 
 | ||||||
|             self.load(&handle); |             self.load(&handle); | ||||||
| 
 | 
 | ||||||
|             if let Some(texture) = self |             if let Some(texture) = | ||||||
|                 .cache |                 self.cache.borrow_mut().get(&handle).unwrap().upload( | ||||||
|                 .borrow_mut() |                     device, | ||||||
|                 .get(&handle) |                     encoder, | ||||||
|                 .unwrap() |                     &self.texture_layout, | ||||||
|                 .upload(device, encoder, &self.texture_layout, svg.scale[0] as u32, svg.scale[1] as u32) |                     svg.scale[0] as u32, | ||||||
|  |                     svg.scale[1] as u32, | ||||||
|  |                 ) | ||||||
|             { |             { | ||||||
|                 let instance_buffer = device |                 let instance_buffer = device | ||||||
|                     .create_buffer_mapped(1, wgpu::BufferUsage::COPY_SRC) |                     .create_buffer_mapped(1, wgpu::BufferUsage::COPY_SRC) | ||||||
| @ -409,12 +411,8 @@ impl Hash for Handle { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| enum Memory { | enum Memory { | ||||||
|     Host { |     Host { tree: resvg::usvg::Tree }, | ||||||
|         tree: resvg::usvg::Tree, |     Device { bind_group: Rc<wgpu::BindGroup> }, | ||||||
|     }, |  | ||||||
|     Device { |  | ||||||
|         bind_group: Rc<wgpu::BindGroup>, |  | ||||||
|     }, |  | ||||||
|     NotFound, |     NotFound, | ||||||
|     Invalid, |     Invalid, | ||||||
| } | } | ||||||
| @ -426,7 +424,7 @@ impl Memory { | |||||||
|         encoder: &mut wgpu::CommandEncoder, |         encoder: &mut wgpu::CommandEncoder, | ||||||
|         texture_layout: &wgpu::BindGroupLayout, |         texture_layout: &wgpu::BindGroupLayout, | ||||||
|         width: u32, |         width: u32, | ||||||
|         height: u32 |         height: u32, | ||||||
|     ) -> Option<Rc<wgpu::BindGroup>> { |     ) -> Option<Rc<wgpu::BindGroup>> { | ||||||
|         match self { |         match self { | ||||||
|             Memory::Host { tree } => { |             Memory::Host { tree } => { | ||||||
| @ -447,10 +445,17 @@ impl Memory { | |||||||
|                         | wgpu::TextureUsage::SAMPLED, |                         | wgpu::TextureUsage::SAMPLED, | ||||||
|                 }); |                 }); | ||||||
| 
 | 
 | ||||||
|                 let mut canvas = resvg::raqote::DrawTarget::new(width as i32, height as i32); |                 let mut canvas = | ||||||
|  |                     resvg::raqote::DrawTarget::new(width as i32, height as i32); | ||||||
|                 let opt = resvg::Options::default(); |                 let opt = resvg::Options::default(); | ||||||
|                 let screen_size = resvg::ScreenSize::new(width, height).unwrap(); |                 let screen_size = | ||||||
|                 resvg::backend_raqote::render_to_canvas(tree, &opt, screen_size, &mut canvas); |                     resvg::ScreenSize::new(width, height).unwrap(); | ||||||
|  |                 resvg::backend_raqote::render_to_canvas( | ||||||
|  |                     tree, | ||||||
|  |                     &opt, | ||||||
|  |                     screen_size, | ||||||
|  |                     &mut canvas, | ||||||
|  |                 ); | ||||||
|                 let slice = canvas.get_data(); |                 let slice = canvas.get_data(); | ||||||
|                 let temp_buf = device |                 let temp_buf = device | ||||||
|                     .create_buffer_mapped( |                     .create_buffer_mapped( | ||||||
| @ -506,7 +511,10 @@ impl Memory { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Debug for Memory { | impl Debug for Memory { | ||||||
|     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { |     fn fmt( | ||||||
|  |         &self, | ||||||
|  |         f: &mut std::fmt::Formatter<'_>, | ||||||
|  |     ) -> Result<(), std::fmt::Error> { | ||||||
|         match self { |         match self { | ||||||
|             Memory::Host { .. } => write!(f, "Memory::Host"), |             Memory::Host { .. } => write!(f, "Memory::Host"), | ||||||
|             Memory::Device { .. } => write!(f, "Memory::Device"), |             Memory::Device { .. } => write!(f, "Memory::Device"), | ||||||
|  | |||||||
| @ -1,5 +1,6 @@ | |||||||
| pub use font_kit::error::SelectionError as LoadError; | pub use font_kit::{ | ||||||
| pub use font_kit::family_name::FamilyName as Family; |     error::SelectionError as LoadError, family_name::FamilyName as Family, | ||||||
|  | }; | ||||||
| 
 | 
 | ||||||
| pub struct Source { | pub struct Source { | ||||||
|     raw: font_kit::source::SystemSource, |     raw: font_kit::source::SystemSource, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user