MCPcopy Index your code
hub / github.com/endbasic/endbasic / raw_write_wrapped

Method raw_write_wrapped

std/src/console/graphics.rs:451–487  ·  view source on GitHub ↗

Renders the given text at the current cursor position, with wrapping and scrolling if necessary.

(&mut self, text: String)

Source from the content-addressed store, hash-verified

449 /// Renders the given text at the current cursor position, with wrapping and
450 /// scrolling if necessary.
451 fn raw_write_wrapped(&mut self, text: String) -> io::Result<()> {
452 let mut line_buffer = LineBuffer::from(text);
453
454 loop {
455 let fit_chars = self.size_chars.x - self.cursor_pos.x;
456
457 let remaining = line_buffer.split_off(usize::from(fit_chars));
458 let len = match u16::try_from(line_buffer.len()) {
459 Ok(len) => len,
460 Err(_) => return Err(io::Error::new(io::ErrorKind::InvalidInput, "Text too long")),
461 };
462
463 if len > 0 {
464 let xy = self.cursor_pos.clamped_mul(self.glyph_size);
465 let size = SizeInPixels::new(
466 len.clamped_mul(self.glyph_size.width),
467 self.glyph_size.height,
468 );
469
470 self.raster_ops.set_draw_color(self.bg_color);
471 self.raster_ops.draw_rect_filled(xy, size)?;
472
473 self.raster_ops.set_draw_color(self.fg_color);
474 self.raster_ops.write_text(xy, &line_buffer.into_inner())?;
475 self.cursor_pos.x += len;
476 }
477
478 line_buffer = remaining;
479 if line_buffer.is_empty() {
480 break;
481 } else {
482 self.open_line()?;
483 }
484 }
485
486 Ok(())
487 }
488}
489
490#[async_trait(?Send)]

Callers 2

printMethod · 0.80
writeMethod · 0.80

Calls 9

split_offMethod · 0.80
clamped_mulMethod · 0.80
into_innerMethod · 0.80
open_lineMethod · 0.80
lenMethod · 0.45
set_draw_colorMethod · 0.45
draw_rect_filledMethod · 0.45
write_textMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected