Run cargo fmt
This commit is contained in:
parent
20a0577034
commit
b957453404
17 changed files with 95 additions and 107 deletions
|
|
@ -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::{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
);
|
||||
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,
|
||||
);
|
||||
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];
|
||||
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,
|
||||
);
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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> {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ impl Backend {
|
|||
staging_belt,
|
||||
encoder,
|
||||
frame,
|
||||
target_size
|
||||
target_size,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ pub mod settings;
|
|||
pub mod triangle;
|
||||
pub mod window;
|
||||
|
||||
mod buffers;
|
||||
mod backend;
|
||||
mod buffers;
|
||||
mod quad;
|
||||
mod text;
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue