-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: quad rendering including border only inside of the bounds #1843
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Good catch! Just a small detail.
tiny_skia/src/backend.rs
Outdated
// Make sure the border radius is not larger than the bounds | ||
let border_width = border_width | ||
.min(bounds.width / 2.0) | ||
.min(bounds.height / 2.0); | ||
|
||
// Offset the fill by the border width | ||
let path_bounds = Rectangle { | ||
x: bounds.x + border_width, | ||
y: bounds.y + border_width, | ||
width: bounds.width - 2.0 * border_width, | ||
height: bounds.height - 2.0 * border_width, | ||
}; | ||
// fill border radius is the border radius minus the border width | ||
let mut fill_border_radius = *border_radius; | ||
for radius in &mut fill_border_radius { | ||
*radius = (*radius - border_width / 2.0) | ||
.min(path_bounds.width / 2.0) | ||
.min(path_bounds.height / 2.0); | ||
} | ||
let path = rounded_rectangle(path_bounds, fill_border_radius); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expect the border to be rendered on top of the background like a border-box
in CSS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so I guess that would mean not offsetting the fill rectangle?
Hmm this might need some more testing. I'm going to mark it as a draft until i've tested it some more 😅. Specifically, if the border radius is smaller than half the border width, the path doesn't seem to work well. |
This seems to be working pretty well now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
It seems that border should not be drawn outside the quad bounds. For example, a slider handle with a large border radius will leave a trail of the border color when it is dragged, because it goes un-tracked in the damage.
This change also makes tiny-skia rendering of quads more consistent with the wgpu backend, which didn't seem to draw outside the bounds as far as i could tell with the same slider test.