Skip to content

Commit d647f51

Browse files
committed
Fix up primitives/grid
1 parent e945b8a commit d647f51

File tree

4 files changed

+329
-91
lines changed

4 files changed

+329
-91
lines changed

crates/bevy_gizmos/src/grid.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ use bevy_color::LinearRgba;
88
use bevy_math::{Quat, UVec2, Vec2, Vec3};
99

1010
/// A builder returned by [`Gizmos::grid`] and [`Gizmos::grid_2d`]
11-
pub struct GridBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
12-
gizmos: &'a mut Gizmos<'w, 's, T>,
11+
pub struct GridBuilder<'a, 'w, 's, Config, Clear>
12+
where
13+
Config: GizmoConfigGroup,
14+
Clear: 'static + Send + Sync,
15+
{
16+
gizmos: &'a mut Gizmos<'w, 's, Config, Clear>,
1317
position: Vec3,
1418
rotation: Quat,
1519
spacing: Vec2,
@@ -19,7 +23,11 @@ pub struct GridBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
1923
color: LinearRgba,
2024
}
2125

22-
impl<T: GizmoConfigGroup> GridBuilder<'_, '_, '_, T> {
26+
impl<Config, Clear> GridBuilder<'_, '_, '_, Config, Clear>
27+
where
28+
Config: GizmoConfigGroup,
29+
Clear: 'static + Send + Sync,
30+
{
2331
/// Skews the grid by `tan(skew)` in the x direction.
2432
/// `skew` is in radians
2533
pub fn skew_x(mut self, skew: f32) -> Self {
@@ -47,7 +55,11 @@ impl<T: GizmoConfigGroup> GridBuilder<'_, '_, '_, T> {
4755
}
4856
}
4957

