diff --git a/src/ui/text_svg.rs b/src/ui/text_svg.rs index 02eb890..0edf35f 100644 --- a/src/ui/text_svg.rs +++ b/src/ui/text_svg.rs @@ -279,45 +279,56 @@ impl TextSvg { let line_spacing = 10.0; let text_and_line_spacing = font_size + line_spacing; - let (text_anchor, starting_y_position) = match self.alignment - { - TextAlignment::TopLeft => ("start", 0.0), - TextAlignment::TopCenter => ("middle", 0.0), - TextAlignment::TopRight => ("end", 0.0), - TextAlignment::MiddleLeft => { - let middle_position = size.height / 2.0; - let position = half_lines - .mul_add(-text_and_line_spacing, middle_position); - ("start", position) - } - TextAlignment::MiddleCenter => { - let middle_position = size.height / 2.0; - let position = half_lines - .mul_add(-text_and_line_spacing, middle_position); - ("middle", position) - } - TextAlignment::MiddleRight => { - let middle_position = size.height / 2.0; - let position = half_lines - .mul_add(-text_and_line_spacing, middle_position); - ("end", position) - } - TextAlignment::BottomLeft => { - let position = size.height - - (total_lines as f32 * text_and_line_spacing); - ("start", position) - } - TextAlignment::BottomCenter => { - let position = size.height - - (total_lines as f32 * text_and_line_spacing); - ("middle", position) - } - TextAlignment::BottomRight => { - let position = size.height - - (total_lines as f32 * text_and_line_spacing); - ("end", position) - } - }; + let (text_anchor, starting_y_position, x_position) = + match self.alignment { + TextAlignment::TopLeft => ("start", font_size, "0"), + TextAlignment::TopCenter => { + ("middle", font_size, "50%") + } + TextAlignment::TopRight => ("end", font_size, "100%"), + TextAlignment::MiddleLeft => { + let middle_position = size.height / 2.0; + let position = half_lines.mul_add( + -text_and_line_spacing, + middle_position, + ); + ("start", position, "0") + } + TextAlignment::MiddleCenter => { + let middle_position = size.height / 2.0; + let position = half_lines.mul_add( + -text_and_line_spacing, + middle_position, + ); + ("middle", position, "50%") + } + TextAlignment::MiddleRight => { + let middle_position = size.height / 2.0; + let position = half_lines.mul_add( + -text_and_line_spacing, + middle_position, + ); + ("end", position, "100%") + } + TextAlignment::BottomLeft => { + let position = size.height + - (total_lines as f32 + * text_and_line_spacing); + ("start", position, "0") + } + TextAlignment::BottomCenter => { + let position = size.height + - (total_lines as f32 + * text_and_line_spacing); + ("middle", position, "50%") + } + TextAlignment::BottomRight => { + let position = size.height + - (total_lines as f32 + * text_and_line_spacing); + ("end", position, "100%") + } + }; final_svg.push_str(&format!("", size.width, size.height)); @@ -337,7 +348,7 @@ impl TextSvg { // "", // ); - final_svg.push_str(&format!("{}", + "{}", (index as f32).mul_add( text_and_line_spacing, starting_y_position