Conversation
rizukirr
force-pushed
the
fix/raylib-border-radius-clamp
branch
from
May 22, 2026 09:49
020694f to
bd9e2f2
Compare
yuval-herman
added a commit
to yuval-herman/Planet-Wars-Runner
that referenced
this pull request
Aug 30, 2026
yuval-herman
added a commit
to yuval-herman/Planet-Wars-Runner
that referenced
this pull request
Aug 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
Clay_BorderRenderData.cornerRadiusfor any corner exceeds half the element's shorter side, the raylib renderer's border code draws aDrawRingarc with its center positioned outside the element's bounding box. The result is huge ring arcs that sweep across the rest of the layout.This shows up easily with a pill-shaped element using a sentinel radius (e.g.
999) plus a thin border — common pattern for chips, badges, toggle pills.Cause
In the
CLAY_RENDER_COMMAND_TYPE_BORDERcase, eachDrawRing(center, innerRadius, outerRadius, ...)is called with the raw pixel value ofconfig->cornerRadius.{topLeft,topRight,bottomLeft,bottomRight}. The center for each corner ring is computed asboundingBox.{corner} ± cornerRadius, so whencornerRadius > element_size, the center lands outside the element and the ring is drawn with that huge radius.DrawRingdoes no internal clamping, so the arc renders wherever the geometry lands.Repro
Any element where a corner radius exceeds half the element's shorter side, combined with a non-zero border width:
Before the patch this draws four arcs centered ~999px outside the element corners, painting curved lines across whatever else is on screen.
Fix
Compute
maxRadius = min(boundingBox.width, boundingBox.height) / 2.0fonce at the top of the border case, derive four clamped per-corner locals, and use those locals in everyDrawRectangleVandDrawRingcall in the block.Behavior is unchanged when radii already fit the element. Over-large radii now produce the maximum pill/circle shape that fits inside the bbox, which is the intuitive result.
Diff size: 17 insertions / 12 deletions, all inside the existing
CLAY_RENDER_COMMAND_TYPE_BORDERblock. No new helpers, no API change, no behavior change for existing well-formed inputs.Note on the rectangle path
The rectangle path (
CLAY_RENDER_COMMAND_TYPE_RECTANGLE) doesn't have this bug because it usesDrawRectangleRounded(rect, roundness, segments, color)with a normalizedroundness = (cornerRadius * 2) / min(width, height), and raylib'sDrawRectangleRoundedcapsroundnessat1.0internally. That's incidental to howDrawRectangleRoundedconsumes its input, not the result of explicit clamping in this file — the border path usesDrawRingwhich takes raw pixel radii and needs the clamp added here.Scope
cornerRadiusbefore emitting commands. Doing it there would benefit every renderer uniformly but is a larger change with cross-renderer impact — out of scope for this fix.Tested
RadiusAll(999) + 1px border) — cross-window arcs appeared exactly where the bug predicts.