From 1078eb7b45308f0f66b8d82dff67ea6d4a1ecc29 Mon Sep 17 00:00:00 2001 From: gurtt <6712553+gurtt@users.noreply.github.com> Date: Fri, 20 Dec 2024 15:44:35 -0800 Subject: [PATCH] Add drawTextInRect to Swift --- Sources/PlaydateKit/Core/Graphics.swift | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Sources/PlaydateKit/Core/Graphics.swift b/Sources/PlaydateKit/Core/Graphics.swift index a63f09c..5fe0589 100644 --- a/Sources/PlaydateKit/Core/Graphics.swift +++ b/Sources/PlaydateKit/Core/Graphics.swift @@ -598,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.