← ziglang.inraylib-zigGitHub

text

Fonts, text drawing, codepoints and strings. 59 functions, from raylib's rtext.

Font loading/unloading functions

rl.loadFontEx

Load font from file with defined codepoints and generation size, use NULL for codepoints and 0 for codepointCount to load the default character set, font size is provided in pixels height

Zigfn loadFontEx(fileName: [:0]const u8, fontSize: i32, codepoints: ?[]const i32) error{LoadFailed}!Font
CFont LoadFontEx(const char *fileName, int fontSize, const int *codepoints, int codepointCount);

Used in textures_image_text, text_font_filters, text_font_loading, text_unicode_ranges, text_3d_drawing, text_codepoints_loading.

rl.loadFontFromImage

Load font from Image (XNA style)

Zigfn loadFontFromImage(image: Image, key: Color, firstChar: i32) error{LoadFailed}!Font
CFont LoadFontFromImage(Image image, Color key, int firstChar);

rl.loadFontFromMemory

Load font from memory buffer, fileType refers to extension: i.e. '.ttf'

Zigfn loadFontFromMemory(fileType: [:0]const u8, fileData: []const u8, fontSize: i32, codepoints: ?[]const i32) error{LoadFailed}!Font
CFont LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int dataSize, int fontSize, const int *codepoints, int codepointCount);

rl.isFontValid

Check if font is valid (font data loaded, WARNING: GPU texture not checked)

Zigfn isFontValid(font: Font) bool
Cbool IsFontValid(Font font);

rl.loadFontData

Load font data for further use

Load font data for further use. Free with `unloadFontData`.

Zigfn loadFontData(fileData: []const u8, fontSize: i32, codepoints: ?[]const i32, @"type": FontType) error{LoadFailed}![]GlyphInfo
CGlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSize, const int *codepoints, int codepointCount, int type, int *glyphCount);

Used in text_font_sdf.

rl.genImageFontAtlas

Generate image font atlas using chars info

Generate image font atlas using chars info. `glyphRecs` receives a raylib-allocated rectangle array (typically `&font.recs`; freed by `unloadFont`, or with `memFree`).

Zigfn genImageFontAtlas(glyphs: []const GlyphInfo, glyphRecs: *?[*]Rectangle, fontSize: i32, padding: i32, packMethod: i32) Image
CImage GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyphCount, int fontSize, int padding, int packMethod);

Used in text_font_sdf.

rl.unloadFontData

Unload font chars info data (RAM)

Zigfn unloadFontData(glyphs: []GlyphInfo) void
Cvoid UnloadFontData(GlyphInfo *glyphs, int glyphCount);

rl.exportFontAsCode

Export font as code file, returns true on success

Zigfn exportFontAsCode(font: Font, fileName: [:0]const u8) bool
Cbool ExportFontAsCode(Font font, const char *fileName);

Text drawing functions

rl.drawTextPro

Draw text using Font and pro parameters (rotation)

Zigfn drawTextPro(font: Font, text: [:0]const u8, position: Vector2, origin: Vector2, rotation: f32, fontSize: f32, spacing: f32, tint: Color) void
Cvoid DrawTextPro(Font font, const char *text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint);

rl.drawTextCodepoints

Draw multiple characters (codepoint)

Zigfn drawTextCodepoints(font: Font, codepoints: []const i32, position: Vector2, fontSize: f32, spacing: f32, tint: Color) void
Cvoid DrawTextCodepoints(Font font, const int *codepoints, int codepointCount, Vector2 position, float fontSize, float spacing, Color tint);

Text font info functions

rl.measureTextCodepoints

Measure string size for an existing array of codepoints for Font

Zigfn measureTextCodepoints(font: Font, codepoints: []const i32, fontSize: f32, spacing: f32) Vector2
CVector2 MeasureTextCodepoints(Font font, const int *codepoints, int length, float fontSize, float spacing);

rl.getGlyphInfo

Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found

Zigfn getGlyphInfo(font: Font, codepoint: i32) GlyphInfo
CGlyphInfo GetGlyphInfo(Font font, int codepoint);

rl.getGlyphAtlasRec

Get glyph rectangle in font atlas for a codepoint (unicode character), fallback to '?' if not found

