Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions mousefood/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ where
width: display.bounding_box().size.width as u16,
height: display.bounding_box().size.height as u16,
};

//make best effort to center the drawing
let off_x = (pixels.width % font_regular.character_size.width as u16) / 2;
let off_y = (pixels.height % font_regular.character_size.height as u16) / 2;
let char_offset = geometry::Point::new(off_x as i32, off_y as i32);

Self {
buffer: framebuffer::HeapBuffer::new(display.bounding_box()),
display,
Expand All @@ -101,7 +107,7 @@ where
font_regular,
font_bold,
font_italic,
char_offset: geometry::Point::new(0, font_regular.character_size.height as i32),
char_offset,
columns_rows: layout::Size {
height: pixels.height / font_regular.character_size.height as u16,
width: pixels.width / font_regular.character_size.width as u16,
Expand Down Expand Up @@ -176,10 +182,11 @@ where
);
}

Text::new(
Text::with_baseline(
cell.symbol(),
position + self.char_offset,
style_builder.build(),
embedded_graphics::text::Baseline::Top,
)
.draw(&mut self.buffer)
.map_err(|_| crate::error::Error::DrawError)?;
Expand Down