diff --git a/src/text.rs b/src/text.rs index af553641..823cc9c8 100644 --- a/src/text.rs +++ b/src/text.rs @@ -359,13 +359,65 @@ pub fn draw_text_ex(text: &str, x: f32, y: f32, params: TextParams) { dest_size: Some(vec2(dest.w, dest.h)), source: Some(source), rotation: angle_rad, - pivot: Option::Some(vec2(dest.x, dest.y)), + pivot: Some(vec2(dest.x, dest.y)), ..Default::default() }, ); } } +/// Draw multiline text with the given font_size, line_distance_factor and color. +/// If no line distance but a custom font is given, the fonts line gap will be used as line distance factor if it exists. +pub fn draw_multiline_text( + text: &str, + x: f32, + y: f32, + font_size: f32, + line_distance_factor: Option, + color: Color, +) { + draw_multiline_text_ex( + text, + x, + y, + line_distance_factor, + TextParams { + font_size: font_size as u16, + font_scale: 1.0, + color, + ..Default::default() + }, + ) +} + +/// Draw multiline text with the given line distance and custom params such as font, font size and font scale. +/// If no line distance but a custom font is given, the fonts newline size will be used as line distance factor if it exists. +pub fn draw_multiline_text_ex( + text: &str, + x: f32, + mut y: f32, + line_distance_factor: Option, + params: TextParams, +) { + let line_distance = match line_distance_factor { + Some(distance) => distance, + None => { + let mut font_line_distance = 0.0; + if let Some(font) = params.font { + if let Some(metrics) = font.font.horizontal_line_metrics(1.0) { + font_line_distance = metrics.new_line_size; + } + } + font_line_distance + } + }; + + for line in text.lines() { + draw_text_ex(line, x, y, params.clone()); + y += line_distance * params.font_size as f32 * params.font_scale; + } +} + /// Get the text center. pub fn get_text_center( text: &str,