Zigfn getGlyphAtlasRec(font: Font, codepoint: i32) Rectangle
CRectangle GetGlyphAtlasRec(Font font, int codepoint);

Text codepoints management functions (unicode characters)

rl.loadUTF8

Load UTF-8 text encoded from codepoints array

Load UTF-8 text encoded from codepoints array. Free with `unloadUTF8`.

Zigfn loadUTF8(codepoints: []const i32) error{LoadFailed}![:0]u8
Cchar *LoadUTF8(const int *codepoints, int length);

rl.unloadUTF8

Unload UTF-8 text encoded from codepoints array

Unload UTF-8 text encoded from codepoints array.

Zigfn unloadUTF8(text: [:0]u8) void
Cvoid UnloadUTF8(char *text);

rl.loadCodepoints

Load all codepoints from a UTF-8 text string, codepoints count returned by parameter

Load all codepoints from a UTF-8 text string. Free with `unloadCodepoints`.

Zigfn loadCodepoints(text: [:0]const u8) error{LoadFailed}![]i32
Cint *LoadCodepoints(const char *text, int *count);

Used in textures_image_text, text_codepoints_loading.

rl.getCodepoint

Get next codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure

Get next codepoint in a UTF-8 encoded string and its size in bytes; 0x3f('?') on failure.

Zigfn getCodepoint(text: [:0]const u8) CodepointResult
Cint GetCodepoint(const char *text, int *codepointSize);

Used in text_rectangle_bounds, text_unicode_emojis, text_3d_drawing.

rl.getCodepointNext

Get next codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure

Get next codepoint in a UTF-8 encoded string and its size in bytes; 0x3f('?') on failure.

Zigfn getCodepointNext(text: [:0]const u8) CodepointResult
Cint GetCodepointNext(const char *text, int *codepointSize);

Used in text_codepoints_loading, text_inline_styling.

rl.getCodepointPrevious

Get previous codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure

Get previous codepoint in a UTF-8 encoded string and its size in bytes; 0x3f('?') on failure.

Zigfn getCodepointPrevious(text: [:0]const u8) CodepointResult
Cint GetCodepointPrevious(const char *text, int *codepointSize);

Used in text_codepoints_loading.

rl.codepointToUTF8

Encode one codepoint into UTF-8 byte array (array length returned as parameter)

Encode one codepoint into UTF-8 bytes (slice into a static buffer).

Zigfn codepointToUTF8(codepoint: i32) []const u8
Cconst char *CodepointToUTF8(int codepoint, int *utf8Size);

Text strings management functions (no UTF-8 strings, only byte chars)

rl.loadTextLines

Load text as separate lines ('\n')

Load text as separate lines ('\n'). Free with `unloadTextLines`.

Zigfn loadTextLines(text: [:0]const u8) error{LoadFailed}![][*:0]u8
Cchar **LoadTextLines(const char *text, int *count);

Used in core_text_file_loading.

rl.unloadTextLines

Unload text lines

Unload text lines loaded with `loadTextLines`.

Zigfn unloadTextLines(lines: [][*:0]u8) void
Cvoid UnloadTextLines(char **text, int lineCount);

Used in core_text_file_loading.

rl.textCopy

Copy one string to another, returns bytes copied

Copy one string to another, returns bytes copied. `dst` must be large enough for `src` plus its terminator (C semantics, unchecked).

Zigfn textCopy(dst: [*]u8, src: [:0]const u8) i32
Cint TextCopy(char *dst, const char *src);

Used in core_drop_files, core_directory_files, models_skybox_rendering.

rl.textIsEqual

Check if two text strings are equal

Zigfn textIsEqual(text1: [:0]const u8, text2: [:0]const u8) bool
Cbool TextIsEqual(const char *text1, const char *text2);

Used in text_unicode_emojis.

rl.textLength

Get text length, checks for '\0' ending

Zigfn textLength(text: [:0]const u8) u32
Cunsigned int TextLength(const char *text);

rl.textFormat

Text formatting with variables (sprintf() style)

Text formatting with variables (std.fmt syntax). Like raylib's TextFormat, the result lives in one of a few internal static buffers: it is valid until the same buffer is reused several calls later. Truncates at 1023 bytes.

