Skip to main content

Crate sdl3_ttf_sys

Crate sdl3_ttf_sys 

Source
Expand description

§sdl3-ttf-sys: Low level Rust bindings for SDL3_ttf

These are low level Rust bindings for SDL3_ttf, an add-on library for SDL 3 for rendering text. This version of sdl3-ttf-sys has bindings for SDL_ttf versions 3.2.0 to 3.2.2, inclusive.

sdl3-ttf-sys works out of the box on any target that SDL3_ttf supports and doesn’t require anything else if the SDL3_ttf library is installed or otherwise available. On targets that support it you can use pkg-config or vcpkg to locate the SDL3_ttf library if required (see below).

If the SDL3_ttf library isn’t already available, you have the option of building it from source as part of the build (see below), which requires CMake, a C compiler, and any dependencies that SDL3_ttf needs to build on your target. You can also choose to use vendored dependencies. Builds for web are supported via Emscripten (wasm32-unknown-emscripten).

Most of the docs are generated directly from the original C headers, which documents how SDL works in C. Using it from Rust might work differently in some cases. For example, macros in C are usually translated to constants or constant functions in Rust, but the docs may still refer to them as macros. Documentation specific to these Rust bindings are tagged with sdl3-sys.

Browse the API at docs.rs!

§Usage

sdl3-ttf-sys is compatible with SDL_ttf version 3.2.0 or later. Some APIs require later versions; you can check availability in the documentation. The latest available stable release is recommended.

By default, sdl3-ttf-sys will attempt to link to a dynamic/shared library named SDL3_ttf in the default library search path, using the usual platform specific naming convention for libraries. You can change this behaviour with the following feature flags.

FeatureDescription
use-pkg-configUse pkg-config to find and link the SDL_ttf library.
use-vcpkgUse vcpkg to find and link the SDL_ttf library.
build-from-sourceBuild and link SDL_ttf from source. You have to install any dependencies SDL needs to build for your target first. See below for build related features.
build-from-source-staticShortcut for enabling both the build-from-source and link-static features. This should no longer be necessary.
build-static-vendoredBuild and link SDL_ttf from source, use vendored libraries (see below), and link it all statically.
link-frameworkLink to a framework on Apple targets. This currently requires SDL3_ttf.xcframework to be located at ~/Library/Frameworks or /Library/Frameworks. The built executable has to be put in a signed app bundle to be able to run.
link-staticLink SDL_ttf statically.
no-linkDon’t link anything, and provide linking flags via Cargo metadata so you can do manual linking if desired.

§Building from source

When building from source with the build-from-source feature flag, you can use features to configure which backends and image formats to support. Features marked with “(cmake)” below all have an sdlttf- prefix and correspond to SDL_ttf’s cmake variables. They’re autodetected if not set. You can use a no- prefix to disable a cmake feature, for example no-sdlttf-harfbuzz disables harfbuzz support. Activated features override features disabled with the no- prefix.

§Linking and vendoring
Feature (cmake)Description
vendoredBuild dependencies from source as part of building SDL_ttf
§Rendering
Feature (cmake)Description
harfbuzzUse harfbuzz to improve text shaping
plutosvgUse plutosvg for color emoji support

§Other features

FeatureDescription
debug-implsImplement the Debug trait for most SDL_ttf types.
metadataEnable metadata. Also see only-metadata.
only-metadataShortcut for enabling both the metadata and no-link features. Recommended when you need metadata but don’t need to call into SDL_ttf, e.g. for build scripts.

§Recent changes

  • 0.6.1:

    • Enable use-pkg-config and use-vcpkg features by default
    • Require exact version match for source crate when building from source (fix for Android)
    • Add new and value assoc function/method for groups (ids, enums, etc)
    • impl Display for ids under the display-impls feature
    • Add metadata for structs and unions
    • Fix Android builds being built for the wrong arch (Thanks to Archee)
  • 0.6.0:

    • Update sdl3-sys to 0.6.0
    • Synchronize version number with sdl3-sys
    • Add metadata
    • Remove deprecated aliases
    • Make some functions safe and/or const
    • MSRV 1.85

See ChangeLog.md for older changes

Modules§

everything
Reexports of everything from the other modules
textengine
ttf
Header file for SDL_ttf library