Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple procedural text rendering API
This adds `rive::RawText` can be used to append text runs with different styles and set layout rules for the text. It's pretty full featured. Simple example (trimmed for brevity): ``` auto roboto = loadFont("RobotoFlex.ttf"); // setup text object rive::RawText text(RiveFactory()); text.append("Hello world! ", roboto); // later during rendering text.render(renderer); ``` <img width="538" alt="CleanShot 2024-07-25 at 21 59 43@2x" src="https://github.com/user-attachments/assets/7c421cca-ec91-4978-b358-7ba5d457746a"> A few more complex examples: ``` auto roboto = loadFont("RobotoFlex.ttf"); auto montserrat = loadFont("Montserrat.ttf"); rive::RawText text(RiveFactory()); text.append("Hello world! ", roboto, 72.0f); text.append("Moon's cool too. ", montserrat, 64.0f); ``` <img width="491" alt="CleanShot 2024-07-25 at 22 01 28@2x" src="https://github.com/user-attachments/assets/06272869-11dc-43f3-a7a3-6bde7a226238"> Because `RawText` represents one contiguous styled block of text, you can apply rules like overflow, sizing, alignment, different paint, etc: ``` rive::RawText text(RiveFactory()); text.maxWidth(450.0f); text.maxHeight(330.0f); text.sizing(rive::TextSizing::fixed); text.overflow(rive::TextOverflow::ellipsis); text.append("Hello world! ", roboto, 72.0f); text.append("Moon's cool too. ", montserrat, 64.0f); auto paint = RiveFactory()->makeRenderPaint(); paint->color(0x88ff0000); text.append("Mars is red.", roboto, 72.0f, paint); ``` <img width="401" alt="CleanShot 2024-07-25 at 22 03 01@2x" src="https://github.com/user-attachments/assets/bf03d1e6-c966-4834-92ab-20d9918186ad"> You can also supply an override paint during rendering to force paint the whole thing with one color: ``` auto paint = RiveFactory()->makeRenderPaint(); paint->color(0xff00ff00); text.render(renderer, paint); ``` <img width="321" alt="CleanShot 2024-07-25 at 22 04 44@2x" src="https://github.com/user-attachments/assets/eaaf2983-4cd5-45e0-96fd-5edc72da211a"> Diffs= a56419984 Simple procedural text rendering API (#7701) Co-authored-by: Chris Dalton <[email protected]> Co-authored-by: Luigi Rosso <[email protected]>
- Loading branch information