Clamp image border radius to clip_bounds dimensions

Fixes #3100.
This commit is contained in:
Héctor Ramón Jiménez 2025-11-01 15:41:13 +01:00
parent b500cd85e7
commit b6a0adf2d9
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
3 changed files with 7 additions and 13 deletions

View file

@ -97,13 +97,13 @@ impl Example {
self.snap,
),
text!("Radius: {top_left:.2}/{top_right:.2}/{bottom_right:.2}/{bottom_left:.2}"),
slider(1.0..=100.0, top_left, Message::RadiusTopLeftChanged).step(0.01),
slider(1.0..=100.0, top_right, Message::RadiusTopRightChanged).step(0.01),
slider(1.0..=100.0, bottom_right, Message::RadiusBottomRightChanged)
slider(1.0..=200.0, top_left, Message::RadiusTopLeftChanged).step(0.01),
slider(1.0..=200.0, top_right, Message::RadiusTopRightChanged).step(0.01),
slider(1.0..=200.0, bottom_right, Message::RadiusBottomRightChanged)
.step(0.01),
slider(1.0..=100.0, bottom_left, Message::RadiusBottomLeftChanged)
slider(1.0..=200.0, bottom_left, Message::RadiusBottomLeftChanged)
.step(0.01),
slider(1.0..=10.0, self.border_width, Message::BorderWidthChanged)
slider(0.0..=10.0, self.border_width, Message::BorderWidthChanged)
.step(0.01),
text!("Shadow: {sx:.2}x{sy:.2}, {sr:.2}"),
slider(-100.0..=100.0, sx, Message::ShadowXOffsetChanged)

View file

@ -95,7 +95,7 @@ fn vs_main(input: VertexInput) -> VertexOutput {
}
out.position = globals.transform * out.position;
out.border_radius = globals.scale_factor * input.border_radius;
out.border_radius = globals.scale_factor * min(input.border_radius, vec4(min(input.clip_bounds.z, input.clip_bounds.w) / 2.0));
out.atlas = vec4(input.atlas_pos, input.atlas_pos + input.atlas_scale);
out.layer = input.layer;
out.opacity = input.opacity;

View file

@ -40,13 +40,7 @@ fn solid_vs_main(input: SolidVertexInput) -> SolidVertexOutput {
scale_snap = round(pos + scale + vec2(0.001, 0.001)) - pos - pos_snap - scale;
}
var min_border_radius = min(input.scale.x, input.scale.y) * 0.5;
var border_radius: vec4<f32> = vec4<f32>(
min(input.border_radius.x, min_border_radius),
min(input.border_radius.y, min_border_radius),
min(input.border_radius.z, min_border_radius),
min(input.border_radius.w, min_border_radius)
);
let border_radius = min(input.border_radius, vec4(min(input.scale.x, input.scale.y) / 2.0));
var transform: mat4x4<f32> = mat4x4<f32>(
vec4<f32>(scale.x + scale_snap.x + 1.0, 0.0, 0.0, 0.0),