50-
impl<T: GizmoConfigGroup> Drop for GridBuilder<'_, '_, '_, T> {
58+
impl<Config, Clear> Drop for GridBuilder<'_, '_, '_, Config, Clear>
59+
where
60+
Config: GizmoConfigGroup,
61+
Clear: 'static + Send + Sync,
62+
{
5163
/// Draws a grid, by drawing lines with the stored [`Gizmos`]
5264
fn drop(&mut self) {
5365
if !self.gizmos.enabled {
@@ -103,7 +115,11 @@ impl<T: GizmoConfigGroup> Drop for GridBuilder<'_, '_, '_, T> {
103115
}
104116
}
105117

106-
impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
118+
impl<'w, 's, Config, Clear> Gizmos<'w, 's, Config, Clear>
119+
where
120+
Config: GizmoConfigGroup,
121+
Clear: 'static + Send + Sync,
122+
{
107123
/// Draw a 2D grid in 3D.
108124
///
109125
/// This should be called for each frame the grid needs to be rendered.
@@ -147,7 +163,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
147163
cell_count: UVec2,
148164
spacing: Vec2,
149165
color: impl Into<LinearRgba>,
150-
) -> GridBuilder<'_, 'w, 's, T> {
166+
) -> GridBuilder<'_, 'w, 's, Config, Clear> {
151167
GridBuilder {
152168
gizmos: self,
153169
position,
@@ -203,7 +219,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
203219
cell_count: UVec2,
204220
spacing: Vec2,
205221
color: impl Into<LinearRgba>,
206-
) -> GridBuilder<'_, 'w, 's, T> {
222+
) -> GridBuilder<'_, 'w, 's, Config, Clear> {
207223
GridBuilder {
208224
gizmos: self,
209225
position: position.extend(0.),

crates/bevy_gizmos/src/primitives/dim2.rs

Lines changed: 104 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ pub trait GizmoPrimitive2d<P: Primitive2d> {
3838

3939
// direction 2d
4040

41-
impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Dir2> for Gizmos<'w, 's, T> {
41+
impl<'w, 's, Config, Clear> GizmoPrimitive2d<Dir2> for Gizmos<'w, 's, Config, Clear>
42+
where
43+
Config: GizmoConfigGroup,
44+
Clear: 'static + Send + Sync,
45+
{
4246
type Output<'a> = () where Self : 'a;
4347

4448
fn primitive_2d(
@@ -62,7 +66,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Dir2> for Gizmos<'w, 's, T> {
6266

6367
// circle 2d
6468

65-
impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Circle> for Gizmos<'w, 's, T> {
69+
impl<'w, 's, Config, Clear> GizmoPrimitive2d<Circle> for Gizmos<'w, 's, Config, Clear>
70+
where
71+
Config: GizmoConfigGroup,
72+
Clear: 'static + Send + Sync,
73+
{
6674
type Output<'a> = () where Self: 'a;
6775

6876
fn primitive_2d(
@@ -82,7 +90,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Circle> for Gizmos<'w, 's, T>
8290

8391
// ellipse 2d
8492

85-
impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Ellipse> for Gizmos<'w, 's, T> {
93+
impl<'w, 's, Config, Clear> GizmoPrimitive2d<Ellipse> for Gizmos<'w, 's, Config, Clear>
94+
where
95+
Config: GizmoConfigGroup,
96+
Clear: 'static + Send + Sync,
97+
{
8698
type Output<'a> = () where Self: 'a;
8799

88100
fn primitive_2d(
@@ -102,7 +114,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Ellipse> for Gizmos<'w, 's, T
102114

103115
// capsule 2d
104116

105-
impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Capsule2d> for Gizmos<'w, 's, T> {
117+
impl<'w, 's, Config, Clear> GizmoPrimitive2d<Capsule2d> for Gizmos<'w, 's, Config, Clear>
118+
where
119+
Config: GizmoConfigGroup,
120+
Clear: 'static + Send + Sync,
121+
{
106122
type Output<'a> = () where Self: 'a;
107123

108124
fn primitive_2d(
@@ -168,8 +184,12 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Capsule2d> for Gizmos<'w, 's,
168184
// line 2d
169185
//
170186
/// Builder for configuring the drawing options of [`Line2d`].
171-
pub struct Line2dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
172-
gizmos: &'a mut Gizmos<'w, 's, T>,
187+
pub struct Line2dBuilder<'a, 'w, 's, Config, Clear>
188+
where
189+
Config: GizmoConfigGroup,
190+
Clear: 'static + Send + Sync,
191+
{
192+
gizmos: &'a mut Gizmos<'w, 's, Config, Clear>,
173193

174194
direction: Dir2, // Direction of the line
175195

@@ -180,16 +200,24 @@ pub struct Line2dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
180200
draw_arrow: bool, // decides whether to indicate the direction of the line with an arrow
181201
}
182202

183-
impl<T: GizmoConfigGroup> Line2dBuilder<'_, '_, '_, T> {
203+
impl<Config, Clear> Line2dBuilder<'_, '_, '_, Config, Clear>
204+
where
205+
Config: GizmoConfigGroup,
206+
Clear: 'static + Send + Sync,
207+
{
184208
/// Set the drawing mode of the line (arrow vs. plain line)
185209
pub fn draw_arrow(mut self, is_enabled: bool) -> Self {
186210
self.draw_arrow = is_enabled;
187211
self
188212
}
189213
}
190214

191-
impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Line2d> for Gizmos<'w, 's, T> {
192-
type Output<'a> = Line2dBuilder<'a, 'w, 's, T> where Self: 'a;
215+
impl<'w, 's, Config, Clear> GizmoPrimitive2d<Line2d> for Gizmos<'w, 's, Config, Clear>
216+
where
217+
Config: GizmoConfigGroup,
218+
Clear: 'static + Send + Sync,
219+
{
220+
type Output<'a> = Line2dBuilder<'a, 'w, 's, Config, Clear> where Self: 'a;
193221

194222
fn primitive_2d(
195223
&mut self,
@@ -209,7 +237,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Line2d> for Gizmos<'w, 's, T>
209237
}
210238
}
211239

212-
impl<T: GizmoConfigGroup> Drop for Line2dBuilder<'_, '_, '_, T> {
240+
impl<Config, Clear> Drop for Line2dBuilder<'_, '_, '_, Config, Clear>
241+
where
242+
Config: GizmoConfigGroup,
243+
Clear: 'static + Send + Sync,
244+
{
213245
fn drop(&mut self) {
214246
if !self.gizmos.enabled {
215247
return;
@@ -239,7 +271,11 @@ impl<T: GizmoConfigGroup> Drop for Line2dBuilder<'_, '_, '_, T> {
239271

240272
// plane 2d
241273

242-
impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Plane2d> for Gizmos<'w, 's, T> {
274+
impl<'w, 's, Config, Clear> GizmoPrimitive2d<Plane2d> for Gizmos<'w, 's, Config, Clear>
275+
where
276+
Config: GizmoConfigGroup,
277+
Clear: 'static + Send + Sync,
278+
{
243279
type Output<'a> = () where Self: 'a;
244280

245281
fn primitive_2d(
@@ -289,8 +325,12 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Plane2d> for Gizmos<'w, 's, T
289325
// segment 2d
290326

291327
/// Builder for configuring the drawing options of [`Segment2d`].
292-
pub struct Segment2dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
293-
gizmos: &'a mut Gizmos<'w, 's, T>,
328+
pub struct Segment2dBuilder<'a, 'w, 's, Config, Clear>
329+
where
330+
Config: GizmoConfigGroup,
331+
Clear: 'static + Send + Sync,
332+
{
333+
gizmos: &'a mut Gizmos<'w, 's, Config, Clear>,
294334

295335
direction: Dir2, // Direction of the line segment
296336
half_length: f32, // Half-length of the line segment
@@ -302,16 +342,24 @@ pub struct Segment2dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
302342
draw_arrow: bool, // decides whether to draw just a line or an arrow
303343
}
304344

305-
impl<T: GizmoConfigGroup> Segment2dBuilder<'_, '_, '_, T> {
345+
impl<Config, Clear> Segment2dBuilder<'_, '_, '_, Config, Clear>
346+
where
347+
Config: GizmoConfigGroup,
348+
Clear: 'static + Send + Sync,
349+
{
306350
/// Set the drawing mode of the line (arrow vs. plain line)
307351
pub fn draw_arrow(mut self, is_enabled: bool) -> Self {
308352
self.draw_arrow = is_enabled;
309353
self
310354
}
311355
}
312356

313-
impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Segment2d> for Gizmos<'w, 's, T> {
314-
type Output<'a> = Segment2dBuilder<'a, 'w, 's, T> where Self: 'a;
357+
impl<'w, 's, Config, Clear> GizmoPrimitive2d<Segment2d> for Gizmos<'w, 's, Config, Clear>
358+
where
359+
Config: GizmoConfigGroup,
360+
Clear: 'static + Send + Sync,
361+
{
362+
type Output<'a> = Segment2dBuilder<'a, 'w, 's, Config, Clear> where Self: 'a;
315363

316364
fn primitive_2d(
317365
&mut self,
@@ -334,7 +382,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Segment2d> for Gizmos<'w, 's,
334382
}
335383
}
336384

337-
impl<T: GizmoConfigGroup> Drop for Segment2dBuilder<'_, '_, '_, T> {
385+
impl<Config, Clear> Drop for Segment2dBuilder<'_, '_, '_, Config, Clear>
386+
where
387+
Config: GizmoConfigGroup,
388+
Clear: 'static + Send + Sync,
389+
{
338390
fn drop(&mut self) {
339391
if !self.gizmos.enabled {
340392
return;
@@ -354,8 +406,11 @@ impl<T: GizmoConfigGroup> Drop for Segment2dBuilder<'_, '_, '_, T> {
354406

355407
// polyline 2d
356408

357-
impl<'w, 's, const N: usize, T: GizmoConfigGroup> GizmoPrimitive2d<Polyline2d<N>>
358-
for Gizmos<'w, 's, T>
409+
impl<'w, 's, const N: usize, Config, Clear> GizmoPrimitive2d<Polyline2d<N>>
410+
for Gizmos<'w, 's, Config, Clear>
411+
where
412+
Config: GizmoConfigGroup,
413+
Clear: 'static + Send + Sync,
359414
{
360415
type Output<'a> = () where Self: 'a;
361416

@@ -383,7 +438,11 @@ impl<'w, 's, const N: usize, T: GizmoConfigGroup> GizmoPrimitive2d<Polyline2d<N>
383438

384439
// boxed polyline 2d
385440

386-
impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<BoxedPolyline2d> for Gizmos<'w, 's, T> {
441+
impl<'w, 's, Config, Clear> GizmoPrimitive2d<BoxedPolyline2d> for Gizmos<'w, 's, Config, Clear>
442+
where
443+
Config: GizmoConfigGroup,
444+
Clear: 'static + Send + Sync,
445+
{
387446
type Output<'a> = () where Self: 'a;
388447

389448
fn primitive_2d(
@@ -410,7 +469,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<BoxedPolyline2d> for Gizmos<'
410469

411470
// triangle 2d
412471

413-
impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Triangle2d> for Gizmos<'w, 's, T> {
472+
impl<'w, 's, Config, Clear> GizmoPrimitive2d<Triangle2d> for Gizmos<'w, 's, Config, Clear>
473+
where
474+
Config: GizmoConfigGroup,
475+
Clear: 'static + Send + Sync,
476+
{
414477
type Output<'a> = () where Self: 'a;
415478

416479
fn primitive_2d(
@@ -431,7 +494,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Triangle2d> for Gizmos<'w, 's
431494

432495
// rectangle 2d
433496

434-
impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Rectangle> for Gizmos<'w, 's, T> {
497+
impl<'w, 's, Config, Clear> GizmoPrimitive2d<Rectangle> for Gizmos<'w, 's, Config, Clear>
498+
where
499+
Config: GizmoConfigGroup,
500+
Clear: 'static + Send + Sync,
501+
{
435502
type Output<'a> = () where Self: 'a;
436503

437504
fn primitive_2d(
@@ -459,8 +526,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Rectangle> for Gizmos<'w, 's,
459526

460527
// polygon 2d
461528

462-
impl<'w, 's, const N: usize, T: GizmoConfigGroup> GizmoPrimitive2d<Polygon<N>>
463-
for Gizmos<'w, 's, T>
529+
impl<'w, 's, const N: usize, Config, Clear> GizmoPrimitive2d<Polygon<N>>
530+
for Gizmos<'w, 's, Config, Clear>
531+
where
532+
Config: GizmoConfigGroup,
533+
Clear: 'static + Send + Sync,
464534
{
465535
type Output<'a> = () where Self: 'a;
466536

@@ -498,7 +568,11 @@ impl<'w, 's, const N: usize, T: GizmoConfigGroup> GizmoPrimitive2d<Polygon<N>>
498568

499569
// boxed polygon 2d
500570

501-
impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<BoxedPolygon> for Gizmos<'w, 's, T> {
571+
impl<'w, 's, Config, Clear> GizmoPrimitive2d<BoxedPolygon> for Gizmos<'w, 's, Config, Clear>
572+
where
573+
Config: GizmoConfigGroup,
574+
Clear: 'static + Send + Sync,
575+
{
502576
type Output<'a> = () where Self: 'a;
503577

504578
fn primitive_2d(
@@ -533,7 +607,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<BoxedPolygon> for Gizmos<'w,
533607

534608
// regular polygon 2d
535609

536-
impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<RegularPolygon> for Gizmos<'w, 's, T> {
610+
impl<'w, 's, Config, Clear> GizmoPrimitive2d<RegularPolygon> for Gizmos<'w, 's, Config, Clear>
611+
where
612+
Config: GizmoConfigGroup,
613+
Clear: 'static + Send + Sync,
614+
{
537615
type Output<'a> = () where Self: 'a;
538616

539617
fn primitive_2d(

0 commit comments

Comments
 (0)