Files
playdate-kit/Sources/PlaydateKit/Graphics/Structures/Graphics.Rect.swift
T
javier c5037dd716 Swift 6.4 migration and exhancements (#1)
This PR contains the work done to update the library and the attached example project to use the Swift 6.4 computer as a minimum supported version and also, to use the latest features introduced in it.

Reviewed-on: #1
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
2026-09-18 13:15:08 +00:00

44 lines
1.3 KiB
Swift

internal import CPlaydate
extension Graphics {
/// A rectangle, in pixels. Mirrors `LCDRect`: `right` and `bottom` are exclusive.
public struct Rect: Sendable {
public var left: Int
/// Exclusive.
public var right: Int
public var top: Int
/// Exclusive.
public var bottom: Int
public init(left: Int, right: Int, top: Int, bottom: Int) {
self.left = left
self.right = right
self.top = top
self.bottom = bottom
}
/// `(x, y)` is the upper-left corner.
public init(x: Int, y: Int, width: Int, height: Int) {
self.init(left: x, right: x + width, top: y, bottom: y + height)
}
init(_ rect: LCDRect) {
self.init(left: Int(rect.left), right: Int(rect.right),
top: Int(rect.top), bottom: Int(rect.bottom))
}
var cValue: LCDRect {
LCDRect(left: Int32(left), right: Int32(right),
top: Int32(top), bottom: Int32(bottom))
}
public var width: Int { right - left }
public var height: Int { bottom - top }
public func translated(dx: Int, dy: Int) -> Rect {
Rect(left: left + dx, right: right + dx, top: top + dy, bottom: bottom + dy)
}
}
}