Function macroquad::text::get_text_center
source · pub fn get_text_center(
text: &str,
font: Option<&Font>,
font_size: u16,
font_scale: f32,
rotation: f32
) -> Vec2
Expand description
Get the text center.
Examples found in repository?
examples/text.rs (line 75)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
async fn main() {
let font = load_ttf_font("./examples/DancingScriptRegular.ttf")
.await
.unwrap();
let mut angle = 0.0;
loop {
clear_background(BLACK);
draw_text_ex("Custom font size:", 20.0, 20.0, TextParams::default());
let mut y = 20.0;
for font_size in (30..100).step_by(20) {
let text = "abcdef";
let params = TextParams {
font_size,
..Default::default()
};
y += font_size as f32;
draw_text_ex(text, 20.0, y, params);
}
draw_text_ex("Dynamic font scale:", 20.0, 400.0, TextParams::default());
draw_text_ex(
"abcd",
20.0,
450.0,
TextParams {
font_size: 50,
font_scale: get_time().sin() as f32 / 2.0 + 1.0,
..Default::default()
},
);
draw_text_ex("Custom font:", 400.0, 20.0, TextParams::default());
draw_text_ex(
"abcd",
400.0,
70.0,
TextParams {
font_size: 50,
font: Some(&font),
..Default::default()
},
);
draw_text_ex(
"abcd",
400.0,
160.0,
TextParams {
font_size: 100,
font: Some(&font),
..Default::default()
},
);
draw_text_ex(
"abcd",
screen_width() / 4.0 * 2.0,
screen_height() / 3.0 * 2.0,
TextParams {
font_size: 70,
font: Some(&font),
rotation: angle,
..Default::default()
},
);
let center = get_text_center("abcd", Option::None, 70, 1.0, angle * 2.0);
draw_text_ex(
"abcd",
screen_width() / 4.0 * 3.0 - center.x,
screen_height() / 3.0 * 2.0 - center.y,
TextParams {
font_size: 70,
rotation: angle * 2.0,
..Default::default()
},
);
angle -= 0.030;
next_frame().await
}
}