Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ In this file will be listed the changes, especially the breaking ones that one s
when upgrading from a version of rust-sdl2 to another.

### Next
[PR #1493](https://github.com/Rust-SDL2/rust-sdl2/pull/1493) Add `Rect::origin` and specifies origin location in `Rect::new`.

[PR #1472](https://github.com/Rust-SDL2/rust-sdl2/pull/1472) Add `Canvas::render_geometry`, `Canvas::render_geometry_raw` and an example that uses them both. Both these bindings use `SDL_RenderGeometryRaw`.

Expand Down
16 changes: 13 additions & 3 deletions src/sdl2/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::ptr;

/// The maximal integer value that can be used for rectangles.
///
/// This value is smaller than strictly needed, but is useful in ensuring that
/// This value is smaller than is strictly needed, but is useful in ensuring that
/// rect sizes will never have to be truncated when clamping.
pub fn max_int_value() -> u32 {
i32::MAX as u32 / 2
Expand Down Expand Up @@ -115,7 +115,7 @@ impl Hash for Rect {
}

impl Rect {
/// Creates a new rectangle from the given values.
/// Creates a new rectangle from the given values with an origin in the Upper Left.
///
/// The width and height are clamped to ensure that the right and bottom
/// sides of the rectangle does not exceed i32::MAX (the value
Expand Down Expand Up @@ -236,7 +236,17 @@ impl Rect {
pub fn bottom(&self) -> i32 {
self.raw.y + self.raw.h
}


/// Returns the origin of the rectangle (Top Left)
///
/// ```
/// use sdl2::rect::Rect;
/// assert_eq!(Rect::new(5, 5, 10, 10).origin(), (5,5));
/// ```
pub fn origin(&self) -> (i32, i32) {
(self.left(), self.top())
}

/// Shifts this rectangle to the left by `offset`.
///
/// # Example
Expand Down
Loading