From 470266f54069a1c9b6147026d018b437b6457f7b Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 5 Nov 2019 03:16:46 +0100 Subject: Add horizontal offset to `Primitive::Clip` --- wgpu/src/renderer.rs | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'wgpu/src/renderer.rs') diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs index fbc39327..ca4cbb58 100644 --- a/wgpu/src/renderer.rs +++ b/wgpu/src/renderer.rs @@ -1,7 +1,7 @@ use crate::{quad, Image, Primitive, Quad, Transformation}; use iced_native::{ renderer::Debugger, renderer::Windowed, Background, Color, Layout, - MouseCursor, Point, Rectangle, Widget, + MouseCursor, Point, Rectangle, Vector, Widget, }; use raw_window_handle::HasRawWindowHandle; @@ -44,17 +44,17 @@ pub struct Target { pub struct Layer<'a> { bounds: Rectangle, - y_offset: u32, + offset: Vector, quads: Vec, images: Vec, text: Vec>, } impl<'a> Layer<'a> { - pub fn new(bounds: Rectangle, y_offset: u32) -> Self { + pub fn new(bounds: Rectangle, offset: Vector) -> Self { Self { bounds, - y_offset, + offset, quads: Vec::new(), images: Vec::new(), text: Vec::new(), @@ -157,7 +157,7 @@ impl Renderer { width: u32::from(target.width), height: u32::from(target.height), }, - 0, + Vector::new(0, 0), )); self.draw_primitive(primitive, &mut layers); @@ -257,7 +257,10 @@ impl Renderer { border_radius, } => { layer.quads.push(Quad { - position: [bounds.x, bounds.y - layer.y_offset as f32], + position: [ + bounds.x - layer.offset.x as f32, + bounds.y - layer.offset.y as f32, + ], scale: [bounds.width, bounds.height], color: match background { Background::Color(color) => color.into_linear(), @@ -279,15 +282,15 @@ impl Renderer { } => { let clip_layer = Layer::new( Rectangle { - x: bounds.x as u32, - y: bounds.y as u32 - layer.y_offset, + x: bounds.x as u32 - layer.offset.x, + y: bounds.y as u32 - layer.offset.y, width: bounds.width as u32, height: bounds.height as u32, }, - layer.y_offset + offset, + layer.offset + *offset, ); - let new_layer = Layer::new(layer.bounds, layer.y_offset); + let new_layer = Layer::new(layer.bounds, layer.offset); layers.push(clip_layer); @@ -307,7 +310,10 @@ impl Renderer { target: &wgpu::TextureView, ) { let translated = transformation - * Transformation::translate(0.0, -(layer.y_offset as f32)); + * Transformation::translate( + -(layer.offset.x as f32), + -(layer.offset.y as f32), + ); if layer.quads.len() > 0 { self.quad_pipeline.draw( -- cgit