summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-11-03 04:35:16 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-11-03 04:35:16 +0100
commitb95745340441835bd25b5cadc2342254631f8c05 (patch)
tree38f103e59a9decdc83ac5c7514fe89006bf0c7dd
parent20a0577034b40a6bbabee9bbbfc085f3fd5016c0 (diff)
downloadiced-b95745340441835bd25b5cadc2342254631f8c05.tar.gz
iced-b95745340441835bd25b5cadc2342254631f8c05.tar.bz2
iced-b95745340441835bd25b5cadc2342254631f8c05.zip
Run `cargo fmt`
-rw-r--r--examples/clock/src/main.rs2
-rw-r--r--examples/modern_art/src/main.rs21
-rw-r--r--examples/solar_system/src/main.rs14
-rw-r--r--glow/src/backend.rs2
-rw-r--r--glow/src/triangle/gradient.rs93
-rw-r--r--glow/src/window/compositor.rs6
-rw-r--r--graphics/src/gradient/linear.rs6
-rw-r--r--graphics/src/layer.rs24
-rw-r--r--graphics/src/layer/image.rs2
-rw-r--r--graphics/src/lib.rs2
-rw-r--r--graphics/src/primitive.rs2
-rw-r--r--graphics/src/widget/canvas.rs8
-rw-r--r--wgpu/src/backend.rs2
-rw-r--r--wgpu/src/buffers.rs6
-rw-r--r--wgpu/src/buffers/dynamic.rs8
-rw-r--r--wgpu/src/lib.rs2
-rw-r--r--wgpu/src/triangle.rs8
17 files changed, 98 insertions, 110 deletions
diff --git a/examples/clock/src/main.rs b/examples/clock/src/main.rs
index be614201..a389c54f 100644
--- a/examples/clock/src/main.rs
+++ b/examples/clock/src/main.rs
@@ -1,6 +1,6 @@
use iced::executor;
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::{
diff --git a/examples/modern_art/src/main.rs b/examples/modern_art/src/main.rs
index fc203cff..db9b0491 100644
--- a/examples/modern_art/src/main.rs
+++ b/examples/modern_art/src/main.rs
@@ -1,9 +1,10 @@
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::{
executor, Application, Color, Command, Element, Length, Point, Rectangle,
- Renderer, Size, Theme, Settings
+ Renderer, Settings, Size, Theme,
};
use rand::{thread_rng, Rng};
@@ -86,7 +87,7 @@ fn random_direction() -> Location {
5 => Location::Bottom,
6 => Location::BottomLeft,
7 => Location::Left,
- _ => Location::TopLeft
+ _ => Location::TopLeft,
}
}
@@ -106,7 +107,7 @@ fn generate_box(frame: &mut Frame, bounds: Size) -> bool {
top_left,
size,
start: random_direction(),
- end: random_direction()
+ end: random_direction(),
});
let stops = thread_rng().gen_range(1..15u32);
@@ -130,17 +131,9 @@ fn generate_box(frame: &mut Frame, bounds: Size) -> bool {
);
if solid {
- frame.fill_rectangle(
- top_left,
- size,
- random_color(),
- );
+ frame.fill_rectangle(top_left, size, random_color());
} else {
- frame.fill_rectangle(
- top_left,
- size,
- &gradient(top_left, size),
- );
+ frame.fill_rectangle(top_left, size, &gradient(top_left, size));
};
solid
diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs
index b638c6d0..09ac508d 100644
--- a/examples/solar_system/src/main.rs
+++ b/examples/solar_system/src/main.rs
@@ -11,7 +11,9 @@ use iced::executor;
use iced::theme::{self, Theme};
use iced::time;
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::{
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_fill = Gradient::linear(
- Position::Absolute {
- start: Point::new(-Self::EARTH_RADIUS, 0.0),
- end: Point::new(Self::EARTH_RADIUS, 0.0)
- }
- )
+ let earth_fill = Gradient::linear(Position::Absolute {
+ start: 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.8, Color::from_rgb(0.0, 0.20, 0.47))
.build()
diff --git a/glow/src/backend.rs b/glow/src/backend.rs
index 7333d513..21af2ecf 100644
--- a/glow/src/backend.rs
+++ b/glow/src/backend.rs
@@ -1,6 +1,6 @@
-use crate::{program, triangle};
use crate::quad;
use crate::text;
+use crate::{program, triangle};
use crate::{Settings, Transformation, Viewport};
use iced_graphics::backend;
diff --git a/glow/src/triangle/gradient.rs b/glow/src/triangle/gradient.rs
index 36e434e3..ad41dffd 100644
--- a/glow/src/triangle/gradient.rs
+++ b/glow/src/triangle/gradient.rs
@@ -57,52 +57,55 @@ impl Program {
if &self.uniform_data.gradient != gradient {
match gradient {
- Gradient::Linear(linear) => {
- unsafe {
- gl.uniform_4_f32(
- Some(
- &self.uniform_data.uniform_locations.gradient_direction_location
- ),
- linear.start.x,
- linear.start.y,
- linear.end.x,
- linear.end.y
- );
-
- gl.uniform_1_u32(
- Some(
- &self
- .uniform_data
- .uniform_locations
- .color_stops_size_location,
- ),
- (linear.color_stops.len() * 2) as u32,
- );
-
- let mut stops = [0.0; 128];
-
- for (index, stop) in linear.color_stops.iter().enumerate().take(16) {
- stops[index*8] = stop.color.r;
- stops[(index*8)+1] = stop.color.g;
- stops[(index*8)+2] = stop.color.b;
- stops[(index*8)+3] = stop.color.a;
- stops[(index*8)+4] = stop.offset;
- stops[(index*8)+5] = 0.;
- stops[(index*8)+6] = 0.;
- stops[(index*8)+7] = 0.;
- }
-
- gl.uniform_4_f32_slice(
- Some(
- &self
- .uniform_data
- .uniform_locations
- .color_stops_location,
- ),
- &stops,
- );
+ Gradient::Linear(linear) => unsafe {
+ gl.uniform_4_f32(
+ Some(
+ &self
+ .uniform_data
+ .uniform_locations
+ .gradient_direction_location,
+ ),
+ linear.start.x,
+ linear.start.y,
+ linear.end.x,
+ linear.end.y,
+ );
+
+ gl.uniform_1_u32(
+ Some(
+ &self
+ .uniform_data
+ .uniform_locations
+ .color_stops_size_location,
+ ),
+ (linear.color_stops.len() * 2) as u32,
+ );
+
+ let mut stops = [0.0; 128];
+
+ for (index, stop) in
+ linear.color_stops.iter().enumerate().take(16)
+ {
+ stops[index * 8] = stop.color.r;
+ stops[(index * 8) + 1] = stop.color.g;
+ stops[(index * 8) + 2] = stop.color.b;
+ stops[(index * 8) + 3] = stop.color.a;
+ stops[(index * 8) + 4] = stop.offset;
+ stops[(index * 8) + 5] = 0.;
+ stops[(index * 8) + 6] = 0.;
+ stops[(index * 8) + 7] = 0.;
}
- }
+
+ gl.uniform_4_f32_slice(
+ Some(
+ &self
+ .uniform_data
+ .uniform_locations
+ .color_stops_location,
+ ),
+ &stops,
+ );
+ },
}
self.uniform_data.gradient = gradient.clone();
diff --git a/glow/src/window/compositor.rs b/glow/src/window/compositor.rs
index 6459dbce..20756032 100644
--- a/glow/src/window/compositor.rs
+++ b/glow/src/window/compositor.rs
@@ -26,7 +26,11 @@ impl<Theme> iced_graphics::window::GLCompositor for Compositor<Theme> {
log::info!("{:#?}", settings);
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);
log::info!("Renderer: {}", renderer);
diff --git a/graphics/src/gradient/linear.rs b/graphics/src/gradient/linear.rs
index 31dcbe00..aaa9e234 100644
--- a/graphics/src/gradient/linear.rs
+++ b/graphics/src/gradient/linear.rs
@@ -103,7 +103,7 @@ pub struct Builder {
start: Point,
end: Point,
stops: Vec<ColorStop>,
- error: Option<BuilderError>
+ error: Option<BuilderError>,
}
impl Builder {
@@ -126,7 +126,7 @@ impl Builder {
start,
end,
stops: vec![],
- error: None
+ error: None,
}
}
@@ -148,7 +148,7 @@ impl Builder {
}) {
Ok(_) => {
self.error = Some(BuilderError::DuplicateOffset(offset))
- },
+ }
Err(index) => {
self.stops.insert(index, ColorStop { offset, color });
}
diff --git a/graphics/src/layer.rs b/graphics/src/layer.rs
index 56a42a9d..40e006a2 100644
--- a/graphics/src/layer.rs
+++ b/graphics/src/layer.rs
@@ -1,17 +1,17 @@
//! Organize rendering primitives into a flattened list of layers.
+mod image;
pub mod mesh;
mod quad;
mod text;
-mod image;
use crate::alignment;
-use crate::{
- Background, Font, Point, Primitive, Rectangle, Size, Vector, Viewport,
-};
pub use crate::layer::image::Image;
pub use crate::layer::mesh::Mesh;
pub use crate::layer::quad::Quad;
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.
#[derive(Debug)]
@@ -178,14 +178,12 @@ impl<'a> Layer<'a> {
// Only draw visible content
if let Some(clip_bounds) = layer.bounds.intersection(&bounds) {
- layer.meshes.push(
- Mesh {
- origin: Point::new(translation.x, translation.y),
- buffers,
- clip_bounds,
- style,
- }
- );
+ layer.meshes.push(Mesh {
+ origin: Point::new(translation.x, translation.y),
+ buffers,
+ clip_bounds,
+ style,
+ });
}
}
Primitive::Clip { bounds, content } => {
@@ -244,4 +242,4 @@ impl<'a> Layer<'a> {
}
}
}
-} \ No newline at end of file
+}
diff --git a/graphics/src/layer/image.rs b/graphics/src/layer/image.rs
index cbba7888..045ec665 100644
--- a/graphics/src/layer/image.rs
+++ b/graphics/src/layer/image.rs
@@ -1,5 +1,5 @@
-use iced_native::{image, svg};
use crate::Rectangle;
+use iced_native::{image, svg};
/// A raster or vector image.
#[derive(Debug, Clone)]
diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs
index 0d29416c..d4274237 100644
--- a/graphics/src/lib.rs
+++ b/graphics/src/lib.rs
@@ -29,13 +29,13 @@ mod viewport;
pub mod backend;
pub mod font;
+pub mod gradient;
pub mod layer;
pub mod overlay;
pub mod renderer;
pub mod triangle;
pub mod widget;
pub mod window;
-pub mod gradient;
pub use antialiasing::Antialiasing;
pub use backend::Backend;
diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs
index 5cb0ef23..c0d6bb55 100644
--- a/graphics/src/primitive.rs
+++ b/graphics/src/primitive.rs
@@ -2,8 +2,8 @@ use iced_native::image;
use iced_native::svg;
use iced_native::{Background, Color, Font, Rectangle, Size, Vector};
-use crate::{alignment, layer::mesh};
use crate::triangle;
+use crate::{alignment, layer::mesh};
use std::sync::Arc;
diff --git a/graphics/src/widget/canvas.rs b/graphics/src/widget/canvas.rs
index ea2efcc1..b9ccb721 100644
--- a/graphics/src/widget/canvas.rs
+++ b/graphics/src/widget/canvas.rs
@@ -9,12 +9,12 @@ pub mod path;
mod cache;
mod cursor;
+pub mod fill;
+pub(crate) mod frame;
mod geometry;
mod program;
-mod text;
-pub mod fill;
pub mod stroke;
-pub(crate) mod frame;
+mod text;
pub use cache::Cache;
pub use cursor::Cursor;
@@ -27,8 +27,8 @@ pub use program::Program;
pub use stroke::{LineCap, LineDash, LineJoin, Stroke};
pub use text::Text;
-use crate::{Backend, Primitive, Renderer};
pub use crate::gradient::{self, Gradient};
+use crate::{Backend, Primitive, Renderer};
use iced_native::layout::{self, Layout};
use iced_native::mouse;
diff --git a/wgpu/src/backend.rs b/wgpu/src/backend.rs
index 9295a491..80026673 100644
--- a/wgpu/src/backend.rs
+++ b/wgpu/src/backend.rs
@@ -94,7 +94,7 @@ impl Backend {
staging_belt,
encoder,
frame,
- target_size
+ target_size,
);
}
diff --git a/wgpu/src/buffers.rs b/wgpu/src/buffers.rs
index dc9fc6e2..34fe0fca 100644
--- a/wgpu/src/buffers.rs
+++ b/wgpu/src/buffers.rs
@@ -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
/// changes & a redraw is requested.
- pub fn resize(
- &mut self,
- device: &wgpu::Device,
- new_count: usize,
- ) -> bool {
+ pub fn resize(&mut self, device: &wgpu::Device, new_count: usize) -> bool {
let size =
wgpu::BufferAddress::from((mem::size_of::<T>() * new_count) as u64);
diff --git a/wgpu/src/buffers/dynamic.rs b/wgpu/src/buffers/dynamic.rs
index 63955b6e..3c65d6e1 100644
--- a/wgpu/src/buffers/dynamic.rs
+++ b/wgpu/src/buffers/dynamic.rs
@@ -65,9 +65,7 @@ impl<T: ShaderType + WriteInto> Buffer<T> {
pub fn uniform(device: &wgpu::Device, label: &'static str) -> Self {
Buffer::new(
device,
- BufferType::Uniform(encase::DynamicUniformBuffer::new(
- Vec::new(),
- )),
+ BufferType::Uniform(encase::DynamicUniformBuffer::new(Vec::new())),
label,
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 {
Buffer::new(
device,
- BufferType::Storage(encase::DynamicStorageBuffer::new(
- Vec::new(),
- )),
+ BufferType::Storage(encase::DynamicStorageBuffer::new(Vec::new())),
label,
wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST,
)
diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs
index c76c8c7a..a2b4ff39 100644
--- a/wgpu/src/lib.rs
+++ b/wgpu/src/lib.rs
@@ -42,8 +42,8 @@ pub mod settings;
pub mod triangle;
pub mod window;
-mod buffers;
mod backend;
+mod buffers;
mod quad;
mod text;
diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs
index 0956c57d..a21e0fac 100644
--- a/wgpu/src/triangle.rs
+++ b/wgpu/src/triangle.rs
@@ -3,15 +3,15 @@ use crate::{settings, Transformation};
use core::fmt;
use std::fmt::Formatter;
-use iced_graphics::layer::{Mesh, mesh};
+use iced_graphics::layer::{mesh, Mesh};
use iced_graphics::Size;
use crate::buffers::StaticBuffer;
pub use iced_graphics::triangle::{Mesh2D, Vertex2D};
-mod solid;
mod gradient;
mod msaa;
+mod solid;
/// Triangle pipeline for all mesh layers in a [`iced_graphics::Canvas`] widget.
#[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
//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).
- let _ = self
- .vertex_buffer
- .resize(device, total_vertices);
+ let _ = self.vertex_buffer.resize(device, total_vertices);
let _ = self.index_buffer.resize(device, total_indices);
//prepare dynamic buffers & data store for writing