Skip to content

Text Box

Make Games Fast Screenshot

Overview

Draw a rectangle into your games canvas that contains text. Wrap, align, and position the textbox by using the text_box! macro.

API

text_box!

Draws a text box with the ability to align, wrap, and position text

text_box!(
    &str,
    font = &str,
    scale = f32,
    start = usize,
    end = usize,
    w = u32,
    h = u32,
    x = i32,
    y = i32,
    color = u32,
    align = &str,
    preserve_whitespace = bool,
    fixed = bool,
    bounds = Bounds,
)
ParamTypeDefaultDescription
-&str-Text to be displayed.
font&str"medium"Size to display text in: "small", "medium", or "large".
scalef321.0Scale of text box.
startusize0Starting character to be displayed.
endusizetext.len()Ending character to be displayed, defaults to entire text.
wu32[screen width]Width of the text box in pixels.
hu32[screen height]Height of the text box in pixels.
xi320Starting x position of the text.
yi320Starting y position of the text.
coloru320xffffffffHex color to display text in.
align&str"left"Text alignment. Available options: "left", "center", or "right".
preserve_whitespacebooltrueIf true, newline ('\n'), tab ('\t'), and space (' ') chars will not be ignored.
fixedboolfalseIf true, the text box's size and position are unaffected by the camera.
boundsBoundsSets the x, y, w, h of the text box.

Usage

Basic Usage

    text_box!(
        "Welcome to Turbo!",
        font = "medium",
        width = 50,
        height = 20,
    );
Preview

Welcome To Turbo

Advanced Usage

Wrap and adjust the text_box by declaring different width, height, and align values. Position it with different x and y values:

    text_box!(
        "Turbo makes UI elements easy and fast!",
        x = 80,
        y = 40,
        w = 100,
        h = 80,
        font = "medium",
        align = "center",
        color = 0x000000ff
    );

Turbo Makes UI Easy Screenshot