(
&mut self,
font: &SpriteFont,
position: Vec2,
text: &[TextSegment<'_>],
max_chars: Option<usize>,
)
| 219 | } |
| 220 | |
| 221 | pub fn text_segments( |
| 222 | &mut self, |
| 223 | font: &SpriteFont, |
| 224 | position: Vec2, |
| 225 | text: &[TextSegment<'_>], |
| 226 | max_chars: Option<usize>, |
| 227 | ) { |
| 228 | let mut cursor = Vec2::new(0.0, font.ascent.floor()); |
| 229 | let mut last_char = None; |
| 230 | let mut chars = 0; |
| 231 | |
| 232 | for segment in text { |
| 233 | for ch in segment.content.chars() { |
| 234 | chars += 1; |
| 235 | |
| 236 | if max_chars.map(|m| chars > m) == Some(true) { |
| 237 | return; |
| 238 | } |
| 239 | |
| 240 | if ch.is_control() { |
| 241 | if ch == '\n' { |
| 242 | cursor.x = 0.0; |
| 243 | cursor.y += font.line_height().floor(); |
| 244 | } |
| 245 | |
| 246 | continue; |
| 247 | } |
| 248 | |
| 249 | if let Some(glyph) = font.glyph(ch) { |
| 250 | if let Some(kerning) = last_char.and_then(|l| font.kerning(l, ch)) { |
| 251 | cursor.x += kerning; |
| 252 | } |
| 253 | |
| 254 | if let Some(image) = &glyph.image { |
| 255 | self.texture_region( |
| 256 | font.texture(), |
| 257 | (position + cursor + image.offset).floor(), |
| 258 | image.uv, |
| 259 | DrawParams::new().color(segment.color), |
| 260 | ); |
| 261 | } |
| 262 | |
| 263 | cursor.x += glyph.advance; |
| 264 | |
| 265 | last_char = Some(ch); |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | pub fn text( |
| 272 | &mut self, |
no test coverage detected