Skip to content

[Renderers/Raylib] Odin measure text function for Raylib doesn't support variable font size #308

Description

@tralph3

I found the measure text function provided in the example for the raylib renderer in the odin bindings to give wrong results. Here's how it looks like:

Image

Luckily, raylib has its own function to measure text, and it works perfectly.

This is the revised function:

measureText :: proc "c" (text: StringSlice, config: ^TextElementConfig, userData: rawptr) -> Dimensions {
    context = runtime.default_context()

    cloned := strings.clone_to_cstring(string(text.chars[:text.length]), context.temp_allocator)
    result := raylib.MeasureTextEx(
        raylibFonts[config.fontId].font,
        cloned,
        f32(config.fontSize),
        f32(config.letterSpacing))

    return {
        width = result.x,
        height = result.y
    }
}

And this is the result:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions