diff options
Diffstat (limited to '')
-rw-r--r-- | wgpu/src/renderer.rs | 32 | ||||
-rw-r--r-- | wgpu/src/renderer/widget.rs | 1 | ||||
-rw-r--r-- | wgpu/src/renderer/widget/progress_bar.rs | 51 |
3 files changed, 81 insertions, 3 deletions
diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs index 8f0b2020..9757904c 100644 --- a/wgpu/src/renderer.rs +++ b/wgpu/src/renderer.rs @@ -1,12 +1,12 @@ use crate::{ - image, quad, text, Defaults, Image, Primitive, Quad, Settings, + image, quad, text, triangle, Defaults, Image, Primitive, Quad, Settings, Transformation, }; use iced_native::{ renderer::{Debugger, Windowed}, Background, Color, Layout, MouseCursor, Point, Rectangle, Vector, Widget, }; - +use std::sync::Arc; use wgpu::{ Adapter, BackendBit, CommandEncoderDescriptor, Device, DeviceDescriptor, Extensions, Limits, PowerPreference, Queue, RequestAdapterOptions, @@ -27,6 +27,7 @@ pub struct Renderer { quad_pipeline: quad::Pipeline, image_pipeline: image::Pipeline, text_pipeline: text::Pipeline, + triangle_pipeline: crate::triangle::Pipeline, } struct Layer<'a> { @@ -34,6 +35,7 @@ struct Layer<'a> { offset: Vector<u32>, quads: Vec<Quad>, images: Vec<Image>, + meshes: Vec<Arc<triangle::Mesh2D>>, text: Vec<wgpu_glyph::Section<'a>>, } @@ -45,6 +47,7 @@ impl<'a> Layer<'a> { quads: Vec::new(), images: Vec::new(), text: Vec::new(), + meshes: Vec::new(), } } } @@ -67,7 +70,8 @@ impl Renderer { let text_pipeline = text::Pipeline::new(&mut device, settings.default_font); let quad_pipeline = quad::Pipeline::new(&mut device); - let image_pipeline = image::Pipeline::new(&mut device); + let image_pipeline = crate::image::Pipeline::new(&mut device); + let triangle_pipeline = triangle::Pipeline::new(&mut device); Self { device, @@ -75,6 +79,7 @@ impl Renderer { quad_pipeline, image_pipeline, text_pipeline, + triangle_pipeline, } } @@ -252,6 +257,9 @@ impl Renderer { scale: [bounds.width, bounds.height], }); } + Primitive::Mesh2D(mesh) => { + layer.meshes.push(mesh.clone()); + } Primitive::Clip { bounds, offset, @@ -330,6 +338,24 @@ impl Renderer { ) { let bounds = layer.bounds * dpi; + if layer.meshes.len() > 0 { + let translated = transformation + * Transformation::translate( + -(layer.offset.x as f32) * dpi, + -(layer.offset.y as f32) * dpi, + ); + + self.triangle_pipeline.draw( + &mut self.device, + encoder, + target, + translated, + dpi, + &layer.meshes, + bounds, + ); + } + if layer.quads.len() > 0 { self.quad_pipeline.draw( &mut self.device, diff --git a/wgpu/src/renderer/widget.rs b/wgpu/src/renderer/widget.rs index daf35cbe..2c75413f 100644 --- a/wgpu/src/renderer/widget.rs +++ b/wgpu/src/renderer/widget.rs @@ -3,6 +3,7 @@ mod checkbox; mod column; mod container; mod image; +mod progress_bar; mod radio; mod row; mod scrollable; diff --git a/wgpu/src/renderer/widget/progress_bar.rs b/wgpu/src/renderer/widget/progress_bar.rs new file mode 100644 index 00000000..e9346fda --- /dev/null +++ b/wgpu/src/renderer/widget/progress_bar.rs @@ -0,0 +1,51 @@ +use crate::{Primitive, Renderer}; +use iced_native::{progress_bar, Background, Color, MouseCursor, Rectangle}; + +impl progress_bar::Renderer for Renderer { + const DEFAULT_HEIGHT: u16 = 30; + + fn draw( + &self, + bounds: Rectangle, + range: std::ops::RangeInclusive<f32>, + value: f32, + background: Option<Background>, + active_color: Option<Color>, + ) -> Self::Output { + let (range_start, range_end) = range.into_inner(); + let active_progress_width = bounds.width + * ((value - range_start) / (range_end - range_start).max(1.0)); + + let background = Primitive::Group { + primitives: vec![Primitive::Quad { + bounds: Rectangle { ..bounds }, + background: background + .unwrap_or(Background::Color([0.6, 0.6, 0.6].into())) + .into(), + border_radius: 5, + border_width: 0, + border_color: Color::TRANSPARENT, + }], + }; + + let active_progress = Primitive::Quad { + bounds: Rectangle { + width: active_progress_width, + ..bounds + }, + background: Background::Color( + active_color.unwrap_or([0.0, 0.95, 0.0].into()), + ), + border_radius: 5, + border_width: 0, + border_color: Color::TRANSPARENT, + }; + + ( + Primitive::Group { + primitives: vec![background, active_progress], + }, + MouseCursor::OutOfBounds, + ) + } +} |