diff --git a/src/ui/song_editor.rs b/src/ui/song_editor.rs index 25bc56a..350c1d8 100644 --- a/src/ui/song_editor.rs +++ b/src/ui/song_editor.rs @@ -311,11 +311,11 @@ impl SongEditor { - - Hello World - - - Hello World + + Hello World this is + longer chunks of text + where we need to test whether the text + will look ok! "#.as_bytes()); stack!( diff --git a/src/ui/text_svg.rs b/src/ui/text_svg.rs index 9be41f4..ea6f24c 100644 --- a/src/ui/text_svg.rs +++ b/src/ui/text_svg.rs @@ -165,11 +165,15 @@ impl TextSvg { } else { "".into() }; - // text y coords are based on bottom left corner so we need to take height into consideration responsive(move |s| { + let total_lines = self.text.lines().count(); + let half_lines = (total_lines / 2) as f32; + let middle_position = s.height / 2.0; + let line_spacing = 10.0; + let starting_y_position = middle_position - (half_lines * (self.font.size as f32 + line_spacing)); let text_pieces: Vec = self.text.lines().map(|t| format!("{}", t)).collect(); let base = format!("{} - + {} ", s.width, s.height, shadow, self.font.name, self.font.size, self.fill, stroke, self.text); Svg::new(Handle::from_memory( @@ -180,9 +184,11 @@ impl TextSvg { } fn text_spans(&self) -> Vec { + let total_lines = self.text.lines().count(); self.text .lines() - .map(|t| format!("{}", t)) + .enumerate() + .map(|(i, t)| format!("{}", t)) .collect() } }