From 5929b267221757658eec6d29002a45c53128fb3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 28 May 2025 20:47:23 +0200 Subject: [PATCH] Apply snap distance to `Mesh` primitives in `iced_wgpu` --- wgpu/src/triangle.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index a3f850dd..78d16e5a 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -2,7 +2,7 @@ mod msaa; use crate::Buffer; -use crate::core::{Rectangle, Size, Transformation}; +use crate::core::{Point, Rectangle, Size, Transformation, Vector}; use crate::graphics::Antialiasing; use crate::graphics::mesh::{self, Mesh}; @@ -445,10 +445,25 @@ impl Layer { let mut index_offset = 0; for mesh in meshes { - let indices = mesh.indices(); + let clip_bounds = mesh.clip_bounds() * transformation; + let snap_distance = clip_bounds + .snap() + .map(|snapped_bounds| { + Point::new(snapped_bounds.x as f32, snapped_bounds.y as f32) + - clip_bounds.position() + }) + .unwrap_or(Vector::ZERO); - let uniforms = - Uniforms::new(transformation * mesh.transformation()); + let uniforms = Uniforms::new( + transformation + * mesh.transformation() + * Transformation::translate( + snap_distance.x, + snap_distance.y, + ), + ); + + let indices = mesh.indices(); index_offset += self.index_buffer.write( device,