PanelContainer won't clip_content with corner_radius in 4.3beta1 (bug?)

Godot Version

4.3beta1

Question

I’ve seen examples of this in 4.2…
But I can’t get it to work as demonstrated when I try in 4.3beta1.

Is this a bug?

image



The way I’ve solved this temporarily is to use a corner radius shader.
But I think clip_content = true should work for this.

shader_type canvas_item;

uniform float corner_scale: hint_range(0., 1.) = 0.;

bool isOut(float x, float y) {
    return pow(x, 2.) + pow(y, 2.) > pow(corner_scale * .5, 2.);
}

void fragment() {
    float s = corner_scale * .5;

    if (
        (UV.x < s      && UV.y < s      && isOut(UV.x - s,      UV.y - s)) ||
        (UV.x < s      && UV.y > 1. - s && isOut(UV.x - s,      UV.y - 1. + s)) ||
        (UV.x > 1. - s && UV.y < s      && isOut(UV.x - 1. + s, UV.y - s)) ||
        (UV.x > 1. - s && UV.y > 1. - s && isOut(UV.x - 1. + s, UV.y - 1. + s))
    ) {
        COLOR.a = 0.;
    }
}

Control.clip_contents only clips the control’s rectangle. It does not take anything else into account.

You can try setting CanvasItem.clip_children of the PanelContainer to Clip + Draw instead.

2 Likes

Oh right now I see the difference between Control.clip_contents and CanvasItem.clip_children.

This kinda works, but will clip children at the outside of the border, rather than inside the border.

So, the solution seems then be between using this:

PanelContainer => corner_radius 40, border_width 8
  PanelContainer => clip_children ClipChildrenMode.CLIP_CHILDREN_AND_DRAW, corner_radius 32, # 40 - 8
    TextureButton

Or this:

PanelContainer => corner_radius 40, border_width 8
  TextureButton + CornerRadiusShader