fix: support per-corner radius

also adjusts the radius by half of the outline thickness. I believe this is the radius at the center of the outline.
This commit is contained in:
Ashley Wulber 2025-09-24 17:50:23 -04:00 committed by Victoria Brekenfeld
parent b3aa10436a
commit c6320eec0c
5 changed files with 67 additions and 28 deletions

View file

@ -173,7 +173,7 @@ impl From<Id> for Key {
#[derive(PartialEq)]
struct IndicatorSettings {
thickness: u8,
radius: u8,
radius: [u8; 4],
alpha: f32,
color: [f32; 3],
}
@ -195,7 +195,7 @@ impl IndicatorShader {
key: impl Into<Key>,
mut element_geo: Rectangle<i32, Local>,
thickness: u8,
radius: u8,
radius: [u8; 4],
alpha: f32,
active_window_hint: [f32; 3],
) -> PixelShaderElement {
@ -208,8 +208,7 @@ impl IndicatorShader {
key,
element_geo,
thickness,
// FIXME, this seems to look OK, but I doubt it is correct
radius + thickness,
radius,
alpha,
active_window_hint,
)
@ -220,7 +219,7 @@ impl IndicatorShader {
key: impl Into<Key>,
geo: Rectangle<i32, Local>,
thickness: u8,
radius: u8,
radius: [u8; 4],
alpha: f32,
color: [f32; 3],
) -> PixelShaderElement {
@ -263,7 +262,15 @@ impl IndicatorShader {
[color[0] * alpha, color[1] * alpha, color[2] * alpha],
),
Uniform::new("thickness", thickness),
Uniform::new("radius", radius as f32),
Uniform::new(
"radius",
[
radius[0] as f32 + thickness / 2.,
radius[1] as f32 + thickness / 2.,
radius[2] as f32 + thickness / 2.,
radius[3] as f32 + thickness / 2.,
],
),
],
Kind::Unspecified,
);
@ -376,7 +383,7 @@ pub fn init_shaders(renderer: &mut GlesRenderer) -> Result<(), GlesError> {
&[
UniformName::new("color", UniformType::_3f),
UniformName::new("thickness", UniformType::_1f),
UniformName::new("radius", UniformType::_1f),
UniformName::new("radius", UniformType::_4f),
],
)?;
let rectangle_shader = renderer.compile_custom_pixel_shader(

View file

@ -8,10 +8,14 @@ varying vec2 v_coords;
uniform vec3 color;
uniform float thickness;
uniform float radius;
uniform vec4 radius;
float rounded_box(vec2 center, vec2 size, float radius) {
return length(max(abs(center) - size + radius, 0.0)) - radius;
float rounded_box(in vec2 p, in vec2 b, in vec4 r)
{
r.xy = (p.x > 0.0) ? r.xy : r.zw;
r.x = (p.y > 0.0) ? r.x : r.y;
vec2 q = abs(p) - b + r.x;
return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - r.x;
}
void main() {