fix: quad rendering including border only inside of the bounds#1843
Merged
hecrj merged 5 commits intoiced-rs:masterfrom Jun 27, 2023
Merged
fix: quad rendering including border only inside of the bounds#1843hecrj merged 5 commits intoiced-rs:masterfrom
hecrj merged 5 commits intoiced-rs:masterfrom
Conversation
hecrj
requested changes
May 11, 2023
Member
hecrj
left a comment
There was a problem hiding this comment.
Thanks. Good catch! Just a small detail.
tiny_skia/src/backend.rs
Outdated
Comment on lines
176
to
195
| // 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); |
Member
There was a problem hiding this comment.
I'd expect the border to be rendered on top of the background like a border-box in CSS.
Contributor
Author
There was a problem hiding this comment.
Ok, so I guess that would mean not offsetting the fill rectangle?
Contributor
Author
|
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. |
Contributor
Author
|
This seems to be working pretty well now. |
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.
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.