Skip to content

Conversation

@pmasschelier
Copy link

This pull request adds rendering of separate radius for each corner of a RoundedRectangle for SDL2 and SDL3.
The radius of each corner is still limited by the half of the min(rect.w, rect.h) until this part of the layout is handled by clay.

    CLAY({ .id = CLAY_ID("OuterContainer"),
        .backgroundColor = {43, 41, 51, 255 },
        .layout = {
            .layoutDirection = CLAY_TOP_TO_BOTTOM,
            .sizing = layoutExpand,
            .padding = CLAY_PADDING_ALL(16),
            .childGap = 16
        }
    }) {
        RenderSquare(CLAY_CORNER_RADIUS(8));
        RenderSquare((Clay_CornerRadius){ 16.f, 0.f, 0.f, 0.f });
        RenderSquare((Clay_CornerRadius){ 0.f, 16.f, 0.f, 0.f });
        RenderSquare((Clay_CornerRadius){ 0.f, 0.f,16.f, 0.f });
        RenderSquare((Clay_CornerRadius){ 0.f, 0.f,0.f,16.f });
        RenderSquare((Clay_CornerRadius){ 0.f, 0.f,RECTANGLE_HEIGHT, 0.f });
        RenderSquare((Clay_CornerRadius){ RECTANGLE_HEIGHT, 10.f,20.f,0.f });
    }
image

@pmasschelier
Copy link
Author

I added the inline function SDL_Clay_AddQuadIndices for clarity
This image summarize which rectangle is drawn by the n-th call of SDL_Clay_AddQuadIndices
rounded

@pmasschelier
Copy link
Author

I believe that the version using shaders and SDF proposed in #488 would be more efficient but this would require an Clay_SDL_Initialize and Clay_SDL_Close like raylib for shader creation and deletion which would break the renderer API (but would standardize it).
However using shaders with the SDL3 is not trivial and I believe it is not supported by SDL2. Moreover assuming a backend (for instance by getting an OpenGL context and using glsl shaders) would break portability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant