Skip to content

Commit 9901536

Browse files
authored
add get_default_font and fix related bugs (#810)
1 parent c7019a9 commit 9901536

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/text.rs

+22-6
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl Font {
213213
/// # use macroquad::prelude::*;
214214
/// # #[macroquad::main("test")]
215215
/// # async fn main() {
216-
/// let font = Font::default();
216+
/// let mut font = get_default_font();
217217
/// font.set_filter(FilterMode::Linear);
218218
/// # }
219219
/// ```
@@ -228,6 +228,12 @@ impl Font {
228228
// }
229229
}
230230

231+
impl Default for Font {
232+
fn default() -> Self {
233+
get_default_font()
234+
}
235+
}
236+
231237
/// Arguments for "draw_text_ex" function such as font, font_size etc
232238
#[derive(Debug, Clone)]
233239
pub struct TextParams<'a> {
@@ -418,12 +424,16 @@ pub fn draw_multiline_text_ex(
418424
let line_distance = match line_distance_factor {
419425
Some(distance) => distance,
420426
None => {
421-
let mut font_line_distance = 1.0;
422-
if let Some(font) = params.font {
423-
if let Some(metrics) = font.font.horizontal_line_metrics(1.0) {
424-
font_line_distance = metrics.new_line_size;
425-
}
427+
let mut font_line_distance = 0.0;
428+
let font = if let Some(font) = params.font {
429+
font
430+
} else {
431+
&get_default_font()
432+
};
433+
if let Some(metrics) = font.font.horizontal_line_metrics(1.0) {
434+
font_line_distance = metrics.new_line_size;
426435
}
436+
427437
font_line_distance
428438
}
429439
};
@@ -475,6 +485,12 @@ impl FontsStorage {
475485
}
476486
}
477487

488+
/// Returns macroquads default font.
489+
pub fn get_default_font() -> Font {
490+
let context = get_context();
491+
context.fonts_storage.default_font.clone()
492+
}
493+
478494
/// From given font size in world space gives
479495
/// (font_size, font_scale and font_aspect) params to make rasterized font
480496
/// looks good in currently active camera

0 commit comments

Comments
 (0)