Skip to content

Commit

Permalink
Ran cargo_fmt over changed files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maldela committed Dec 11, 2019
1 parent a88aae5 commit 5696afc
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 55 deletions.
21 changes: 9 additions & 12 deletions native/src/widget/icon.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
//! 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::path::{Path, PathBuf};
use std::{
hash::Hash,
path::{Path, PathBuf},
};

/// A simple icon_loader widget.
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -63,10 +67,7 @@ where
) -> Renderer::Output {
let bounds = layout.bounds();

renderer.draw(
bounds,
self.path.as_path(),
)
renderer.draw(bounds, self.path.as_path())
}

fn hash_layout(&self, state: &mut Hasher) {
Expand All @@ -86,11 +87,7 @@ pub trait Renderer: crate::Renderer {
/// Draws an [`Icon`].
///
/// [`Icon`]: struct.Icon.html
fn draw(
&mut self,
bounds: Rectangle,
path: &Path,
) -> Self::Output;
fn draw(&mut self, bounds: Rectangle, path: &Path) -> Self::Output;
}

impl<'a, Message, Renderer> From<Icon> for Element<'a, Message, Renderer>
Expand Down
4 changes: 2 additions & 2 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ pub mod widget {

#[doc(no_inline)]
pub use {
button::Button, icon::Icon, image::Image, scrollable::Scrollable, slider::Slider,
text_input::TextInput,
button::Button, icon::Icon, image::Image, scrollable::Scrollable,
slider::Slider, text_input::TextInput,
};

/// A container that distributes its contents vertically.
Expand Down
12 changes: 5 additions & 7 deletions wgpu/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,11 @@ impl Renderer {
scale: [bounds.width, bounds.height],
});
}
Primitive::Svg { handle, bounds } => {
layer.svgs.push(Svg {
handle: handle.clone(),
position: [bounds.x, bounds.y],
scale: [bounds.width, bounds.height],
})
},
Primitive::Svg { handle, bounds } => layer.svgs.push(Svg {
handle: handle.clone(),
position: [bounds.x, bounds.y],
scale: [bounds.width, bounds.height],
}),
Primitive::Clip {
bounds,
offset,
Expand Down
12 changes: 3 additions & 9 deletions wgpu/src/renderer/widget/icon.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
use crate::{svg::Handle, Primitive, Renderer};
use iced_native::{
icon, MouseCursor, Rectangle,
};
use iced_native::{icon, MouseCursor, Rectangle};
use std::path::Path;

impl icon::Renderer for Renderer {
fn draw(
&mut self,
bounds: Rectangle,
path: &Path,
) -> Self::Output {
fn draw(&mut self, bounds: Rectangle, path: &Path) -> Self::Output {
(
Primitive::Svg {
handle: Handle::from_path(path),
Expand All @@ -18,4 +12,4 @@ impl icon::Renderer for Renderer {
MouseCursor::OutOfBounds,
)
}
}
}
54 changes: 31 additions & 23 deletions wgpu/src/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use std::{
u32,
};


#[derive(Debug)]
pub struct Pipeline {
cache: RefCell<Cache>,
Expand Down Expand Up @@ -220,10 +219,11 @@ impl Pipeline {
opt.usvg.dpi = handle.dpi as f64;
opt.usvg.font_size = handle.font_size as f64;

let mem = match resvg::usvg::Tree::from_file(&handle.path, &opt.usvg) {
Ok(tree) => Memory::Host { tree },
Err(_) => Memory::Invalid
};
let mem =
match resvg::usvg::Tree::from_file(&handle.path, &opt.usvg) {
Ok(tree) => Memory::Host { tree },
Err(_) => Memory::Invalid,
};

let _ = self.cache.borrow_mut().insert(&handle, mem);
}
Expand Down Expand Up @@ -265,12 +265,14 @@ impl Pipeline {

self.load(&handle);

if let Some(texture) = self
.cache
.borrow_mut()
.get(&handle)
.unwrap()
.upload(device, encoder, &self.texture_layout, svg.scale[0] as u32, svg.scale[1] as u32)
if let Some(texture) =
self.cache.borrow_mut().get(&handle).unwrap().upload(
device,
encoder,
&self.texture_layout,
svg.scale[0] as u32,
svg.scale[1] as u32,
)
{
let instance_buffer = device
.create_buffer_mapped(1, wgpu::BufferUsage::COPY_SRC)
Expand Down Expand Up @@ -409,12 +411,8 @@ impl Hash for Handle {
}

enum Memory {
Host {
tree: resvg::usvg::Tree,
},
Device {
bind_group: Rc<wgpu::BindGroup>,
},
Host { tree: resvg::usvg::Tree },
Device { bind_group: Rc<wgpu::BindGroup> },
NotFound,
Invalid,
}
Expand All @@ -426,7 +424,7 @@ impl Memory {
encoder: &mut wgpu::CommandEncoder,
texture_layout: &wgpu::BindGroupLayout,
width: u32,
height: u32
height: u32,
) -> Option<Rc<wgpu::BindGroup>> {
match self {
Memory::Host { tree } => {
Expand All @@ -447,10 +445,17 @@ impl Memory {
| 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 screen_size = resvg::ScreenSize::new(width, height).unwrap();
resvg::backend_raqote::render_to_canvas(tree, &opt, screen_size, &mut canvas);
let screen_size =
resvg::ScreenSize::new(width, height).unwrap();
resvg::backend_raqote::render_to_canvas(
tree,
&opt,
screen_size,
&mut canvas,
);
let slice = canvas.get_data();
let temp_buf = device
.create_buffer_mapped(
Expand Down Expand Up @@ -506,7 +511,10 @@ impl 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 {
Memory::Host { .. } => write!(f, "Memory::Host"),
Memory::Device { .. } => write!(f, "Memory::Device"),
Expand Down Expand Up @@ -593,4 +601,4 @@ struct Instance {
#[derive(Debug, Clone, Copy)]
struct Uniforms {
transform: [f32; 16],
}
}
5 changes: 3 additions & 2 deletions wgpu/src/text/font.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub use font_kit::error::SelectionError as LoadError;
pub use font_kit::family_name::FamilyName as Family;
pub use font_kit::{
error::SelectionError as LoadError, family_name::FamilyName as Family,
};

pub struct Source {
raw: font_kit::source::SystemSource,
Expand Down

0 comments on commit 5696afc

Please sign in to comment.