Text Box
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,
width = u32,
height = u32,
x = i32,
y = i32,
color = u32,
align = &str,
)
Param | Type | Default | Description |
---|---|---|---|
- | &str | - | Text to be displayed |
font | &str | "medium" | Size to display text in: "small" , "medium" , or "large" |
scale | f32 | 1.0 | Line spacing and scale of text box |
start | usize | 0 | Starting character to be displayed |
end | usize | text.len() | Ending character to be displayed, defaults to entire text |
width | u32 | 0 | Width of the text box in pixels |
height | u32 | 0 | Height of the text box in pixels |
x | i32 | 0 | Starting x position of the text |
y | i32 | 0 | Starting y position of the text |
color | u32 | 0xffffffff | Hex color to display text in |
align | &str | "left" | Text allignment in: "left" , "center" , or "right" |
Usage
Basic Usage
text_box!(
"Welcome to Turbo!",
font = "medium",
width = 50,
height = 20,
);
Preview
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!",
font = "medium",
scale = 1.2,
start = 0,
end = 100,
width = 100,
height = 80,
x = 80,
y = 40,
align = "center",
color = 0x000000ff
);