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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

jagprog5
Copy link

@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
Author

@Cobrand

@jagprog5
Copy link
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
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
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?

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