Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
no-inline-html:
allowed_elements:
- div
- img
no-duplicate-heading: false
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,31 @@ the `fonts` feature can be disabled by turning off the default crate features.
[`ibm437`](https://crates.io/crates/ibm437) is a good alternative that includes
some drawing characters, but is not as large as embedded-graphics-unicodefonts.

### Bold and italic fonts

Bold and italic modifiers are supported, but this requires providing fonts
through `EmbeddedBackendConfig`.
If only regular font is provided, it serves as a fallback.
All fonts must be of the same size.

```rust
use mousefood::{EmbeddedBackend, EmbeddedBackendConfig, fonts};

let config = EmbeddedBackendConfig {
font_regular: fonts::MONO_6X13,
font_bold: Some(fonts::MONO_6X13_BOLD),
font_italic: Some(fonts::MONO_6X13_ITALIC),
..Default::default()
};
let backend = EmbeddedBackend::new(&mut display, config);
```

<div align="center">
<img alt="Bold and Italic fonts"
src="https://github.com/j-g00da/mousefood/blob/6640da9402794ea8f9370e0dc2b4bd1ebf2c6356/assets/bold_italic.png?raw=true"
style="max-width: 640px"/>
</div>

### Simulator

Mousefood can be run in a simulator
Expand Down
25 changes: 19 additions & 6 deletions src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ where
/// Regular font.
pub font_regular: MonoFont<'static>,
/// Bold font.
pub font_bold: MonoFont<'static>,
pub font_bold: Option<MonoFont<'static>>,
/// Italic font.
pub font_italic: Option<MonoFont<'static>>,
}

impl<D, C> Default for EmbeddedBackendConfig<D, C>
Expand All @@ -40,7 +42,8 @@ where
Self {
flush_callback: Box::new(|_| {}),
font_regular: default_font::regular,
font_bold: default_font::bold,
font_bold: None,
font_italic: None,
}
}
}
Expand Down Expand Up @@ -74,7 +77,8 @@ where
buffer: framebuffer::HeapBuffer<C>,

font_regular: MonoFont<'static>,
font_bold: MonoFont<'static>,
font_bold: Option<MonoFont<'static>>,
font_italic: Option<MonoFont<'static>>,

char_offset: geometry::Point,

Expand All @@ -96,7 +100,8 @@ where
#[cfg(not(feature = "simulator"))] flush_callback: impl FnMut(&mut D) + 'static,
#[cfg(feature = "simulator")] flush_callback: impl FnMut(&mut SimulatorDisplay<C>) + 'static,
font_regular: MonoFont<'static>,
font_bold: MonoFont<'static>,
font_bold: Option<MonoFont<'static>>,
font_italic: Option<MonoFont<'static>>,
) -> EmbeddedBackend<'display, D, C> {
let pixels = layout::Size {
width: display.bounding_box().size.width as u16,
Expand All @@ -109,6 +114,7 @@ where
flush_callback: Box::new(flush_callback),
font_regular,
font_bold,
font_italic,
char_offset: geometry::Point::new(0, font_regular.character_size.height as i32),
columns_rows: layout::Size {
height: pixels.height / font_regular.character_size.height as u16,
Expand Down Expand Up @@ -139,6 +145,7 @@ where
config.flush_callback,
config.font_regular,
config.font_bold,
config.font_italic,
)
}

Expand Down Expand Up @@ -181,9 +188,15 @@ where

for modifier in cell.style().add_modifier.iter() {
style_builder = match modifier {
style::Modifier::BOLD => style_builder.font(&self.font_bold),
style::Modifier::BOLD => match &self.font_bold {
None => style_builder.font(&self.font_regular),
Some(font) => style_builder.font(font),
},
style::Modifier::DIM => style_builder, // TODO
style::Modifier::ITALIC => style_builder, // TODO
style::Modifier::ITALIC => match &self.font_italic {
None => style_builder.font(&self.font_regular),
Some(font) => style_builder.font(font),
},
style::Modifier::UNDERLINED => style_builder.underline(),
style::Modifier::SLOW_BLINK => style_builder, // TODO
style::Modifier::RAPID_BLINK => style_builder, // TODO
Expand Down
4 changes: 0 additions & 4 deletions src/default_font.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#[cfg(feature = "fonts")]
pub use embedded_graphics_unicodefonts::MONO_6X10 as bold;
#[cfg(feature = "fonts")]
pub use embedded_graphics_unicodefonts::MONO_6X10 as regular;

#[cfg(not(feature = "fonts"))]
pub use embedded_graphics::mono_font::ascii::FONT_6X10 as regular;
#[cfg(not(feature = "fonts"))]
pub use embedded_graphics::mono_font::ascii::FONT_6X10 as bold;