sdl2-unifont

Crates.iosdl2-unifont
lib.rssdl2-unifont
version1.0.2
sourcesrc
created_at2018-10-14 10:55:08.295224
updated_at2021-04-24 06:05:35.382388
descriptionEmbedded GNU Unifont for Rust SDL programs, for simple font rendering tasks
homepage
repositoryhttps://github.com/carlalbrecht/sdl2-unifont
max_upload_size
id90097
size4,698,584
Carl Albrecht (carlalbrecht)

documentation

README

sdl2-unifont Latest Version Documentation

Sometimes, you just need to draw some text in your SDL application, and don't need any kind of advanced rendering features. You don't want the hassle of distributing a separate font file, relying on system fonts which often vary in location, or having to use SDL_ttf, just to display a few lines of text.

This library embeds the GNU Unifont, xzipped, inside the application binary, and decompresses it automatically before use. The library tries somewhat to minimise both it's on-disk and in-memory size.

Getting Started

Check here for the latest version of sdl2-unifont.

Or add the following to your Cargo.toml:

[dependencies]
sdl2-unifont = "1.0.2"

Demo


The example program's output

Run the included example, with cargo run --example demo --features plane-1 to produce the above screen.

Example

extern crate sdl2_unifont;

use sdl2_unifont::renderer::SurfaceRenderer;

use sdl2::pixels::Color;

fn main() {
    // Red text with transparent background
    let mut renderer =
        SurfaceRenderer::new(Color::RGB(255, 0, 0), Color::RGBA(0, 0, 0, 0));

    // Draw text to a surface, which can be used like any other. .draw() returns
    // an error result if the string contains a character which is not in the
    // Unifont.
    let surface = renderer.draw("Sample Text").unwrap();

    // Renderer simply holds state for producing new text surfaces
    renderer.bg_color = Color::RGB(255, 255, 0);
    renderer.bold = true;
    renderer.scale = 2;
    let example2 = renderer.draw("Big and bold").unwrap();
}

Consult examples/demo.rs for additional example code.

Commit count: 40

cargo fmt