Fix crash when selections exceed the container's bounds
This commit is contained in:
@@ -54,7 +54,13 @@ impl PathBuilder {
|
||||
self.current = point;
|
||||
}
|
||||
|
||||
pub fn build(self, color: ColorU) -> Path {
|
||||
pub fn build(mut self, color: ColorU, clip_bounds: Option<RectF>) -> Path {
|
||||
if let Some(clip_bounds) = clip_bounds {
|
||||
self.bounds = self
|
||||
.bounds
|
||||
.intersection(clip_bounds)
|
||||
.unwrap_or(RectF::default());
|
||||
}
|
||||
Path {
|
||||
bounds: self.bounds,
|
||||
color,
|
||||
|
||||
@@ -181,6 +181,8 @@ impl Renderer {
|
||||
vertices.push(shaders::GPUIPathVertex {
|
||||
xy_position: (atlas_origin + xy_position).to_float2(),
|
||||
st_position: vertex.st_position.to_float2(),
|
||||
clip_rect_origin: atlas_origin.to_float2(),
|
||||
clip_rect_size: size.to_float2(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,4 +63,6 @@ typedef enum {
|
||||
typedef struct {
|
||||
vector_float2 xy_position;
|
||||
vector_float2 st_position;
|
||||
vector_float2 clip_rect_origin;
|
||||
vector_float2 clip_rect_size;
|
||||
} GPUIPathVertex;
|
||||
|
||||
@@ -218,21 +218,33 @@ fragment float4 sprite_fragment(
|
||||
return color;
|
||||
}
|
||||
|
||||
struct PathAtlasVertexOutput {
|
||||
float4 position [[position]];
|
||||
float2 st_position;
|
||||
float clip_rect_distance [[clip_distance]] [4];
|
||||
};
|
||||
|
||||
struct PathAtlasFragmentInput {
|
||||
float4 position [[position]];
|
||||
float2 st_position;
|
||||
};
|
||||
|
||||
vertex PathAtlasFragmentInput path_atlas_vertex(
|
||||
vertex PathAtlasVertexOutput path_atlas_vertex(
|
||||
uint vertex_id [[vertex_id]],
|
||||
constant GPUIPathVertex *vertices [[buffer(GPUIPathAtlasVertexInputIndexVertices)]],
|
||||
constant float2 *atlas_size [[buffer(GPUIPathAtlasVertexInputIndexAtlasSize)]]
|
||||
) {
|
||||
GPUIPathVertex v = vertices[vertex_id];
|
||||
float4 device_position = to_device_position(v.xy_position, *atlas_size);
|
||||
return PathAtlasFragmentInput {
|
||||
return PathAtlasVertexOutput {
|
||||
device_position,
|
||||
v.st_position,
|
||||
{
|
||||
v.xy_position.x - v.clip_rect_origin.x,
|
||||
v.clip_rect_origin.x + v.clip_rect_size.x - v.xy_position.x,
|
||||
v.xy_position.y - v.clip_rect_origin.y,
|
||||
v.clip_rect_origin.y + v.clip_rect_size.y - v.xy_position.y
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -156,7 +156,9 @@ impl Layer {
|
||||
}
|
||||
|
||||
fn push_path(&mut self, path: Path) {
|
||||
self.paths.push(path);
|
||||
if !path.bounds.is_empty() {
|
||||
self.paths.push(path);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn paths(&self) -> &[Path] {
|
||||
|
||||
Reference in New Issue
Block a user