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,
w = u32,
h = u32,
x = i32,
y = i32,
color = u32,
align = &str,
preserve_whitespace = bool,
fixed = bool,
bounds = Bounds,
)
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 | 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. |
w | u32 | [screen width] | Width of the text box in pixels. |
h | u32 | [screen height] | 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 alignment. Available options: "left" , "center" , or "right" . |
preserve_whitespace | bool | true | If true , newline ('\n' ), tab ('\t' ), and space (' ' ) chars will not be ignored. |
fixed | bool | false | If true , the text box's size and position are unaffected by the camera. |
bounds | Bounds | Sets the x , y , w , h of the text box. |
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!",
x = 80,
y = 40,
w = 100,
h = 80,
font = "medium",
align = "center",
color = 0x000000ff
);