Run cargo fmt

This commit is contained in:
Héctor Ramón Jiménez 2022-11-03 04:35:16 +01:00
parent 20a0577034
commit b957453404
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
17 changed files with 95 additions and 107 deletions

View file

@ -1,6 +1,6 @@
use iced::executor; use iced::executor;
use iced::widget::canvas::{ use iced::widget::canvas::{
Cache, Cursor, Geometry, LineCap, Path, Stroke, stroke, stroke, Cache, Cursor, Geometry, LineCap, Path, Stroke,
}; };
use iced::widget::{canvas, container}; use iced::widget::{canvas, container};
use iced::{ use iced::{

View file

@ -1,9 +1,10 @@
use iced::widget::canvas::{ use iced::widget::canvas::{
self, Cache, Canvas, Cursor, Frame, Geometry, Gradient, gradient::Position, gradient::Location self, gradient::Location, gradient::Position, Cache, Canvas, Cursor, Frame,
Geometry, Gradient,
}; };
use iced::{ use iced::{
executor, Application, Color, Command, Element, Length, Point, Rectangle, executor, Application, Color, Command, Element, Length, Point, Rectangle,
Renderer, Size, Theme, Settings Renderer, Settings, Size, Theme,
}; };
use rand::{thread_rng, Rng}; use rand::{thread_rng, Rng};
@ -86,7 +87,7 @@ fn random_direction() -> Location {
5 => Location::Bottom, 5 => Location::Bottom,
6 => Location::BottomLeft, 6 => Location::BottomLeft,
7 => Location::Left, 7 => Location::Left,
_ => Location::TopLeft _ => Location::TopLeft,
} }
} }
@ -106,7 +107,7 @@ fn generate_box(frame: &mut Frame, bounds: Size) -> bool {
top_left, top_left,
size, size,
start: random_direction(), start: random_direction(),
end: random_direction() end: random_direction(),
}); });
let stops = thread_rng().gen_range(1..15u32); let stops = thread_rng().gen_range(1..15u32);
@ -130,17 +131,9 @@ fn generate_box(frame: &mut Frame, bounds: Size) -> bool {
); );
if solid { if solid {
frame.fill_rectangle( frame.fill_rectangle(top_left, size, random_color());
top_left,
size,
random_color(),
);
} else { } else {
frame.fill_rectangle( frame.fill_rectangle(top_left, size, &gradient(top_left, size));
top_left,
size,
&gradient(top_left, size),
);
}; };
solid solid

View file

