Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes draw_text_ex to pass params by reference #738

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/arkanoid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async fn main() {
"Press space to start",
SCR_W / 2. - 5.,
SCR_H / 2.,
text_params,
&text_params,
);

ball_x = platform_x;
Expand Down
18 changes: 9 additions & 9 deletions examples/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async fn main() {
loop {
clear_background(BLACK);

draw_text_ex("Custom font size:", 20.0, 20.0, TextParams::default());
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) {
Expand All @@ -22,27 +22,27 @@ async fn main() {
};

y += font_size as f32;
draw_text_ex(text, 20.0, y, params);
draw_text_ex(text, 20.0, y, &params);
}

draw_text_ex("Dynamic font scale:", 20.0, 400.0, TextParams::default());
draw_text_ex("Dynamic font scale:", 20.0, 400.0, &TextParams::default());
draw_text_ex(
"abcd",
20.0,
450.0,
TextParams {
&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("Custom font:", 400.0, 20.0, &TextParams::default());
draw_text_ex(
"abcd",
400.0,
70.0,
TextParams {
&TextParams {
font_size: 50,
font: Some(&font),
..Default::default()
Expand All @@ -53,7 +53,7 @@ async fn main() {
"abcd",
400.0,
160.0,
TextParams {
&TextParams {
font_size: 100,
font: Some(&font),
..Default::default()
Expand All @@ -64,7 +64,7 @@ async fn main() {
"abcd",
screen_width() / 4.0 * 2.0,
screen_height() / 3.0 * 2.0,
TextParams {
&TextParams {
font_size: 70,
font: Some(&font),
rotation: angle,
Expand All @@ -77,7 +77,7 @@ async fn main() {
"abcd",
screen_width() / 4.0 * 3.0 - center.x,
screen_height() / 3.0 * 2.0 - center.y,
TextParams {
&TextParams {
font_size: 70,
rotation: angle * 2.0,
..Default::default()
Expand Down
2 changes: 1 addition & 1 deletion examples/text_measures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn draw_text_annotated(text: &str, font: Option<&Font>, x: f32, baseline: f32) {
text,
x,
baseline,
TextParams {
&TextParams {
font_size: 100,
font,
..Default::default()
Expand Down
4 changes: 2 additions & 2 deletions src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ pub fn draw_text(text: &str, x: f32, y: f32, font_size: f32, color: Color) {
text,
x,
y,
TextParams {
&TextParams {
font_size: font_size as u16,
font_scale: 1.0,
color,
Expand All @@ -296,7 +296,7 @@ pub fn draw_text(text: &str, x: f32, y: f32, font_size: f32, color: Color) {
}

/// Draw text with custom params such as font, font size and font scale.
pub fn draw_text_ex(text: &str, x: f32, y: f32, params: TextParams) {
pub fn draw_text_ex(text: &str, x: f32, y: f32, params: &TextParams) {
let font = params
.font
.unwrap_or(&get_context().fonts_storage.default_font);
Expand Down
Loading