diff --git a/Sources/CPlaydate/include/CPlaydate.apinotes b/Sources/CPlaydate/include/CPlaydate.apinotes index 1f6fed02..67895749 100644 --- a/Sources/CPlaydate/include/CPlaydate.apinotes +++ b/Sources/CPlaydate/include/CPlaydate.apinotes @@ -40,6 +40,10 @@ Tags: EnumExtensibility: open - Name: SoundWaveform EnumExtensibility: open +- Name: PDTextWrappingMode + EnumExtensibility: open +- Name: PDTextAlignment + EnumExtensibility: open Enumerators: - Name: kButtonLeft SwiftName: left @@ -233,3 +237,15 @@ Enumerators: SwiftName: flippedY - Name: kBitmapFlippedXY SwiftName: flippedXY +- Name: kWrapClip + SwiftName: clip +- Name: kWrapCharacter + SwiftName: character +- Name: kWrapWord + SwiftName: word +- Name: kAlignTextLeft + SwiftName: left +- Name: kAlignTextCenter + SwiftName: center +- Name: kAlignTextRight + SwiftName: right diff --git a/Sources/PlaydateKit/Core/Graphics.swift b/Sources/PlaydateKit/Core/Graphics.swift index cc854832..5fe05891 100644 --- a/Sources/PlaydateKit/Core/Graphics.swift +++ b/Sources/PlaydateKit/Core/Graphics.swift @@ -229,6 +229,9 @@ public enum Graphics { public typealias StringEncoding = PDStringEncoding public typealias PolygonFillRule = LCDPolygonFillRule public typealias SolidColor = LCDSolidColor + + public typealias TextWrap = PDTextWrappingMode + public typealias TextAlignment = PDTextAlignment public class BitmapTable { // MARK: Lifecycle @@ -595,6 +598,28 @@ public enum Graphics { CInt(point.y) )) } + + /// Draws the text in the given rectangle using the provided options. If no font has + /// been set with setFont, the default system font Asheville Sans 14 Light is used. + public static func drawTextInRect( + _ text: String, + in rect: Rect, + wrap: TextWrap = .clip, + aligned: TextAlignment = .left + ) { + graphics.drawTextInRect.unsafelyUnwrapped( + text, + text.utf8.count, + .kUTF8Encoding, + CInt(rect.x), + CInt(rect.y), + CInt(rect.width), + CInt(rect.height), + wrap, + aligned + ) + } + /// Draws an ellipse inside the rectangle `rect` of width `lineWidth` (inset from the rectangle bounds). /// If `startAngle` != `endAngle`, this draws an arc between the given angles.