mirror of
https://github.com/fossasia/badgemagic-rs
synced 2025-06-24 15:53:58 +00:00
feat: move proporional font functonality to feature
This commit is contained in:
parent
36f748c092
commit
9f6c282e48
2 changed files with 19 additions and 3 deletions
|
@ -35,6 +35,7 @@ embedded-graphics = ["dep:embedded-graphics"]
|
|||
serde = ["dep:serde"]
|
||||
usb-hid = ["dep:hidapi"]
|
||||
ble = ["dep:btleplug", "dep:uuid", "dep:tokio"]
|
||||
u8g2-fonts = ["dep:u8g2-fonts"]
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.95"
|
||||
|
@ -50,4 +51,4 @@ serde_json = { version = "1.0.134", optional = true }
|
|||
time = "0.3.37"
|
||||
toml = { version = "0.8.19", optional = true }
|
||||
zerocopy = { version = "0.8.14", features = ["derive"] }
|
||||
u8g2-fonts = { version = "0.5.2", features = ["embedded_graphics_textstyle"] }
|
||||
u8g2-fonts = { version = "0.5.2", features = ["embedded_graphics_textstyle"], optional = true}
|
||||
|
|
19
src/main.rs
19
src/main.rs
|
@ -18,6 +18,11 @@ use embedded_graphics::{
|
|||
Drawable, Pixel,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
|
||||
|
||||
#[cfg(not(any(feature = "u8g2-fonts")))]
|
||||
use embedded_graphics::mono_font::{iso_8859_1::FONT_6X9, MonoTextStyle};
|
||||
#[cfg(feature = "u8g2-fonts")]
|
||||
use u8g2_fonts::{fonts::u8g2_font_lucasfont_alternate_tf, U8g2TextStyle};
|
||||
|
||||
#[derive(Parser)]
|
||||
|
@ -102,7 +107,7 @@ fn main() -> Result<()> {
|
|||
return list_devices(&args.transport);
|
||||
}
|
||||
|
||||
let payload = gnerate_payload(&mut args)?;
|
||||
let payload = generate_payload(&mut args)?;
|
||||
|
||||
write_payload(&args.transport, payload)
|
||||
}
|
||||
|
@ -128,7 +133,7 @@ fn list_devices(transport: &TransportProtocol) -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn gnerate_payload(args: &mut Args) -> Result<PayloadBuffer> {
|
||||
fn generate_payload(args: &mut Args) -> Result<PayloadBuffer> {
|
||||
let config_path = args.config.take().unwrap_or_default();
|
||||
let config = fs::read_to_string(&config_path)
|
||||
.with_context(|| format!("load config: {config_path:?}"))?;
|
||||
|
@ -157,8 +162,18 @@ fn gnerate_payload(args: &mut Args) -> Result<PayloadBuffer> {
|
|||
style = style.border();
|
||||
}
|
||||
style = style.speed(message.speed).mode(message.mode);
|
||||
|
||||
match message.content {
|
||||
Content::Text { text } => {
|
||||
|
||||
#[cfg(not(any(feature = "u8g2-fonts")))]
|
||||
let text = Text::new(
|
||||
&text,
|
||||
Point::new(0, 7),
|
||||
MonoTextStyle::new(&FONT_6X9, BinaryColor::On),
|
||||
);
|
||||
|
||||
#[cfg(feature = "u8g2-fonts")]
|
||||
let text = Text::new(
|
||||
&text,
|
||||
Point::new(0, 8),
|
||||
|
|
Loading…
Reference in a new issue