Skip to content
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

add ClippingRect #1450

Merged
merged 8 commits into from
Feb 19, 2025
Merged

add ClippingRect #1450

merged 8 commits into from
Feb 19, 2025

Conversation

jagprog5
Copy link
Contributor

@jagprog5 jagprog5 commented Jan 2, 2025

in rust-sdl2, Rect can't have a zero width or height. This is instead represented with Option, where None covers this case.

The Canvas set_clip_rect and clip_rect function work with Option as well. However, for those functions None instead represents the lack of a clipping rect. This is distinctly differently, as clearing the clipping rect is like setting a Rect with an infinite area, and not a zero area (which would instead disable drawing).

This is value aliasing which can be corrected with a better type representation; it's impossible with current API to set a clipping rect with a zero area, which is a valid request that disables drawing. Since this has been fixed in sdl2, this MR keep in sync with upstream.

This is not backwards compatible. Thoughts?

@jagprog5
Copy link
Contributor Author

@Cobrand

@jagprog5
Copy link
Contributor Author

jagprog5 commented Feb 5, 2025

@AngryLawyer

pub fn clip_rect(&self) -> ClippingRect {
let clip_enabled = unsafe { sys::SDL_RenderIsClipEnabled(self.context.raw) };

if let sys::SDL_bool::SDL_FALSE = clip_enabled {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

binding is unnecessary here, just do if sys::SDL_bool::SDL_FALSE == clip_enabled {

Copy link
Contributor Author

@jagprog5 jagprog5 Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fails to compile

addressed: 76a697e

@Cobrand
Copy link
Member

Cobrand commented Feb 18, 2025

Definitely needs a changelog entry because it breaks the API.

@jagprog5
Copy link
Contributor Author

Definitely needs a changelog entry because it breaks the API.

@Cobrand there is a changelog entry in changelog.md. Am I missing somewhere else to put it?

@Cobrand
Copy link
Member

Cobrand commented Feb 19, 2025

Definitely needs a changelog entry because it breaks the API.

@Cobrand there is a changelog entry in changelog.md. Am I missing somewhere else to put it?

My bad I didn't see it in the initial commit, which is why I thought you didn't add one. Looks good now!

@Cobrand Cobrand merged commit 3486770 into Rust-SDL2:master Feb 19, 2025
16 of 17 checks passed
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.

2 participants