mirror of
https://github.com/fossasia/badgemagic-rs
synced 2025-07-15 17:13:59 +00:00
Squashed commit of the following:
commit9f6c282e48
Author: Valentin Weber <valentin@wv2.ch> Date: Sat Feb 22 18:42:03 2025 +0100 feat: move proporional font functonality to feature commit36f748c092
Author: Valentin Weber <valentin@wv2.ch> Date: Sat Feb 22 02:51:54 2025 +0100 chore: clean up LICENSE-MIT copyriht notice commitfe3abd83d7
Author: Valentin Weber <valentin@wv2.ch> Date: Fri Feb 21 22:28:40 2025 +0100 feat: Move to proportional font To use the available space on the bade more efficient, I changed the font to u8g2_font_lucasfont_alternate_tf from [u8g2-fonts](https://docs.rs/crate/u8g2-fonts/). Lucasfont Alternate was created by Patrick Lauke and is licensed under [CC BY 3.0](https://creativecommons.org/licenses/by/3.0/). No changes to the font were made.
This commit is contained in:
parent
f13e4c215b
commit
00cdff615a
2 changed files with 18 additions and 3 deletions
|
@ -35,6 +35,7 @@ embedded-graphics = ["dep:embedded-graphics"]
|
||||||
serde = ["dep:serde"]
|
serde = ["dep:serde"]
|
||||||
usb-hid = ["dep:hidapi"]
|
usb-hid = ["dep:hidapi"]
|
||||||
ble = ["dep:btleplug", "dep:uuid", "dep:tokio"]
|
ble = ["dep:btleplug", "dep:uuid", "dep:tokio"]
|
||||||
|
u8g2-fonts = ["dep:u8g2-fonts"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.95"
|
anyhow = "1.0.95"
|
||||||
|
@ -50,4 +51,4 @@ serde_json = { version = "1.0.134", optional = true }
|
||||||
time = "0.3.37"
|
time = "0.3.37"
|
||||||
toml = { version = "0.8.19", optional = true }
|
toml = { version = "0.8.19", optional = true }
|
||||||
zerocopy = { version = "0.8.14", features = ["derive"] }
|
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}
|
||||||
|
|
18
src/main.rs
18
src/main.rs
|
@ -18,6 +18,10 @@ use embedded_graphics::{
|
||||||
Drawable, Pixel,
|
Drawable, Pixel,
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
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};
|
use u8g2_fonts::{fonts::u8g2_font_lucasfont_alternate_tf, U8g2TextStyle};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
|
@ -106,7 +110,7 @@ fn main() -> Result<()> {
|
||||||
return list_devices(&args.transport);
|
return list_devices(&args.transport);
|
||||||
}
|
}
|
||||||
|
|
||||||
let payload = gnerate_payload(&mut args)?;
|
let payload = generate_payload(&mut args)?;
|
||||||
|
|
||||||
write_payload(&args.transport, payload)
|
write_payload(&args.transport, payload)
|
||||||
}
|
}
|
||||||
|
@ -132,7 +136,7 @@ fn list_devices(transport: &TransportProtocol) -> Result<()> {
|
||||||
Ok(())
|
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_path = args.config.take().unwrap_or_default();
|
||||||
let config = fs::read_to_string(&config_path)
|
let config = fs::read_to_string(&config_path)
|
||||||
.with_context(|| format!("load config: {config_path:?}"))?;
|
.with_context(|| format!("load config: {config_path:?}"))?;
|
||||||
|
@ -161,8 +165,18 @@ fn gnerate_payload(args: &mut Args) -> Result<PayloadBuffer> {
|
||||||
style = style.border();
|
style = style.border();
|
||||||
}
|
}
|
||||||
style = style.speed(message.speed).mode(message.mode);
|
style = style.speed(message.speed).mode(message.mode);
|
||||||
|
|
||||||
match message.content {
|
match message.content {
|
||||||
Content::Text { text } => {
|
Content::Text { text } => {
|
||||||
|
|
||||||
|
#[cfg(not(any(feature = "u8g2-fonts")))]
|
||||||
|
let text = Text::new(
|
||||||
|
&text,
|
||||||
|
Point::new(0, 8),
|
||||||
|
U8g2TextStyle::new(u8g2_font_lucasfont_alternate_tf, BinaryColor::On),
|
||||||
|
);
|
||||||
|
|
||||||
|
#[cfg(feature = "u8g2-fonts")]
|
||||||
let text = Text::new(
|
let text = Text::new(
|
||||||
&text,
|
&text,
|
||||||
Point::new(0, 8),
|
Point::new(0, 8),
|
||||||
|
|
Loading…
Reference in a new issue