@ -11,7 +11,9 @@ use iced::executor;
use iced::theme::{self, Theme}; use iced::theme::{self, Theme};
use iced::time; use iced::time;
use iced::widget::canvas; use iced::widget::canvas;
use iced::widget::canvas::{Cursor, Path, Stroke, Gradient, stroke, gradient::Position}; use iced::widget::canvas::{
gradient::Position, stroke, Cursor, Gradient, Path, Stroke,
};
use iced::window; use iced::window;
use iced::{ use iced::{
Application, Color, Command, Element, Length, Point, Rectangle, Settings, Application, Color, Command, Element, Length, Point, Rectangle, Settings,
@ -201,12 +203,10 @@ impl<Message> canvas::Program<Message> for State {
let earth = Path::circle(Point::ORIGIN, Self::EARTH_RADIUS); let earth = Path::circle(Point::ORIGIN, Self::EARTH_RADIUS);
let earth_fill = Gradient::linear( let earth_fill = Gradient::linear(Position::Absolute {
Position::Absolute {
start: Point::new(-Self::EARTH_RADIUS, 0.0), start: Point::new(-Self::EARTH_RADIUS, 0.0),
end: Point::new(Self::EARTH_RADIUS, 0.0) end: Point::new(Self::EARTH_RADIUS, 0.0),
} })
)
.add_stop(0.2, Color::from_rgb(0.15, 0.50, 1.0)) .add_stop(0.2, Color::from_rgb(0.15, 0.50, 1.0))
.add_stop(0.8, Color::from_rgb(0.0, 0.20, 0.47)) .add_stop(0.8, Color::from_rgb(0.0, 0.20, 0.47))
.build() .build()

View file

@ -1,6 +1,6 @@
use crate::{program, triangle};
use crate::quad; use crate::quad;
use crate::text; use crate::text;
use crate::{program, triangle};
use crate::{Settings, Transformation, Viewport}; use crate::{Settings, Transformation, Viewport};
use iced_graphics::backend; use iced_graphics::backend;

View file

@ -57,16 +57,18 @@ impl Program {
if &self.uniform_data.gradient != gradient { if &self.uniform_data.gradient != gradient {
match gradient { match gradient {
Gradient::Linear(linear) => { Gradient::Linear(linear) => unsafe {
unsafe {
gl.uniform_4_f32( gl.uniform_4_f32(
Some( Some(
&self.uniform_data.uniform_locations.gradient_direction_location &self
.uniform_data
.uniform_locations
.gradient_direction_location,
), ),
linear.start.x, linear.start.x,
linear.start.y, linear.start.y,
linear.end.x, linear.end.x,
linear.end.y linear.end.y,
); );
gl.uniform_1_u32( gl.uniform_1_u32(
@ -81,15 +83,17 @@ impl Program {
let mut stops = [0.0; 128]; let mut stops = [0.0; 128];
for (index, stop) in linear.color_stops.iter().enumerate().take(16) { for (index, stop) in
stops[index*8] = stop.color.r; linear.color_stops.iter().enumerate().take(16)
stops[(index*8)+1] = stop.color.g; {
stops[(index*8)+2] = stop.color.b; stops[index * 8] = stop.color.r;
stops[(index*8)+3] = stop.color.a; stops[(index * 8) + 1] = stop.color.g;
stops[(index*8)+4] = stop.offset; stops[(index * 8) + 2] = stop.color.b;
stops[(index*8)+5] = 0.; stops[(index * 8) + 3] = stop.color.a;
stops[(index*8)+6] = 0.; stops[(index * 8) + 4] = stop.offset;
stops[(index*8)+7] = 0.; stops[(index * 8) + 5] = 0.;
stops[(index * 8) + 6] = 0.;
stops[(index * 8) + 7] = 0.;
} }
gl.uniform_4_f32_slice( gl.uniform_4_f32_slice(
@ -101,8 +105,7 @@ impl Program {
), ),
&stops, &stops,
); );
} },
}
} }
self.uniform_data.gradient = gradient.clone(); self.uniform_data.gradient = gradient.clone();

View file

@ -26,7 +26,11 @@ impl<Theme> iced_graphics::window::GLCompositor for Compositor<Theme> {
log::info!("{:#?}", settings); log::info!("{:#?}", settings);
let version = gl.version(); let version = gl.version();
log::info!("OpenGL version: {:?} (Embedded: {})", version, version.is_embedded); log::info!(
"OpenGL version: {:?} (Embedded: {})",
version,
version.is_embedded
);
let renderer = gl.get_parameter_string(glow::RENDERER); let renderer = gl.get_parameter_string(glow::RENDERER);
log::info!("Renderer: {}", renderer); log::info!("Renderer: {}", renderer);

View file

@ -103,7 +103,7 @@ pub struct Builder {
start: Point, start: Point,
end: Point, end: Point,
stops: Vec<ColorStop>, stops: Vec<ColorStop>,
error: Option<BuilderError> error: Option<BuilderError>,
} }
impl Builder { impl Builder {
@ -126,7 +126,7 @@ impl Builder {
start, start,
end, end,
stops: vec![], stops: vec![],
error: None error: None,
} }
} }
@ -148,7 +148,7 @@ impl Builder {
}) { }) {
Ok(_) => { Ok(_) => {
self.error = Some(BuilderError::DuplicateOffset(offset)) self.error = Some(BuilderError::DuplicateOffset(offset))
}, }
Err(index) => { Err(index) => {
self.stops.insert(index, ColorStop { offset, color }); self.stops.insert(index, ColorStop { offset, color });
} }

View file

@ -1,17 +1,17 @@
//! Organize rendering primitives into a flattened list of layers. //! Organize rendering primitives into a flattened list of layers.
mod image;
pub mod mesh; pub mod mesh;
mod quad; mod quad;
mod text; mod text;
mod image;
use crate::alignment; use crate::alignment;
use crate::{
Background, Font, Point, Primitive, Rectangle, Size, Vector, Viewport,
};
pub use crate::layer::image::Image; pub use crate::layer::image::Image;
pub use crate::layer::mesh::Mesh; pub use crate::layer::mesh::Mesh;
pub use crate::layer::quad::Quad; pub use crate::layer::quad::Quad;
pub use crate::layer::text::Text; pub use crate::layer::text::Text;
use crate::{
Background, Font, Point, Primitive, Rectangle, Size, Vector, Viewport,
};
/// A group of primitives that should be clipped together. /// A group of primitives that should be clipped together.
#[derive(Debug)] #[derive(Debug)]
@ -178,14 +178,12 @@ impl<'a> Layer<'a> {
// Only draw visible content // Only draw visible content
if let Some(clip_bounds) = layer.bounds.intersection(&bounds) { if let Some(clip_bounds) = layer.bounds.intersection(&bounds) {
layer.meshes.push( layer.meshes.push(Mesh {
Mesh {
origin: Point::new(translation.x, translation.y), origin: Point::new(translation.x, translation.y),
buffers, buffers,
clip_bounds, clip_bounds,
style, style,
} });
);
} }
} }
Primitive::Clip { bounds, content } => { Primitive::Clip { bounds, content } => {

View file

@ -1,5 +1,5 @@
use iced_native::{image, svg};
use crate::Rectangle; use crate::Rectangle;
use iced_native::{image, svg};
/// A raster or vector image. /// A raster or vector image.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View file

@ -29,13 +29,13 @@ mod viewport;
pub mod backend; pub mod backend;
pub mod font; pub mod font;
pub mod gradient;
pub mod layer; pub mod layer;
pub mod overlay; pub mod overlay;
pub mod renderer; pub mod renderer;
pub mod triangle; pub mod triangle;
pub mod widget; pub mod widget;
pub mod window; pub mod window;
pub mod gradient;
pub use antialiasing::Antialiasing; pub use antialiasing::Antialiasing;
pub use backend::Backend; pub use backend::Backend;

View file

@ -2,8 +2,8 @@ use iced_native::image;
use iced_native::svg; use iced_native::svg;
use iced_native::{Background, Color, Font, Rectangle, Size, Vector}; use iced_native::{Background, Color, Font, Rectangle, Size, Vector};
use crate::{alignment, layer::mesh};
use crate::triangle; use crate::triangle;
use crate::{alignment, layer::mesh};
use std::sync::Arc; use std::sync::Arc;

View file

@ -9,12 +9,12 @@ pub mod path;
mod cache; mod cache;
mod cursor; mod cursor;
pub mod fill;
pub(crate) mod frame;
mod geometry; mod geometry;
mod program; mod program;
mod text;
pub mod fill;
pub mod stroke; pub mod stroke;
pub(crate) mod frame; mod text;
pub use cache::Cache; pub use cache::Cache;
pub use cursor::Cursor; pub use cursor::Cursor;
@ -27,8 +27,8 @@ pub use program::Program;
pub use stroke::{LineCap, LineDash, LineJoin, Stroke}; pub use stroke::{LineCap, LineDash, LineJoin, Stroke};
pub use text::Text; pub use text::Text;
use crate::{Backend, Primitive, Renderer};
pub use crate::gradient::{self, Gradient}; pub use crate::gradient::{self, Gradient};
use crate::{Backend, Primitive, Renderer};
use iced_native::layout::{self, Layout}; use iced_native::layout::{self, Layout};
use iced_native::mouse; use iced_native::mouse;

View file

@ -94,7 +94,7 @@ impl Backend {
staging_belt, staging_belt,
encoder, encoder,
frame, frame,
target_size target_size,
); );
} }

View file

@ -56,11 +56,7 @@ impl<T: Pod + Zeroable> StaticBuffer<T> {
/// Returns whether or not the buffer needs to be recreated. This can happen whenever mesh data /// Returns whether or not the buffer needs to be recreated. This can happen whenever mesh data
/// changes & a redraw is requested. /// changes & a redraw is requested.
pub fn resize( pub fn resize(&mut self, device: &wgpu::Device, new_count: usize) -> bool {
&mut self,
device: &wgpu::Device,
new_count: usize,
) -> bool {
let size = let size =
wgpu::BufferAddress::from((mem::size_of::<T>() * new_count) as u64); wgpu::BufferAddress::from((mem::size_of::<T>() * new_count) as u64);

View file

@ -65,9 +65,7 @@ impl<T: ShaderType + WriteInto> Buffer<T> {
pub fn uniform(device: &wgpu::Device, label: &'static str) -> Self { pub fn uniform(device: &wgpu::Device, label: &'static str) -> Self {
Buffer::new( Buffer::new(
device, device,
BufferType::Uniform(encase::DynamicUniformBuffer::new( BufferType::Uniform(encase::DynamicUniformBuffer::new(Vec::new())),
Vec::new(),
)),
label, label,
wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
) )
@ -77,9 +75,7 @@ impl<T: ShaderType + WriteInto> Buffer<T> {
pub fn storage(device: &wgpu::Device, label: &'static str) -> Self { pub fn storage(device: &wgpu::Device, label: &'static str) -> Self {
Buffer::new( Buffer::new(
device, device,
BufferType::Storage(encase::DynamicStorageBuffer::new( BufferType::Storage(encase::DynamicStorageBuffer::new(Vec::new())),
Vec::new(),
)),
label, label,
wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST, wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST,
) )

View file

@ -42,8 +42,8 @@ pub mod settings;
pub mod triangle; pub mod triangle;
pub mod window; pub mod window;
mod buffers;
mod backend; mod backend;
mod buffers;
mod quad; mod quad;
mod text; mod text;

View file

@ -3,15 +3,15 @@ use crate::{settings, Transformation};
use core::fmt; use core::fmt;
use std::fmt::Formatter; use std::fmt::Formatter;
use iced_graphics::layer::{Mesh, mesh}; use iced_graphics::layer::{mesh, Mesh};
use iced_graphics::Size; use iced_graphics::Size;
use crate::buffers::StaticBuffer; use crate::buffers::StaticBuffer;
pub use iced_graphics::triangle::{Mesh2D, Vertex2D}; pub use iced_graphics::triangle::{Mesh2D, Vertex2D};
mod solid;
mod gradient; mod gradient;
mod msaa; mod msaa;
mod solid;
/// Triangle pipeline for all mesh layers in a [`iced_graphics::Canvas`] widget. /// Triangle pipeline for all mesh layers in a [`iced_graphics::Canvas`] widget.
#[derive(Debug)] #[derive(Debug)]
@ -103,9 +103,7 @@ impl Pipeline {
//We are not currently using the return value of these functions as we have no system in //We are not currently using the return value of these functions as we have no system in
//place to calculate mesh diff, or to know whether or not that would be more performant for //place to calculate mesh diff, or to know whether or not that would be more performant for
//the majority of use cases. Therefore we will write GPU data every frame (for now). //the majority of use cases. Therefore we will write GPU data every frame (for now).
let _ = self let _ = self.vertex_buffer.resize(device, total_vertices);
.vertex_buffer
.resize(device, total_vertices);
let _ = self.index_buffer.resize(device, total_indices); let _ = self.index_buffer.resize(device, total_indices);
//prepare dynamic buffers & data store for writing //prepare dynamic buffers & data store for writing