feat: add text rendering functionality with custom font support#5
Merged
Conversation
Closed
There was a problem hiding this comment.
Pull request overview
This PR introduces text rendering to the 2D rendering API exposed to QuickJS, including a new Font class to allow loading and using custom fonts from JavaScript.
Changes:
- Added
FontandTextOptionstypes on the host side and exposedFontin the JS module exports. - Added a new
render.text.drawText(...)binding backed by raylibDrawTextPro. - Added a new example demonstrating custom font usage for text rendering.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/api/js_types.hpp | Adds host-side JSFont and JSTextOptions types to support text rendering configuration. |
| src/api/hostapi.hpp | Exports the new Font class from the vectorjs JS module. |
| src/api/api_context.cpp | Refactors 2D sub-objects and adds the text.drawText binding + option parsing. |
| src/api/api_classes.cpp | Registers the new Font QuickJS class and integrates it into class registration. |
| examples/2d/text.js | Adds a runnable example showcasing render.text.drawText and custom fonts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ering customization
…otation adjustment
Comment on lines
19
to
+23
| JSValue create_update_context_object(JSContext* ctx) { | ||
| return JS_NewObject(ctx); | ||
| } | ||
|
|
||
| JSValue create_draw_render_object(JSContext* ctx) { | ||
| Utils::ScopedJSValue render2d_obj(ctx, JS_NewObject(ctx)); | ||
|
|
||
| // --- FPS Binding --- | ||
| JS_SetPropertyStr(ctx, render2d_obj, "drawFPS", JS_NewCFunction(ctx, [](JSContext* c, JSValueConst, int argc, JSValueConst* argv) -> JSValue { | ||
| if (argc < 1) return JS_ThrowTypeError(c, "drawFPS requires a Vector2 position argument"); | ||
| const auto pos = Utils::get_opaque_or<JSVector2>(c, argv[0], js_vector2_class_id, {0, 0}); | ||
| ::DrawFPS(static_cast<int>(pos.x), static_cast<int>(pos.y)); | ||
| return JS_UNDEFINED; | ||
| }, "drawFPS", 1)); | ||
|
|
||
| // --- Shapes Sub-Object --- | ||
| static JSValue create_shapes_object(JSContext* ctx) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.