Zigfn textFormat(comptime format: []const u8, args: anytype) [:0]const u8
Cconst char *TextFormat(const char *text, ...);

Used in core_delta_time, core_input_mouse_wheel, core_input_gamepad, core_input_multitouch, core_input_gestures_testbed, core_2d_camera_mouse_zoom and 101 more.

rl.textRemoveSpaces

Remove text spaces, concat words

Zigfn textRemoveSpaces(text: [:0]const u8) [:0]const u8
Cconst char *TextRemoveSpaces(const char *text);

rl.getTextBetween

Get text between two strings

Zigfn getTextBetween(text: [:0]const u8, begin: [:0]const u8, end: [:0]const u8) [:0]const u8
Cchar *GetTextBetween(const char *text, const char *begin, const char *end);

rl.textReplace

Replace text string with new string

Zigfn textReplace(text: [:0]const u8, search: [:0]const u8, replacement: [:0]const u8) [:0]const u8
Cchar *TextReplace(const char *text, const char *search, const char *replacement);

rl.textReplaceAlloc

Replace text string with new string, memory must be MemFree()

Caller owns the result: free with `memFree`.

Zigfn textReplaceAlloc(text: [:0]const u8, search: [:0]const u8, replacement: [:0]const u8) ?[:0]u8
Cchar *TextReplaceAlloc(const char *text, const char *search, const char *replacement);

rl.textReplaceBetween

Replace text between two specific strings

Zigfn textReplaceBetween(text: [:0]const u8, begin: [:0]const u8, end: [:0]const u8, replacement: [:0]const u8) [:0]const u8
Cchar *TextReplaceBetween(const char *text, const char *begin, const char *end, const char *replacement);

rl.textReplaceBetweenAlloc

Replace text between two specific strings, memory must be MemFree()

Caller owns the result: free with `memFree`.

Zigfn textReplaceBetweenAlloc(text: [:0]const u8, begin: [:0]const u8, end: [:0]const u8, replacement: [:0]const u8) ?[:0]u8
Cchar *TextReplaceBetweenAlloc(const char *text, const char *begin, const char *end, const char *replacement);

rl.textInsert

Insert text in a defined byte position

Zigfn textInsert(text: [:0]const u8, insert: [:0]const u8, position: i32) [:0]const u8
Cchar *TextInsert(const char *text, const char *insert, int position);

rl.textInsertAlloc

Insert text in a defined byte position, memory must be MemFree()

Caller owns the result: free with `memFree`.

Zigfn textInsertAlloc(text: [:0]const u8, insert: [:0]const u8, position: i32) ?[:0]u8
Cchar *TextInsertAlloc(const char *text, const char *insert, int position);

rl.textJoin

Join text strings with delimiter

Join text strings with delimiter (static memory).

Zigfn textJoin(textList: []const [*:0]const u8, delimiter: [:0]const u8) [:0]const u8
Cchar *TextJoin(char **textList, int count, const char *delimiter);

Used in models_animation_blending, models_animation_timing.

rl.textSplit

Split text into multiple strings, using MAX_TEXTSPLIT_COUNT static strings

Split text into multiple strings (static memory, valid until the next call).

Zigfn textSplit(text: [:0]const u8, delimiter: u8) []const [*:0]const u8
Cchar **TextSplit(const char *text, char delimiter, int *count);

Used in text_words_alignment, text_strings_management.

rl.textAppend

Append text at specific position and move cursor

Append text at specific position and move cursor. `text` must have room (C semantics, unchecked).

Zigfn textAppend(text: [*]u8, append: [:0]const u8, position: *i32) void
Cvoid TextAppend(char *text, const char *append, int *position);

rl.textFindIndex

Find first text occurrence within a string, -1 if not found

Zigfn textFindIndex(text: [:0]const u8, search: [:0]const u8) i32
Cint TextFindIndex(const char *text, const char *search);

Used in core_input_gestures_testbed.

rl.textToInteger

Get integer value from text

Zigfn textToInteger(text: [:0]const u8) i32
Cint TextToInteger(const char *text);

rl.textToFloat

Get float value from text

Zigfn textToFloat(text: [:0]const u8) f32
Cfloat TextToFloat(const char *text);